Version: v1.8

Extend Terraform Addon

Terraform Controller is the core controller to provision and manage cloud resources for KubeVela. It has supported some cloud providers, including AWS, Azure, GCP, Alibaba Cloud, Tencent Cloud, etc. But only a few has been supported as Terraform Addons in KubeVela.

This guide will show you how to extend a Terraform Addon to support your cloud provider.

If the cloud provider you want to support is none of supported cloud providers in Terraform Controller, you have to support it first. If it has been supported by Terraform Controller, you can continue to extend the addon.

  • Clone oam-dev/catalog
  1. $ git clone https://github.com/kubevela/catalog.git
  • Prepare a metadata file

Edit the metadata file hack/addons/terraform/terraform-provider-scaffold/metadata.yaml for your cloud provider.

  1. ...
  2. # -------------------------------------Configuration Metadata for a Terraform Addon-------------------------------------
  3. # provider short name
  4. shortCloudName: tencent
  5. # The Cloud name of the provider
  6. completeCloudName: Tencent Cloud
  7. # When enabling a Terraform provider, these properties need to set for authentication. For Tencent Cloud,
  8. # name: Environment variable name when authenticating Terraform, like https://github.com/oam-dev/terraform-controller/blob/master/controllers/provider/credentials.go#L59
  9. # secretKey: Secret key when storing authentication information in a Kubernetes, like https://github.com/oam-dev/terraform-controller/blob/master/controllers/provider/credentials.go#L109.
  10. cloudProperties:
  11. - name: TENCENTCLOUD_SECRET_ID
  12. secretKey: secretID
  13. description: Get TENCENTCLOUD_SECRET_ID per this guide https://cloud.tencent.com/document/product/1213/67093
  14. - name: TENCENTCLOUD_SECRET_KEY
  15. secretKey: secretKey
  16. description: Get TENCENTCLOUD_SECRET_KEY per this guide https://cloud.tencent.com/document/product/1213/67093
  17. # If one property is region, please set `isRegion` to true
  18. - name: TENCENTCLOUD_REGION
  19. description: Get TENCENTCLOUD_REGION by picking one RegionId from Tencent Cloud region list https://cloud.tencent.com/document/api/1140/40509#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8
  20. isRegion: true

Generate a Terraform Addon for your cloud provider. The generated addon code will be stored in addons/terraform-tencent.

  1. $ make terraform-addon-gen
  2. go run hack/addons/terraform/gen.go hack/addons/terraform/provider-sample.yaml
  3. Generating addon for provider tencent in addons/terraform-tencent
  4. Rendering hack/addons/terraform/terraform-provider-skaffold/metadata.yaml
  5. Rendering hack/addons/terraform/terraform-provider-skaffold/readme.md
  6. Rendering hack/addons/terraform/terraform-provider-skaffold/resources/account-creds.cue
  7. Rendering hack/addons/terraform/terraform-provider-skaffold/resources/parameter.cue
  8. Rendering hack/addons/terraform/terraform-provider-skaffold/resources/provider.cue
  9. Rendering hack/addons/terraform/terraform-provider-skaffold/template.yaml
  10. $ ls addons/terraform-tencent
  11. definitions metadata.yaml readme.md resources template.yaml

Enable the addon Check whether a Provider is created whose name is the same as your cloud provider.

  1. $ vela addon enable ./addons/terraform-tencent TENCENTCLOUD_SECRET_ID=xxx TENCENTCLOUD_SECRET_KEY=yyy TENCENTCLOUD_REGION=ap-chengdu
  2. I0207 10:15:14.005269 32481 apply.go:106] "patching object" name="addon-terraform-tencent" resource="core.oam.dev/v1beta1, Kind=Application"
  3. I0207 10:15:14.138645 32481 apply.go:106] "patching object" name="addon-secret-terraform-tencent" resource="/v1, Kind=Secret"
  4. Addon: terraform-tencent enabled Successfully.
  5. $ kubectl get provider
  6. NAME STATE AGE
  7. tencent ready 1d

You are encouraged to further verify the provider by provision a cloud resource of your cloud provider.

Push the code generated in ./addons and make a pull request.

Write Terraform Addon enable doc for your cloud provider and add it to all supported cloud providers.

Last updated on May 6, 2023 by Tianxin Dong