Extend Cloud Resources

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

Prerequisites

Create a Terraform resource or module for a cloud resource.

For example, we created a Terraform resource for AWS S3 bucket, and stored it in a local file named .

We also created a Terraform module for Alibaba Cloud EIP, and stored it in GitHub repository https://github.com/oam-dev/terraform-alibaba-eip.git.

Generate ComponentDefinition

By running vela def init command, we can generate a ComponentDefinition for a cloud resource based on Terraform resource or module either from a local file, or from a remote GitHub repository.

  1. $ vela def init -h
  2. --git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
  3. --local string Specify the local path of the configuration(HCL) file. Valid when --provider/-p is set.
  1. $ vela def init s3 --type component --provider aws --desc "Terraform configuration for AWS S3" --local aws_s3_bucket.tf
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: ComponentDefinition
  4. metadata:
  5. annotations:
  6. definition.oam.dev/description: Terraform configuration for AWS S3
  7. creationTimestamp: null
  8. labels:
  9. type: terraform
  10. name: aws-s3
  11. namespace: vela-system
  12. schematic:
  13. terraform:
  14. configuration: |
  15. resource "aws_s3_bucket" "bucket-acl" {
  16. bucket = var.bucket
  17. acl = var.acl
  18. output "BUCKET_NAME" {
  19. value = aws_s3_bucket.bucket-acl.bucket_domain_name
  20. }
  21. variable "bucket" {
  22. description = "S3 bucket name"
  23. default = "vela-website"
  24. type = string
  25. }
  26. variable "acl" {
  27. description = "S3 bucket ACL"
  28. default = "private"
  29. type = string
  30. }
  31. workload:
  32. apiVersion: terraform.core.oam.dev/v1beta1
  33. kind: Configuration
  34. status: {}

We use --git to accept Terraform module or resource from a remote GitHub repository to generate a ComponentDefinition.

You are warmly welcome to contribute this extended cloud resource ComponentDefinition to oam-dev/catalog.

Write the generated ComponentDefinition into a file named terraform-<ComponentDefinition_NAME>.yaml and apply it to the running Kubernetes cluster.

  1. kubectl apply -f <FILENAME>

Verify

You can quickly verify the ComponentDefinition by command vela show. It may be a bit slow if you’re loading terraform module from remote git server for the first time. After that, vela will cache the data in folder. You may need to clean up the cached data from this folder if you want to update the module.

  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.

The end user will be able to use the component in an application like below, he must follow the spec as vela show:

You can refer to scenario docs such as Provision cloud resources for more real use cases.

Generate documentation

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

By running vela def doc-gen command, we can generate related docs for the ComponentDefinition either from a local file, or from the running application on kubernetes cluster.

If you choose to generate docs from running cluster, you should provide the name of the ComponentDefinition and the namespace which it is running in.

  1. $ vela def doc-gen alibaba-eip --path ./kubevela.io/docs/end-user/components/cloud-services/terraform/

If you choose to generate docs from local ComponentDefinition file, you should provide the file path.

    Move the file generated to repo. Follow the contribution guide to submit the doc.