Update Terraform contribution doc (#462)
Added flag `--local` to accept local file of Terraform resource or module. Added examples in contribution doc Signed-off-by: Zheng Xi Zhou <zzxwill@gmail.com>
This commit is contained in:
parent
c128d09ae5
commit
88efd55fbd
|
@ -24,8 +24,10 @@ vela def init DEF_NAME [flags]
|
||||||
> vela def init my-def -i --output ./my-def.cue
|
> vela def init my-def -i --output ./my-def.cue
|
||||||
# Command below initiate a ComponentDefinition named my-webservice with the template parsed from ./template.yaml.
|
# Command below initiate a ComponentDefinition named my-webservice with the template parsed from ./template.yaml.
|
||||||
> vela def init my-webservice -i --template-yaml ./template.yaml
|
> vela def init my-webservice -i --template-yaml ./template.yaml
|
||||||
# Command below initiate a typed ComponentDefinition named vswitch from Alibaba Cloud.
|
# Initiate a Terraform ComponentDefinition named vswitch from Github for Alibaba Cloud.
|
||||||
> vela def init vswitch --type component --provider alibaba --desc xxx --git https://github.com/kubevela-contrib/terraform-modules.git --path alibaba/vswitch
|
> vela def init vswitch --type component --provider alibaba --desc xxx --git https://github.com/kubevela-contrib/terraform-modules.git --path alibaba/vswitch
|
||||||
|
# Initiate a Terraform ComponentDefinition named redis from local file for AWS.
|
||||||
|
> vela def init redis --type component --provider aws --desc "Terraform configuration for AWS Redis" --local redis.tf
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
@ -35,11 +37,12 @@ vela def init DEF_NAME [flags]
|
||||||
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
||||||
-h, --help help for init
|
-h, --help help for init
|
||||||
-i, --interactive Specify whether use interactive process to help generate definitions.
|
-i, --interactive Specify whether use interactive process to help generate definitions.
|
||||||
|
--local string Specify the local path of the configuration(HCL) file. Valid when --provider/-p is set.
|
||||||
-o, --output string Specify the output path of the generated definition. If empty, the definition will be printed in the console.
|
-o, --output string Specify the output path of the generated definition. If empty, the definition will be printed in the console.
|
||||||
--path string Specify which path the configuration(HCL) is stored in the Git repository. Valid when --git is set.
|
--path string Specify which path the configuration(HCL) is stored in the Git repository. Valid when --git is set.
|
||||||
-p, --provider alibaba Specify which provider the cloud resource definition belongs to. Only alibaba, `aws`, `azure` are supported.
|
-p, --provider alibaba Specify which provider the cloud resource definition belongs to. Only alibaba, `aws`, `azure` are supported.
|
||||||
-y, --template-yaml string Specify the template yaml file that definition will use to build the schema. If empty, a default template for the given definition type will be used.
|
-y, --template-yaml string Specify the template yaml file that definition will use to build the schema. If empty, a default template for the given definition type will be used.
|
||||||
-t, --type string Specify the type of the new definition. Valid types: scope, workflow-step, component, trait, policy, workload
|
-t, --type string Specify the type of the new definition. Valid types: component, trait, policy, workload, scope, workflow-step
|
||||||
```
|
```
|
||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
@ -49,4 +52,4 @@ vela def init DEF_NAME [flags]
|
||||||
#### Go Back to [CLI Commands](vela) Homepage.
|
#### Go Back to [CLI Commands](vela) Homepage.
|
||||||
|
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 12-Jan-2022, refer to [script in KubeVela](https://github.com/oam-dev/kubevela/tree/master/hack/docgen).
|
###### Auto generated by spf13/cobra on 20-Jan-2022, refer to [script in KubeVela](https://github.com/oam-dev/kubevela/tree/master/hack/docgen).
|
||||||
|
|
|
@ -8,18 +8,104 @@ platform engineers need to prepare ComponentDefinitions for cloud resources if e
|
||||||
|
|
||||||
Here is the guide to create Terraform typed ComponentDefinitions of cloud resources for cloud providers Alibaba Cloud, AWS and Azure.
|
Here is the guide to create Terraform typed ComponentDefinitions of cloud resources for cloud providers Alibaba Cloud, AWS and Azure.
|
||||||
|
|
||||||
# Alibaba Cloud
|
# Prerequisites
|
||||||
|
|
||||||
Take [Elastic IP](https://www.alibabacloud.com/help/doc-detail/36016.htm) as an example.
|
- [`vela` binary](../../install.mdx)
|
||||||
|
|
||||||
## Develop a Terraform resource or module
|
## 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.
|
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`.
|
||||||
|
|
||||||
|
```terraform
|
||||||
|
resource "aws_s3_bucket" "bucket-acl" {
|
||||||
|
bucket = var.bucket
|
||||||
|
acl = var.acl
|
||||||
|
}
|
||||||
|
|
||||||
|
output "BUCKET_NAME" {
|
||||||
|
value = aws_s3_bucket.bucket-acl.bucket_domain_name
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bucket" {
|
||||||
|
description = "S3 bucket name"
|
||||||
|
default = "vela-website"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "acl" {
|
||||||
|
description = "S3 bucket ACL"
|
||||||
|
default = "private"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
## 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.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$vela def init -h
|
||||||
|
|
||||||
|
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
||||||
|
--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.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$vela def init s3 --type component --provider aws --desc "Terraform configuration for AWS S3" --local aws_s3_bucket.tf
|
||||||
|
|
||||||
|
apiVersion: core.oam.dev/v1beta1
|
||||||
|
kind: ComponentDefinition
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
definition.oam.dev/description: Terraform configuration for AWS S3
|
||||||
|
creationTimestamp: null
|
||||||
|
labels:
|
||||||
|
type: terraform
|
||||||
|
name: aws-s3
|
||||||
|
namespace: vela-system
|
||||||
|
spec:
|
||||||
|
schematic:
|
||||||
|
terraform:
|
||||||
|
configuration: |
|
||||||
|
resource "aws_s3_bucket" "bucket-acl" {
|
||||||
|
bucket = var.bucket
|
||||||
|
acl = var.acl
|
||||||
|
}
|
||||||
|
|
||||||
|
output "BUCKET_NAME" {
|
||||||
|
value = aws_s3_bucket.bucket-acl.bucket_domain_name
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bucket" {
|
||||||
|
description = "S3 bucket name"
|
||||||
|
default = "vela-website"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "acl" {
|
||||||
|
description = "S3 bucket ACL"
|
||||||
|
default = "private"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
workload:
|
||||||
|
definition:
|
||||||
|
apiVersion: terraform.core.oam.dev/v1beta1
|
||||||
|
kind: Configuration
|
||||||
|
status: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
We use `--git` to accept Terraform module or resource from a remote GitHub repository to generate a ComponentDefinition.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ 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
|
$ 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
|
||||||
|
|
||||||
apiVersion: core.oam.dev/v1beta1
|
apiVersion: core.oam.dev/v1beta1
|
||||||
kind: ComponentDefinition
|
kind: ComponentDefinition
|
||||||
metadata:
|
metadata:
|
||||||
|
@ -43,8 +129,7 @@ spec:
|
||||||
status: {}
|
status: {}
|
||||||
```
|
```
|
||||||
|
|
||||||
The ComponentDefinition for Alibaba Cloud EIP is generated. You are warmly welcome to contribute this extended cloud
|
You are warmly welcome to contribute this extended cloud resource ComponentDefinition to [oam-dev/catalog](https://github.com/oam-dev/catalog/tree/master/addons/).
|
||||||
resource ComponentDefinition to [oam-dev/catalog](https://github.com/oam-dev/catalog/tree/master/addons/terraform-alibaba/definitions).
|
|
||||||
|
|
||||||
## Verify
|
## Verify
|
||||||
|
|
||||||
|
@ -83,27 +168,4 @@ $ vela def doc-gen alibaba-eip -n vela-system
|
||||||
Generated docs for alibaba-eip in ./kubevela.io/docs/end-user/components/cloud-services/terraform/alibaba-eip.md
|
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](https://github.com/oam-dev/kubevela.io#contributing-to-kubevela-en-docs) to submit the doc.
|
Move the file generated to [oam-dev/kubevela.io](https://github.com/oam-dev/kubevela.io) repo. Follow the [contribution guide](https://github.com/oam-dev/kubevela.io#contributing-to-kubevela-en-docs) to submit the doc.
|
||||||
|
|
||||||
# AWS, Azure and other cloud providers
|
|
||||||
|
|
||||||
This only difference from Alibaba Cloud lies in the section of [Generate ComponentDefinition](#generate-componentdefinition).
|
|
||||||
Please set `--provider` as `aws` or `azure` to generate the ComponentDefinition for an AWS or Azure cloud resource.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ vela def init -h
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
vela def init DEF_NAME [flags]
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
# Command below initiate a typed ComponentDefinition named vswitch from Alibaba Cloud.
|
|
||||||
> vela def init vswitch --type component --provider alibaba --desc xxx --git https://github.com/kubevela-contrib/terraform-modules.git --path alibaba/vswitch
|
|
||||||
|
|
||||||
Flags:
|
|
||||||
-d, --desc string Specify the description of the new definition.
|
|
||||||
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
|
||||||
-h, --help help for init
|
|
||||||
--path string Specify which path the configuration(HCL) is stored in the Git repository. Valid when --git is set.
|
|
||||||
-p, --provider alibaba Specify which provider the cloud resource definition belongs to. Only `alibaba`, `aws`, `azure` are supported.
|
|
||||||
```
|
|
||||||
|
|
|
@ -11,18 +11,104 @@ Terraform 使用任意的云资源。
|
||||||
|
|
||||||
以下是为云供应商阿里云、AWS 和 Azure 创建 Terraform 类型的云资源 ComponentDefinitions 的指南。
|
以下是为云供应商阿里云、AWS 和 Azure 创建 Terraform 类型的云资源 ComponentDefinitions 的指南。
|
||||||
|
|
||||||
# 阿里云
|
# 依赖
|
||||||
|
|
||||||
以 [弹性 IP](https://help.aliyun.com/document_detail/120192.html)为例。
|
- [`vela` 命令行](../../install.mdx)
|
||||||
|
|
||||||
## 开发 Terraform 资源或模块
|
## 开发 Terraform 资源或模块
|
||||||
|
|
||||||
为阿里云 EIP 资源创建一个 Terraform 资源或模块,并将其存储在 GitHub 库,如 https://github.com/oam-dev/terraform-alibaba-eip.git。
|
为云资源开发创建 Terraform 资源或模块。
|
||||||
|
|
||||||
|
比如我们为 AWS S3 bucket 开发了 Terraform 资源,并写入本地文件 `aws_s3_bucket.tf` 里,内容如下:
|
||||||
|
|
||||||
|
```terraform
|
||||||
|
resource "aws_s3_bucket" "bucket-acl" {
|
||||||
|
bucket = var.bucket
|
||||||
|
acl = var.acl
|
||||||
|
}
|
||||||
|
|
||||||
|
output "BUCKET_NAME" {
|
||||||
|
value = aws_s3_bucket.bucket-acl.bucket_domain_name
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bucket" {
|
||||||
|
description = "S3 bucket name"
|
||||||
|
default = "vela-website"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "acl" {
|
||||||
|
description = "S3 bucket ACL"
|
||||||
|
default = "private"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
我们也给阿里云 EIP 开发了 Terraform 模板,并存储在 GitHub 库 https://github.com/oam-dev/terraform-alibaba-eip.git。
|
||||||
|
|
||||||
## 生成 ComponentDefinition
|
## 生成 ComponentDefinition
|
||||||
|
|
||||||
|
通过运行 `vela def init` 命令,我们可以基于 Terraform 资源或模块的云资源生成一个 ComponentDefinition,Terraform 资源或模板可以来自本地文件,
|
||||||
|
也可以来自远程 GitHub 仓库。
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$vela def init -h
|
||||||
|
|
||||||
|
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
||||||
|
--local string Specify the local path of the configuration(HCL) file. Valid when --provider/-p is set.
|
||||||
|
```
|
||||||
|
|
||||||
|
我们使用 `--local` 来接受来自本地文件的 Terraform 资源或模块来生成 ComponentDefinition。
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$vela def init s3 --type component --provider aws --desc "Terraform configuration for AWS S3" --local aws_s3_bucket.tf
|
||||||
|
|
||||||
|
apiVersion: core.oam.dev/v1beta1
|
||||||
|
kind: ComponentDefinition
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
definition.oam.dev/description: Terraform configuration for AWS S3
|
||||||
|
creationTimestamp: null
|
||||||
|
labels:
|
||||||
|
type: terraform
|
||||||
|
name: aws-s3
|
||||||
|
namespace: vela-system
|
||||||
|
spec:
|
||||||
|
schematic:
|
||||||
|
terraform:
|
||||||
|
configuration: |
|
||||||
|
resource "aws_s3_bucket" "bucket-acl" {
|
||||||
|
bucket = var.bucket
|
||||||
|
acl = var.acl
|
||||||
|
}
|
||||||
|
|
||||||
|
output "BUCKET_NAME" {
|
||||||
|
value = aws_s3_bucket.bucket-acl.bucket_domain_name
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bucket" {
|
||||||
|
description = "S3 bucket name"
|
||||||
|
default = "vela-website"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "acl" {
|
||||||
|
description = "S3 bucket ACL"
|
||||||
|
default = "private"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
workload:
|
||||||
|
definition:
|
||||||
|
apiVersion: terraform.core.oam.dev/v1beta1
|
||||||
|
kind: Configuration
|
||||||
|
status: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
我们使用 `--git` 来接受来自远程 GitHub 仓库的 Terraform 模块或资源来生成 ComponentDefinition。
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ 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
|
$ 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
|
||||||
|
|
||||||
apiVersion: core.oam.dev/v1beta1
|
apiVersion: core.oam.dev/v1beta1
|
||||||
kind: ComponentDefinition
|
kind: ComponentDefinition
|
||||||
metadata:
|
metadata:
|
||||||
|
@ -46,7 +132,7 @@ spec:
|
||||||
status: {}
|
status: {}
|
||||||
```
|
```
|
||||||
|
|
||||||
阿里云 EIP 的 ComponentDefinition 已生成,我们热烈欢迎你将扩展的云资源的 ComponentDefinition 贡献到 [oam-dev/catalog](https://github.com/oam-dev/catalog/tree/master/addons/terraform-alibaba/definitions)。
|
我们热烈欢迎你将扩展的云资源的 ComponentDefinition 贡献到 [oam-dev/catalog](https://github.com/oam-dev/catalog/tree/master/addons/)。
|
||||||
|
|
||||||
## 验证
|
## 验证
|
||||||
|
|
||||||
|
@ -84,27 +170,4 @@ $ vela def doc-gen alibaba-eip -n vela-system
|
||||||
Generated docs for alibaba-eip in ./kubevela.io/docs/end-user/components/cloud-services/terraform/alibaba-eip.md
|
Generated docs for alibaba-eip in ./kubevela.io/docs/end-user/components/cloud-services/terraform/alibaba-eip.md
|
||||||
```
|
```
|
||||||
|
|
||||||
将生成的文件移到 oam-dev/catalog 库。参考 [贡献指南](https://github.com/oam-dev/kubevela.io#contributing-to-kubevela-en-docs) 来提交文档。
|
将生成的文件移到 [oam-dev/kubevela.io](https://github.com/oam-dev/kubevela.io) 库。参考 [贡献指南](https://github.com/oam-dev/kubevela.io#contributing-to-kubevela-en-docs) 来提交文档。
|
||||||
|
|
||||||
# AWS、Azure 和其他云供应商
|
|
||||||
|
|
||||||
这与阿里云唯一的区别在于[Generate ComponentDefinition](#生成-ComponentDefinition)部分。
|
|
||||||
请将 `--provider` 设置为 `aws` 或 `azure`,以便为 AWS 或 Azure 云资源生成 ComponentDefinition。
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ vela def init -h
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
vela def init DEF_NAME [flags]
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
# Command below initiate a typed ComponentDefinition named vswitch from Alibaba Cloud.
|
|
||||||
> vela def init vswitch --type component --provider alibaba --desc xxx --git https://github.com/kubevela-contrib/terraform-modules.git --path alibaba/vswitch
|
|
||||||
|
|
||||||
Flags:
|
|
||||||
-d, --desc string Specify the description of the new definition.
|
|
||||||
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
|
||||||
-h, --help help for init
|
|
||||||
--path string Specify which path the configuration(HCL) is stored in the Git repository. Valid when --git is set.
|
|
||||||
-p, --provider alibaba Specify which provider the cloud resource definition belongs to. Only `alibaba`, `aws`, `azure` are supported.
|
|
||||||
```
|
|
||||||
|
|
|
@ -11,18 +11,104 @@ Terraform 使用任意的云资源。
|
||||||
|
|
||||||
以下是为云供应商阿里云、AWS 和 Azure 创建 Terraform 类型的云资源 ComponentDefinitions 的指南。
|
以下是为云供应商阿里云、AWS 和 Azure 创建 Terraform 类型的云资源 ComponentDefinitions 的指南。
|
||||||
|
|
||||||
# 阿里云
|
# 依赖
|
||||||
|
|
||||||
以 [弹性 IP](https://help.aliyun.com/document_detail/120192.html)为例。
|
- [`vela` 命令行](../../install.mdx)
|
||||||
|
|
||||||
## 开发 Terraform 资源或模块
|
## 开发 Terraform 资源或模块
|
||||||
|
|
||||||
为阿里云 EIP 资源创建一个 Terraform 资源或模块,并将其存储在 GitHub 库,如 https://github.com/oam-dev/terraform-alibaba-eip.git。
|
为云资源开发创建 Terraform 资源或模块。
|
||||||
|
|
||||||
|
比如我们为 AWS S3 bucket 开发了 Terraform 资源,并写入本地文件 `aws_s3_bucket.tf` 里,内容如下:
|
||||||
|
|
||||||
|
```terraform
|
||||||
|
resource "aws_s3_bucket" "bucket-acl" {
|
||||||
|
bucket = var.bucket
|
||||||
|
acl = var.acl
|
||||||
|
}
|
||||||
|
|
||||||
|
output "BUCKET_NAME" {
|
||||||
|
value = aws_s3_bucket.bucket-acl.bucket_domain_name
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bucket" {
|
||||||
|
description = "S3 bucket name"
|
||||||
|
default = "vela-website"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "acl" {
|
||||||
|
description = "S3 bucket ACL"
|
||||||
|
default = "private"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
我们也给阿里云 EIP 开发了 Terraform 模板,并存储在 GitHub 库 https://github.com/oam-dev/terraform-alibaba-eip.git。
|
||||||
|
|
||||||
## 生成 ComponentDefinition
|
## 生成 ComponentDefinition
|
||||||
|
|
||||||
|
通过运行 `vela def init` 命令,我们可以基于 Terraform 资源或模块的云资源生成一个 ComponentDefinition,Terraform 资源或模板可以来自本地文件,
|
||||||
|
也可以来自远程 GitHub 仓库。
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$vela def init -h
|
||||||
|
|
||||||
|
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
||||||
|
--local string Specify the local path of the configuration(HCL) file. Valid when --provider/-p is set.
|
||||||
|
```
|
||||||
|
|
||||||
|
我们使用 `--local` 来接受来自本地文件的 Terraform 资源或模块来生成 ComponentDefinition。
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$vela def init s3 --type component --provider aws --desc "Terraform configuration for AWS S3" --local aws_s3_bucket.tf
|
||||||
|
|
||||||
|
apiVersion: core.oam.dev/v1beta1
|
||||||
|
kind: ComponentDefinition
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
definition.oam.dev/description: Terraform configuration for AWS S3
|
||||||
|
creationTimestamp: null
|
||||||
|
labels:
|
||||||
|
type: terraform
|
||||||
|
name: aws-s3
|
||||||
|
namespace: vela-system
|
||||||
|
spec:
|
||||||
|
schematic:
|
||||||
|
terraform:
|
||||||
|
configuration: |
|
||||||
|
resource "aws_s3_bucket" "bucket-acl" {
|
||||||
|
bucket = var.bucket
|
||||||
|
acl = var.acl
|
||||||
|
}
|
||||||
|
|
||||||
|
output "BUCKET_NAME" {
|
||||||
|
value = aws_s3_bucket.bucket-acl.bucket_domain_name
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bucket" {
|
||||||
|
description = "S3 bucket name"
|
||||||
|
default = "vela-website"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "acl" {
|
||||||
|
description = "S3 bucket ACL"
|
||||||
|
default = "private"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
workload:
|
||||||
|
definition:
|
||||||
|
apiVersion: terraform.core.oam.dev/v1beta1
|
||||||
|
kind: Configuration
|
||||||
|
status: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
我们使用 `--git` 来接受来自远程 GitHub 仓库的 Terraform 模块或资源来生成 ComponentDefinition。
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ 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
|
$ 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
|
||||||
|
|
||||||
apiVersion: core.oam.dev/v1beta1
|
apiVersion: core.oam.dev/v1beta1
|
||||||
kind: ComponentDefinition
|
kind: ComponentDefinition
|
||||||
metadata:
|
metadata:
|
||||||
|
@ -46,7 +132,7 @@ spec:
|
||||||
status: {}
|
status: {}
|
||||||
```
|
```
|
||||||
|
|
||||||
阿里云 EIP 的 ComponentDefinition 已生成,我们热烈欢迎你将扩展的云资源的 ComponentDefinition 贡献到 [oam-dev/catalog](https://github.com/oam-dev/catalog/tree/master/addons/terraform-alibaba/definitions)。
|
我们热烈欢迎你将扩展的云资源的 ComponentDefinition 贡献到 [oam-dev/catalog](https://github.com/oam-dev/catalog/tree/master/addons/)。
|
||||||
|
|
||||||
## 验证
|
## 验证
|
||||||
|
|
||||||
|
@ -84,27 +170,4 @@ $ vela def doc-gen alibaba-eip -n vela-system
|
||||||
Generated docs for alibaba-eip in ./kubevela.io/docs/end-user/components/cloud-services/terraform/alibaba-eip.md
|
Generated docs for alibaba-eip in ./kubevela.io/docs/end-user/components/cloud-services/terraform/alibaba-eip.md
|
||||||
```
|
```
|
||||||
|
|
||||||
将生成的文件移到 oam-dev/catalog 库。参考 [贡献指南](https://github.com/oam-dev/kubevela.io#contributing-to-kubevela-en-docs) 来提交文档。
|
将生成的文件移到 [oam-dev/kubevela.io](https://github.com/oam-dev/kubevela.io) 库。参考 [贡献指南](https://github.com/oam-dev/kubevela.io#contributing-to-kubevela-en-docs) 来提交文档。
|
||||||
|
|
||||||
# AWS、Azure 和其他云供应商
|
|
||||||
|
|
||||||
这与阿里云唯一的区别在于[Generate ComponentDefinition](#生成-ComponentDefinition)部分。
|
|
||||||
请将 `--provider` 设置为 `aws` 或 `azure`,以便为 AWS 或 Azure 云资源生成 ComponentDefinition。
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ vela def init -h
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
vela def init DEF_NAME [flags]
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
# Command below initiate a typed ComponentDefinition named vswitch from Alibaba Cloud.
|
|
||||||
> vela def init vswitch --type component --provider alibaba --desc xxx --git https://github.com/kubevela-contrib/terraform-modules.git --path alibaba/vswitch
|
|
||||||
|
|
||||||
Flags:
|
|
||||||
-d, --desc string Specify the description of the new definition.
|
|
||||||
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
|
||||||
-h, --help help for init
|
|
||||||
--path string Specify which path the configuration(HCL) is stored in the Git repository. Valid when --git is set.
|
|
||||||
-p, --provider alibaba Specify which provider the cloud resource definition belongs to. Only `alibaba`, `aws`, `azure` are supported.
|
|
||||||
```
|
|
||||||
|
|
|
@ -8,18 +8,104 @@ platform engineers need to prepare ComponentDefinitions for cloud resources if e
|
||||||
|
|
||||||
Here is the guide to create Terraform typed ComponentDefinitions of cloud resources for cloud providers Alibaba Cloud, AWS and Azure.
|
Here is the guide to create Terraform typed ComponentDefinitions of cloud resources for cloud providers Alibaba Cloud, AWS and Azure.
|
||||||
|
|
||||||
# Alibaba Cloud
|
# Prerequisites
|
||||||
|
|
||||||
Take [Elastic IP](https://www.alibabacloud.com/help/doc-detail/36016.htm) as an example.
|
- [`vela` binary](../../install.mdx)
|
||||||
|
|
||||||
## Develop a Terraform resource or module
|
## 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.
|
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`.
|
||||||
|
|
||||||
|
```terraform
|
||||||
|
resource "aws_s3_bucket" "bucket-acl" {
|
||||||
|
bucket = var.bucket
|
||||||
|
acl = var.acl
|
||||||
|
}
|
||||||
|
|
||||||
|
output "BUCKET_NAME" {
|
||||||
|
value = aws_s3_bucket.bucket-acl.bucket_domain_name
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bucket" {
|
||||||
|
description = "S3 bucket name"
|
||||||
|
default = "vela-website"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "acl" {
|
||||||
|
description = "S3 bucket ACL"
|
||||||
|
default = "private"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
## 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.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$vela def init -h
|
||||||
|
|
||||||
|
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
||||||
|
--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.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$vela def init s3 --type component --provider aws --desc "Terraform configuration for AWS S3" --local aws_s3_bucket.tf
|
||||||
|
|
||||||
|
apiVersion: core.oam.dev/v1beta1
|
||||||
|
kind: ComponentDefinition
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
definition.oam.dev/description: Terraform configuration for AWS S3
|
||||||
|
creationTimestamp: null
|
||||||
|
labels:
|
||||||
|
type: terraform
|
||||||
|
name: aws-s3
|
||||||
|
namespace: vela-system
|
||||||
|
spec:
|
||||||
|
schematic:
|
||||||
|
terraform:
|
||||||
|
configuration: |
|
||||||
|
resource "aws_s3_bucket" "bucket-acl" {
|
||||||
|
bucket = var.bucket
|
||||||
|
acl = var.acl
|
||||||
|
}
|
||||||
|
|
||||||
|
output "BUCKET_NAME" {
|
||||||
|
value = aws_s3_bucket.bucket-acl.bucket_domain_name
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bucket" {
|
||||||
|
description = "S3 bucket name"
|
||||||
|
default = "vela-website"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "acl" {
|
||||||
|
description = "S3 bucket ACL"
|
||||||
|
default = "private"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
workload:
|
||||||
|
definition:
|
||||||
|
apiVersion: terraform.core.oam.dev/v1beta1
|
||||||
|
kind: Configuration
|
||||||
|
status: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
We use `--git` to accept Terraform module or resource from a remote GitHub repository to generate a ComponentDefinition.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ 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
|
$ 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
|
||||||
|
|
||||||
apiVersion: core.oam.dev/v1beta1
|
apiVersion: core.oam.dev/v1beta1
|
||||||
kind: ComponentDefinition
|
kind: ComponentDefinition
|
||||||
metadata:
|
metadata:
|
||||||
|
@ -43,8 +129,7 @@ spec:
|
||||||
status: {}
|
status: {}
|
||||||
```
|
```
|
||||||
|
|
||||||
The ComponentDefinition for Alibaba Cloud EIP is generated. You are warmly welcome to contribute this extended cloud
|
You are warmly welcome to contribute this extended cloud resource ComponentDefinition to [oam-dev/catalog](https://github.com/oam-dev/catalog/tree/master/addons/).
|
||||||
resource ComponentDefinition to [oam-dev/catalog](https://github.com/oam-dev/catalog/tree/master/addons/terraform-alibaba/definitions).
|
|
||||||
|
|
||||||
## Verify
|
## Verify
|
||||||
|
|
||||||
|
@ -83,27 +168,4 @@ $ vela def doc-gen alibaba-eip -n vela-system
|
||||||
Generated docs for alibaba-eip in ./kubevela.io/docs/end-user/components/cloud-services/terraform/alibaba-eip.md
|
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](https://github.com/oam-dev/kubevela.io#contributing-to-kubevela-en-docs) to submit the doc.
|
Move the file generated to [oam-dev/kubevela.io](https://github.com/oam-dev/kubevela.io) repo. Follow the [contribution guide](https://github.com/oam-dev/kubevela.io#contributing-to-kubevela-en-docs) to submit the doc.
|
||||||
|
|
||||||
# AWS, Azure and other cloud providers
|
|
||||||
|
|
||||||
This only difference from Alibaba Cloud lies in the section of [Generate ComponentDefinition](#generate-componentdefinition).
|
|
||||||
Please set `--provider` as `aws` or `azure` to generate the ComponentDefinition for an AWS or Azure cloud resource.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ vela def init -h
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
vela def init DEF_NAME [flags]
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
# Command below initiate a typed ComponentDefinition named vswitch from Alibaba Cloud.
|
|
||||||
> vela def init vswitch --type component --provider alibaba --desc xxx --git https://github.com/kubevela-contrib/terraform-modules.git --path alibaba/vswitch
|
|
||||||
|
|
||||||
Flags:
|
|
||||||
-d, --desc string Specify the description of the new definition.
|
|
||||||
--git string Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.
|
|
||||||
-h, --help help for init
|
|
||||||
--path string Specify which path the configuration(HCL) is stored in the Git repository. Valid when --git is set.
|
|
||||||
-p, --provider alibaba Specify which provider the cloud resource definition belongs to. Only `alibaba`, `aws`, `azure` are supported.
|
|
||||||
```
|
|
||||||
|
|
Loading…
Reference in New Issue