Version: v1.3

Extend Cloud Resources

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.

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 aws_s3_bucket.tf.

  1. resource "aws_s3_bucket" "bucket-acl" {
  2. bucket = var.bucket
  3. acl = var.acl
  4. }
  5. output "BUCKET_NAME" {
  6. value = aws_s3_bucket.bucket-acl.bucket_domain_name
  7. }
  8. variable "bucket" {
  9. description = "S3 bucket name"
  10. default = "vela-website"
  11. type = string
  12. }
  13. variable "acl" {
  14. description = "S3 bucket ACL"
  15. default = "private"
  16. type = string
  17. }

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.

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.

We use --local to accept Terraform resource or module from a local file to generate a ComponentDefinition.

  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. spec:
  13. schematic:
  14. terraform:
  15. configuration: |
  16. resource "aws_s3_bucket" "bucket-acl" {
  17. bucket = var.bucket
  18. acl = var.acl
  19. }
  20. output "BUCKET_NAME" {
  21. value = aws_s3_bucket.bucket-acl.bucket_domain_name
  22. }
  23. variable "bucket" {
  24. description = "S3 bucket name"
  25. default = "vela-website"
  26. type = string
  27. }
  28. variable "acl" {
  29. description = "S3 bucket ACL"
  30. default = "private"
  31. type = string
  32. }
  33. workload:
  34. definition:
  35. apiVersion: terraform.core.oam.dev/v1beta1
  36. kind: Configuration
  37. status: {}

We use --git to accept Terraform module or resource from a remote GitHub repository to generate a 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: {}

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>

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.

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 -n vela-system
  2. Generated docs for alibaba-eip in ./kubevela.io/docs/end-user/components/cloud-services/terraform/alibaba-eip.md

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

  1. $ vela def doc-gen alibaba-eip.yaml

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

Last updated on Nov 1, 2022 by Tianxin Dong