Version: v1.2

Terraform Components

To enable end users to provision and consume cloud resources, platform engineers need to prepare ComponentDefinitions for cloud resources if end users’ requirements are beyond the built-in capabilities.

Here is the guide to create Terraform typed ComponentDefinitions of cloud resources for cloud providers Alibaba Cloud, AWS and Azure.

Alibaba Cloud

Take Elastic IP as an example.

Develop a Terraform resource or module

Create a Terraform resource or module for Alibaba Cloud EIP resource and store it in a GitHub repo like https://github.com/oam-dev/terraform-alibaba-eip.git.

Generate ComponentDefinition

  1. $ vela def init eip --type component --provider alibaba --desc "Terraform configuration for Alibaba Cloud Elastic IP" --git https://github.com/oam-dev/terraform-alibaba-eip.git
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: ComponentDefinition
  4. metadata:
  5. annotations:
  6. definition.oam.dev/description: Terraform configuration for Alibaba Cloud Elastic
  7. IP
  8. creationTimestamp: null
  9. labels:
  10. type: terraform
  11. name: alibaba-eip
  12. namespace: vela-system
  13. spec:
  14. schematic:
  15. terraform:
  16. configuration: https://github.com/oam-dev/terraform-alibaba-eip.git
  17. type: remote
  18. workload:
  19. definition:
  20. apiVersion: terraform.core.oam.dev/v1beta1
  21. kind: Configuration
  22. status: {}

The ComponentDefinition for Alibaba Cloud EIP is generated. You are warmly welcome to contribute this extended cloud resource ComponentDefinition to oam-dev/catalog.

Verify

You can quickly verify the ComponentDefinition by command vela show.

  1. $ vela show alibaba-eip
  2. # Properties
  3. +----------------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------+----------+---------+
  4. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  5. +----------------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------+----------+---------+
  6. | name | Name to be used on all resources as prefix. Default to 'TF-Module-EIP'. | string | true | |
  7. | bandwidth | Maximum bandwidth to the elastic public network, measured in Mbps (Mega bit per second). | number | true | |
  8. | writeConnectionSecretToRef | The secret which the cloud resource connection will be written to | [writeConnectionSecretToRef](#writeConnectionSecretToRef) | false | |
  9. +----------------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------+----------+---------+
  10. ## writeConnectionSecretToRef
  11. +-----------+-----------------------------------------------------------------------------+--------+----------+---------+
  12. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  13. +-----------+-----------------------------------------------------------------------------+--------+----------+---------+
  14. | name | The secret name which the cloud resource connection will be written to | string | true | |
  15. | namespace | The secret namespace which the cloud resource connection will be written to | string | false | |
  16. +-----------+-----------------------------------------------------------------------------+--------+----------+---------+

If the tables display, the ComponentDefinition should work. To take a step further, you can verify it by provision an actual EIP instance per the doc Provision cloud resources.

Generate documentation

You are encouraged to generate the documentation for your ComponentDefinition and submit it to KubeVela official site.

  1. $ vela def doc-gen alibaba-eip -n vela-system
  2. Generated docs for alibaba-eip in ./kubevela.io/docs/end-user/components/cloud-services/terraform/alibaba-eip.md

Move the file generated to oam-dev/catalog repo. Follow the contribution guide to submit the doc.

AWS, Azure and other cloud providers

This only difference from Alibaba Cloud lies in the section of Generate ComponentDefinition. Please set --provider as aws or azure to generate the ComponentDefinition for an AWS or Azure cloud resource.

  1. $ vela def init -h
  2. Usage:
  3. vela def init DEF_NAME [flags]
  4. Examples:
  5. # Command below initiate a typed ComponentDefinition named vswitch from Alibaba Cloud.
  6. > vela def init vswitch --type component --provider alibaba --desc xxx --git https://github.com/kubevela-contrib/terraform-modules.git --path alibaba/vswitch
  7. Flags:
  8. -d, --desc string Specify the description of the new definition.
  9. --git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
  10. -h, --help help for init
  11. --path string Specify which path the configuration(HCL) is stored in the Git repository. Valid when --git is set.
  12. -p, --provider alibaba Specify which provider the cloud resource definition belongs to. Only `alibaba`, `aws`, `azure` are supported.