Terraform

To provision cloud resources, you can use terraform along with related cloud provider addons.

Enable Terraform addon

  1. vela addon enable terraform

After terraform addon enabled, you will have a basic capability to create cloud resource in CRD ways. Then you can enable a terraform provider addon for specific cloud.s

Enable Terraform Provider addon

KubeVela can support following cloud providers by enabling the Terraform provider addons.

  1. $ vela addon list | grep terraform-
  2. terraform-alibaba KubeVela Kubernetes Terraform Controller for Alibaba Cloud [1.0.2, 1.0.1] enabled (1.0.2)
  3. terraform-tencent KubeVela Kubernetes Terraform Controller Provider for Tencent Cloud [1.0.0, 1.0.1] enabled (1.0.0)
  4. terraform-aws KubeVela Kubernetes Terraform Controller for AWS [1.0.0, 1.0.1] enabled (1.0.0)
  5. terraform-azure KubeVela Kubernetes Terraform Controller for Azure [1.0.0, 1.0.1] enabled (1.0.0)
  6. terraform-baidu KubeVela Kubernetes Terraform Controller Provider for Baidu Cloud [1.0.0, 1.0.1] enabled (1.0.0)
  7. terraform-gcp KubeVela Kubernetes Terraform Controller Provider for Google Cloud Platform [1.0.0, 1.0.1] enabled (1.0.0)
  8. terraform-ucloud KubeVela Kubernetes Terraform Controller Provider for UCloud [1.0.1, 1.0.0] enabled (1.0.1)

To enable one of them, use the following command:

  1. $ vela addon enable terraform-<provider-name>

You can also disable, upgrade, check status of an addon by command vela addon.

Authenticate Terraform Provider

After any of the terraform provider addon enabled, you can create credential for them by vela provider command.

Add Credential

Each Terraform provider can be authenticated by the command as below.

  1. $ vela provider add -h
  2. Authenticate Terraform Cloud Provider by creating a credential secret and a Terraform Controller Provider
  3. Usage:
  4. vela provider add [flags]
  5. vela provider add [command]
  6. Examples:
  7. vela provider add <provider-type>
  8. Available Commands:
  9. terraform-alibaba Authenticate Terraform Cloud Provider terraform-alibaba
  10. terraform-aws Authenticate Terraform Cloud Provider terraform-aws
  11. terraform-azure Authenticate Terraform Cloud Provider terraform-azure
  12. terraform-baidu Authenticate Terraform Cloud Provider terraform-baidu
  13. terraform-gcp Authenticate Terraform Cloud Provider terraform-gcp
  14. terraform-tencent Authenticate Terraform Cloud Provider terraform-tencent
  15. terraform-ucloud Authenticate Terraform Cloud Provider terraform-ucloud

For example, let’s authenticate the Terraform provider terraform-aws.

Here is the help message for authenticate the terraform-aws.

  1. $ vela provider add terraform-aws -h
  2. Authenticate Terraform Cloud Provider terraform-aws by creating a credential secret and a Terraform Controller Provider
  3. Usage:
  4. vela provider add terraform-aws [flags]
  5. Examples:
  6. vela provider add terraform-aws
  7. Flags:
  8. --AWS_ACCESS_KEY_ID string Get AWS_ACCESS_KEY_ID per https://aws.amazon.com/blogs/security/wheres-my-secret-access-key/
  9. --AWS_DEFAULT_REGION string Choose one of Code form region list https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions
  10. --AWS_SECRET_ACCESS_KEY string Get AWS_SECRET_ACCESS_KEY per https://aws.amazon.com/blogs/security/wheres-my-secret-access-key/
  11. --AWS_SESSION_TOKEN string Get AWS_SESSION_TOKEN per https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html
  12. -h, --help help for terraform-aws
  13. --name default The name of Terraform Provider for AWS, default is default (default "aws")
  14. Global Flags:
  15. -y, --yes Assume yes for all user prompts

Authenticate a Terraform provider

  1. $ vela provider add terraform-aws --AWS_ACCESS_KEY_ID=xxx --AWS_SECRET_ACCESS_KEY=yyy --AWS_DEFAULT_REGION=us-east-1

Without setting a provider name by --name, an AWS Terraform provider named aws will be created.

You also create multiple providers by specifying the --name flag.

  1. $ vela provider add terraform-aws --name aws-dev --AWS_ACCESS_KEY_ID=xxx --AWS_SECRET_ACCESS_KEY=yyy --AWS_DEFAULT_REGION=us-east-1

Provision cloud resources

After a Terraform provider is authenticated, you can provision and/or consume cloud resources.