Version: v1.2

Terraform 组件

对云资源的集成需求往往是最频繁出现,比如你可能希望数据库、中间件等服务使用阿里云、AWS 等云厂商的,以获得生产级别的可用性并免去运维的麻烦。 Terraform 是目前业内支持云资源最广泛也最受欢迎的组件,KubeVela 对 Terraform 进行了额外的支持,使得用户可以通过 Kubernetes CRD 的方式配合 Terraform 使用任意的云资源。

为了使最终用户能够部署和消费云资源,当用户的要求超出了 内置云资源的能力, 管理员需要要为云资源准备 ComponentDefinitions。

以下是为云供应商阿里云、AWS 和 Azure 创建 Terraform 类型的云资源 ComponentDefinitions 的指南。

阿里云

弹性 IP为例。

开发 Terraform 资源或模块

为阿里云 EIP 资源创建一个 Terraform 资源或模块,并将其存储在 GitHub 库,如 https://github.com/oam-dev/terraform-alibaba-eip.git。

生成 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: {}

阿里云 EIP 的 ComponentDefinition 已生成,我们热烈欢迎你将扩展的云资源的 ComponentDefinition 贡献到 oam-dev/catalog

验证

你可以通过 vela show 命令快速验证 ComponentDefinition。

  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. +-----------+-----------------------------------------------------------------------------+--------+----------+---------+

如果表格能正常出来,ComponentDefinition 应该就可以工作了。更进一步,你可以通过文档部署云资源创建一个实际的 EIP 来验证。

生成文档

我们鼓励你为你的 ComponentDefinition 生成文档并提交给 [KubeVela官方网站](https://github.com/oam-dev/kubevela.io)。

  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

将生成的文件移到 oam-dev/catalog 库。参考 贡献指南 来提交文档。

AWS、Azure 和其他云供应商

这与阿里云唯一的区别在于Generate ComponentDefinition部分。 请将 --provider 设置为 awsazure,以便为 AWS 或 Azure 云资源生成 ComponentDefinition。

  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.