Version: v1.1

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.

Develop a ComponentDefinition for a cloud resource

Alibaba Cloud

Take Elastic IP as an example.

Develop a Terraform resource or module for the cloud resource

We recommend you to search the required cloud resource module in Terraform official module registry. If no luck, you can create a Terraform resource or module yourself per Terraform Alibaba Cloud Provider specifications.

  1. module "eip" {
  2. source = "github.com/zzxwill/terraform-alicloud-eip"
  3. name = var.name
  4. bandwidth = var.bandwidth
  5. }
  6. variable "name" {
  7. description = "Name to be used on all resources as prefix. Default to 'TF-Module-EIP'."
  8. default = "TF-Module-EIP"
  9. type = string
  10. }
  11. variable "bandwidth" {
  12. description = "Maximum bandwidth to the elastic public network, measured in Mbps (Mega bit per second)."
  13. type = number
  14. default = 5
  15. }
  16. output "EIP_ADDRESS" {
  17. description = "The elastic ip address."
  18. value = module.eip.this_eip_address.0
  19. }

For Alibaba Cloud EIP, here is the complete ComponentDefinition. You are warmly welcome to contribute this extended cloud resource ComponentDefinition to oam-dev/kubevela.

  1. apiVersion: core.oam.dev/v1alpha2
  2. kind: ComponentDefinition
  3. metadata:
  4. name: alibaba-eip
  5. namespace: {{.Values.systemDefinitionNamespace}}
  6. annotations:
  7. definition.oam.dev/description: Terraform configuration for Alibaba Cloud Elastic IP
  8. labels:
  9. type: terraform
  10. spec:
  11. workload:
  12. definition:
  13. apiVersion: terraform.core.oam.dev/v1beta1
  14. kind: Configuration
  15. schematic:
  16. terraform:
  17. configuration: |
  18. module "eip" {
  19. source = "github.com/zzxwill/terraform-alicloud-eip"
  20. name = var.name
  21. bandwidth = var.bandwidth
  22. }
  23. variable "name" {
  24. description = "Name to be used on all resources as prefix. Default to 'TF-Module-EIP'."
  25. default = "TF-Module-EIP"
  26. type = string
  27. }
  28. variable "bandwidth" {
  29. description = "Maximum bandwidth to the elastic public network, measured in Mbps (Mega bit per second)."
  30. type = number
  31. default = 5
  32. }
  33. output "EIP_ADDRESS" {
  34. description = "The elastic ip address."
  35. value = module.eip.this_eip_address.0
  36. }

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.