From d083039a321983fc944ad1da1dcd1bf5e7a81255 Mon Sep 17 00:00:00 2001 From: Zheng Xi Zhou Date: Thu, 28 Oct 2021 11:37:41 +0800 Subject: [PATCH] Fix: backport all Terraform related features to release-1.1 (#2553) Copy all Terraform related code to release-1.1 to fix probelms and support features. Fix #2547 --- apis/core.oam.dev/common/types.go | 3 + .../crds/core.oam.dev_traitdefinitions.yaml | 8 + .../core.oam.dev_workloaddefinitions.yaml | 8 + .../core.oam.dev_applicationrevisions.yaml | 32 +++ .../core.oam.dev_componentdefinitions.yaml | 8 + .../core.oam.dev_definitionrevisions.yaml | 16 ++ .../crds/core.oam.dev_policydefinitions.yaml | 4 + .../crds/core.oam.dev_traitdefinitions.yaml | 8 + .../core.oam.dev_workflowstepdefinitions.yaml | 4 + .../core.oam.dev_workloaddefinitions.yaml | 8 + .../addons/terraform-provider-alibaba.yaml | 2 +- .../addons/terraform-provider-aws.yaml | 61 +++++ .../vela-core/templates/addons/terraform.yaml | 251 ++++-------------- .../core.oam.dev_applicationrevisions.yaml | 32 +++ .../core.oam.dev_definitionrevisions.yaml | 16 ++ .../crds/core.oam.dev_policydefinitions.yaml | 4 + .../crds/core.oam.dev_traitdefinitions.yaml | 8 + .../core.oam.dev_workflowstepdefinitions.yaml | 4 + .../core.oam.dev_workloaddefinitions.yaml | 8 + go.mod | 2 +- go.sum | 4 +- .../core.oam.dev_applicationrevisions.yaml | 32 +++ .../core.oam.dev_componentdefinitions.yaml | 8 + .../core.oam.dev_definitionrevisions.yaml | 16 ++ .../crds/core.oam.dev_policydefinitions.yaml | 4 + .../crds/core.oam.dev_traitdefinitions.yaml | 8 + .../core.oam.dev_workflowstepdefinitions.yaml | 4 + .../core.oam.dev_workloaddefinitions.yaml | 8 + pkg/appfile/appfile.go | 1 + .../auto-gen/terraform-provider-alibaba.yaml | 2 +- .../auto-gen/terraform-provider-aws.yaml | 49 ++++ vela-templates/addons/auto-gen/terraform.yaml | 251 ++++-------------- .../terraform-provider-alibaba/template.yaml | 2 +- .../terraform-provider-aws/template.yaml | 51 ++++ .../definitions/terraform-alibaba-ack.yaml | 196 +------------- .../definitions/terraform-alibaba-rds.yaml | 13 +- .../definitions/terraform-aws-s3.yaml | 37 +++ vela-templates/addons/terraform/template.yaml | 2 +- 38 files changed, 584 insertions(+), 591 deletions(-) create mode 100644 charts/vela-core/templates/addons/terraform-provider-aws.yaml create mode 100644 vela-templates/addons/auto-gen/terraform-provider-aws.yaml create mode 100644 vela-templates/addons/terraform-provider-aws/template.yaml create mode 100644 vela-templates/addons/terraform/definitions/terraform-aws-s3.yaml diff --git a/apis/core.oam.dev/common/types.go b/apis/core.oam.dev/common/types.go index 363df57fd..3cb3f1986 100644 --- a/apis/core.oam.dev/common/types.go +++ b/apis/core.oam.dev/common/types.go @@ -114,6 +114,9 @@ type Terraform struct { // +kubebuilder:validation:Enum:=hcl;json;remote Type string `json:"type,omitempty"` + // Path is the sub-directory of remote git repository. It's valid when remote is set + Path string `json:"path,omitempty"` + // ProviderReference specifies the reference to Provider ProviderReference *types.Reference `json:"providerRef,omitempty"` } diff --git a/charts/oam-runtime/crds/core.oam.dev_traitdefinitions.yaml b/charts/oam-runtime/crds/core.oam.dev_traitdefinitions.yaml index 6d694258f..3f33343d6 100644 --- a/charts/oam-runtime/crds/core.oam.dev_traitdefinitions.yaml +++ b/charts/oam-runtime/crds/core.oam.dev_traitdefinitions.yaml @@ -188,6 +188,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -468,6 +472,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/oam-runtime/crds/core.oam.dev_workloaddefinitions.yaml b/charts/oam-runtime/crds/core.oam.dev_workloaddefinitions.yaml index 80d37924e..394473b85 100644 --- a/charts/oam-runtime/crds/core.oam.dev_workloaddefinitions.yaml +++ b/charts/oam-runtime/crds/core.oam.dev_workloaddefinitions.yaml @@ -193,6 +193,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -454,6 +458,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml b/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml index 306b2ace4..028b2b53e 100644 --- a/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml +++ b/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml @@ -1232,6 +1232,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -1635,6 +1639,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -1936,6 +1944,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -3360,6 +3372,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -3656,6 +3672,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -4041,6 +4061,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -4305,6 +4329,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -4585,6 +4613,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml b/charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml index 10530b945..519bb7a93 100644 --- a/charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml @@ -179,6 +179,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -463,6 +467,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-core/crds/core.oam.dev_definitionrevisions.yaml b/charts/vela-core/crds/core.oam.dev_definitionrevisions.yaml index 4e81135c2..d09f351d3 100644 --- a/charts/vela-core/crds/core.oam.dev_definitionrevisions.yaml +++ b/charts/vela-core/crds/core.oam.dev_definitionrevisions.yaml @@ -222,6 +222,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -506,6 +510,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -783,6 +791,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -1041,6 +1053,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-core/crds/core.oam.dev_policydefinitions.yaml b/charts/vela-core/crds/core.oam.dev_policydefinitions.yaml index 07169c704..16eeb0635 100644 --- a/charts/vela-core/crds/core.oam.dev_policydefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_policydefinitions.yaml @@ -151,6 +151,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml b/charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml index 6d694258f..3f33343d6 100644 --- a/charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml @@ -188,6 +188,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -468,6 +472,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-core/crds/core.oam.dev_workflowstepdefinitions.yaml b/charts/vela-core/crds/core.oam.dev_workflowstepdefinitions.yaml index 025dee2f1..880959871 100644 --- a/charts/vela-core/crds/core.oam.dev_workflowstepdefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_workflowstepdefinitions.yaml @@ -148,6 +148,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml b/charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml index 80d37924e..394473b85 100644 --- a/charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml @@ -193,6 +193,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -454,6 +458,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-core/templates/addons/terraform-provider-alibaba.yaml b/charts/vela-core/templates/addons/terraform-provider-alibaba.yaml index 23c63eb3d..6e1c760c2 100644 --- a/charts/vela-core/templates/addons/terraform-provider-alibaba.yaml +++ b/charts/vela-core/templates/addons/terraform-provider-alibaba.yaml @@ -16,7 +16,7 @@ data: apiVersion: v1 kind: Secret metadata: - name: alibaba-provider-secret + name: alibaba-account-creds namespace: vela-system stringData: credentials: | diff --git a/charts/vela-core/templates/addons/terraform-provider-aws.yaml b/charts/vela-core/templates/addons/terraform-provider-aws.yaml new file mode 100644 index 000000000..cad0867ee --- /dev/null +++ b/charts/vela-core/templates/addons/terraform-provider-aws.yaml @@ -0,0 +1,61 @@ +apiVersion: v1 +data: + application: | + apiVersion: core.oam.dev/v1beta1 + kind: Application + metadata: + annotations: + addons.oam.dev/description: Kubernetes Terraform Controller for AWS + addons.oam.dev/name: terraform/provider-aws + name: terraform-provider-aws + namespace: default + spec: + components: + - name: aws-account-creds + properties: + apiVersion: v1 + kind: Secret + metadata: + name: aws-account-creds + namespace: vela-system + stringData: + credentials: | + awsAccessKeyID: [[ index .Args "AWS_ACCESS_KEY_ID" ]] + awsSecretAccessKey: [[ index .Args "AWS_SECRET_ACCESS_KEY" ]] + awsSessionToken: [[ index .Args "AWS_SESSION_TOKEN" ]] + type: Opaque + type: raw + - name: aws + properties: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Provider + metadata: + name: aws + namespace: default + spec: + credentials: + secretRef: + key: credentials + name: aws-account-creds + namespace: vela-system + source: Secret + provider: aws + region: '[[ index .Args "AWS_DEFAULT_REGION" ]]' + type: raw + status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 +kind: ConfigMap +metadata: + annotations: + addons.oam.dev/description: Kubernetes Terraform Controller for AWS + addons.oam.dev/name: terraform/provider-aws + labels: + addons.oam.dev/type: terraform-provider-aws + name: terraform-provider-aws + namespace: {{.Values.systemDefinitionNamespace}} diff --git a/charts/vela-core/templates/addons/terraform.yaml b/charts/vela-core/templates/addons/terraform.yaml index 34a462aef..59028cf1b 100644 --- a/charts/vela-core/templates/addons/terraform.yaml +++ b/charts/vela-core/templates/addons/terraform.yaml @@ -23,7 +23,7 @@ data: chart: terraform-controller repoType: helm url: https://charts.kubevela.net/addons - version: 0.1.19 + version: 0.2.6 type: helm - name: alibaba-ack properties: @@ -40,199 +40,9 @@ data: spec: schematic: terraform: - configuration: | - module "kubernetes" { - source = "github.com/zzxwill/terraform-alicloud-kubernetes" - new_nat_gateway = true - vpc_name = var.vpc_name - vpc_cidr = var.vpc_cidr - vswitch_name_prefix = var.vswitch_name_prefix - vswitch_cidrs = var.vswitch_cidrs - master_instance_types = var.master_instance_types - worker_instance_types = var.worker_instance_types - k8s_pod_cidr = var.k8s_pod_cidr - k8s_service_cidr = var.k8s_service_cidr - k8s_worker_number = var.k8s_worker_number - cpu_core_count = var.cpu_core_count - memory_size = var.memory_size - zone_id = var.zone_id - k8s_version = var.k8s_version - k8s_name_prefix = var.k8s_name_prefix - } - ###################### - # Instance types variables - ###################### - variable "cpu_core_count" { - description = "CPU core count is used to fetch instance types." - type = number - default = 4 - } - variable "memory_size" { - description = "Memory size used to fetch instance types." - type = number - default = 8 - } - ###################### - # VPC variables - ###################### - variable "vpc_name" { - description = "The vpc name used to create a new vpc when 'vpc_id' is not specified. Default to variable `example_name`" - type = string - default = "tf-k8s-vpc" - } - variable "vpc_cidr" { - description = "The cidr block used to launch a new vpc when 'vpc_id' is not specified." - type = string - default = "10.0.0.0/8" - } - ###################### - # VSwitch variables - ###################### - variable "vswitch_name_prefix" { - type = string - description = "The vswitch name prefix used to create several new vswitches. Default to variable 'example_name'." - default = "tf-k8s-vsw" - } - variable "number_format" { - description = "The number format used to output." - type = string - default = "%02d" - } - variable "vswitch_ids" { - description = "List of existing vswitch id." - type = list - default = [] - } - variable "vswitch_cidrs" { - description = "List of cidr blocks used to create several new vswitches when 'vswitch_ids' is not specified." - type = list - default = [ - "10.1.0.0/16", - "10.2.0.0/16", - "10.3.0.0/16"] - } - variable "k8s_name_prefix" { - description = "The name prefix used to create several kubernetes clusters. Default to variable `example_name`" - type = string - default = "poc" - } - variable "new_nat_gateway" { - type = bool - description = "Whether to create a new nat gateway. In this template, a new nat gateway will create a nat gateway, eip and server snat entries." - default = true - } - variable "master_instance_types" { - description = "The ecs instance types used to launch master nodes." - type = list - default = [ - # hongkong - "ecs.sn1ne.xlarge", - # hongkong - "ecs.c6.xlarge", - # hongkong - "ecs.c4.xlarge", - # hongkong - "ecs.c5.xlarge", - "ecs.n4.xlarge", - # "ecs.n1.large", - # "ecs.sn1.large", - # "ecs.s6-c1m2.xlarge", - # "ecs.c6e.xlarge" - ] - } - variable "worker_instance_types" { - description = "The ecs instance types used to launch worker nodes." - type = list - default = [ - # hongkong - "ecs.sn1ne.xlarge", - # hongkong - "ecs.c6.xlarge", - # hongkong - "ecs.c4.xlarge", - # hongkong - "ecs.c6e.xlarge", - "ecs.n4.xlarge", - // "ecs.n1.large", - // "ecs.sn1.large", - // "ecs.s6-c1m2.xlarge" - ] - } - variable "node_cidr_mask" { - type = number - description = "The node cidr block to specific how many pods can run on single node. Valid values: [24-28]." - default = 24 - } - variable "enable_ssh" { - description = "Enable login to the node through SSH." - type = bool - default = true - } - variable "install_cloud_monitor" { - description = "Install cloud monitor agent on ECS." - type = bool - default = true - } - variable "cpu_policy" { - type = string - description = "kubelet cpu policy. Valid values: 'none','static'. Default to 'none'." - default = "none" - } - variable "proxy_mode" { - description = "Proxy mode is option of kube-proxy. Valid values: 'ipvs','iptables'. Default to 'iptables'." - type = string - default = "iptables" - } - variable "password" { - description = "The password of ECS instance." - type = string - default = "Just4Test" - } - variable "k8s_worker_number" { - description = "The number of worker nodes in kubernetes cluster." - type = number - default = 2 - } - # k8s_pod_cidr is only for flannel network - variable "k8s_pod_cidr" { - description = "The kubernetes pod cidr block. It cannot be equals to vpc's or vswitch's and cannot be in them." - type = string - default = "172.20.0.0/16" - } - variable "k8s_service_cidr" { - description = "The kubernetes service cidr block. It cannot be equals to vpc's or vswitch's or pod's and cannot be in them." - type = string - default = "192.168.0.0/16" - } - variable "k8s_version" { - description = "The version of the kubernetes version. Valid values: '1.16.6-aliyun.1','1.14.8-aliyun.1'. Default to '1.16.6-aliyun.1'." - type = string - default = "1.20.4-aliyun.1" - } - variable "zone_id" { - description = "Availability Zone ID" - type = string - default = "cn-hongkong-b" - # "cn-beijing-a" - } - output "name" { - value = module.kubernetes.name - } - output "kubeconfig" { - value = module.kubernetes.kubeconfig - } - output "cluster_ca_cert" { - value = module.kubernetes.cluster_ca_cert - } - output "client_cert" { - value = module.kubernetes.client_cert - } - output "client_key" { - value = module.kubernetes.client_key - } - output "api_server_internet" { - value = module.kubernetes.api_server_internet - } + configuration: https://github.com/kubevela-contrib/terraform-modules.git + path: alibaba/cs/dedicated-kubernetes + type: remote workload: definition: apiVersion: terraform.core.oam.dev/v1beta1 @@ -304,7 +114,7 @@ data: terraform: configuration: | module "rds" { - source = "terraform-alicloud-modules/rds/alicloud" + source = "github.com/kubevela-contrib/terraform-alicloud-rds" engine = "MySQL" engine_version = "8.0" instance_type = "rds.mysql.c1.large" @@ -312,6 +122,8 @@ data: instance_name = var.instance_name account_name = var.account_name password = var.password + allocate_public_connection = var.allocate_public_connection + security_ips = ["0.0.0.0/0",] } output "DB_NAME" { @@ -329,6 +141,9 @@ data: output "DB_PASSWORD" { value = var.password } + output "DB_PUBLIC_HOST" { + value = module.rds.db_public_connection_string + } variable "instance_name" { description = "RDS instance name" @@ -347,6 +162,52 @@ data: type = string default = "Xyfff83jfewGGfaked" } + + variable "allocate_public_connection" { + description = "Whether to allocate public connection for a RDS instance." + type = bool + default = true + } + workload: + definition: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Configuration + type: raw + - name: aws-s3 + properties: + apiVersion: core.oam.dev/v1alpha2 + kind: ComponentDefinition + metadata: + annotations: + definition.oam.dev/description: Terraform configuration for AWS S3 + 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 diff --git a/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml b/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml index 306b2ace4..028b2b53e 100644 --- a/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml @@ -1232,6 +1232,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -1635,6 +1639,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -1936,6 +1944,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -3360,6 +3372,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -3656,6 +3672,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -4041,6 +4061,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -4305,6 +4329,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -4585,6 +4613,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-minimal/crds/core.oam.dev_definitionrevisions.yaml b/charts/vela-minimal/crds/core.oam.dev_definitionrevisions.yaml index 4e81135c2..d09f351d3 100644 --- a/charts/vela-minimal/crds/core.oam.dev_definitionrevisions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_definitionrevisions.yaml @@ -222,6 +222,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -506,6 +510,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -783,6 +791,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -1041,6 +1053,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-minimal/crds/core.oam.dev_policydefinitions.yaml b/charts/vela-minimal/crds/core.oam.dev_policydefinitions.yaml index 07169c704..16eeb0635 100644 --- a/charts/vela-minimal/crds/core.oam.dev_policydefinitions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_policydefinitions.yaml @@ -151,6 +151,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-minimal/crds/core.oam.dev_traitdefinitions.yaml b/charts/vela-minimal/crds/core.oam.dev_traitdefinitions.yaml index 6d694258f..3f33343d6 100644 --- a/charts/vela-minimal/crds/core.oam.dev_traitdefinitions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_traitdefinitions.yaml @@ -188,6 +188,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -468,6 +472,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-minimal/crds/core.oam.dev_workflowstepdefinitions.yaml b/charts/vela-minimal/crds/core.oam.dev_workflowstepdefinitions.yaml index 025dee2f1..880959871 100644 --- a/charts/vela-minimal/crds/core.oam.dev_workflowstepdefinitions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_workflowstepdefinitions.yaml @@ -148,6 +148,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/charts/vela-minimal/crds/core.oam.dev_workloaddefinitions.yaml b/charts/vela-minimal/crds/core.oam.dev_workloaddefinitions.yaml index 80d37924e..394473b85 100644 --- a/charts/vela-minimal/crds/core.oam.dev_workloaddefinitions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_workloaddefinitions.yaml @@ -193,6 +193,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -454,6 +458,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/go.mod b/go.mod index 48c8cd966..41ff77ae5 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/mitchellh/hashstructure/v2 v2.0.1 github.com/oam-dev/cluster-gateway v1.1.2 github.com/oam-dev/terraform-config-inspect v0.0.0-20210418082552-fc72d929aa28 - github.com/oam-dev/terraform-controller v0.2.4 + github.com/oam-dev/terraform-controller v0.2.6 github.com/olekukonko/tablewriter v0.0.5 github.com/onsi/ginkgo v1.16.4 github.com/onsi/gomega v1.16.0 diff --git a/go.sum b/go.sum index 639b163f9..fb0b5a937 100644 --- a/go.sum +++ b/go.sum @@ -1206,8 +1206,8 @@ github.com/oam-dev/stern v1.13.0-alpha h1:EVjM8Qvh6LssB6t4RZrjf9DtCq1cz+/cy6OF7f github.com/oam-dev/stern v1.13.0-alpha/go.mod h1:AOkvfFUv0Arz7GBi0jz7S0Jsu4K/kdvSjNsnRt1+BIg= github.com/oam-dev/terraform-config-inspect v0.0.0-20210418082552-fc72d929aa28 h1:tD8HiFKnt0jnwdTWjeqUnfnUYLD/+Nsmj8ZGIxqDWiU= github.com/oam-dev/terraform-config-inspect v0.0.0-20210418082552-fc72d929aa28/go.mod h1:Mu8i0/DdplvnjwRbAYPsc8+LRR27n/mp8VWdkN10GzE= -github.com/oam-dev/terraform-controller v0.2.4 h1:yGgIzm2EWNghuRutnChrRfhMjdlU/jE/cLfBizCgE24= -github.com/oam-dev/terraform-controller v0.2.4/go.mod h1:wd4rnqnJzz274Sg1/qoeIhBx1rvTZ/ECzXoMff0ucR0= +github.com/oam-dev/terraform-controller v0.2.6 h1:aoEj4sfxDMBdTkM5uKYmjVFOgjhYeYBm0xzdRb4+Xu0= +github.com/oam-dev/terraform-controller v0.2.6/go.mod h1:xFSCd3Nwuh6P1HEpx5jDnLzN35T9hoH53zdojDYE6LI= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml index 5813fd711..79b8b8b03 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml @@ -1232,6 +1232,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -1635,6 +1639,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -1936,6 +1944,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -3360,6 +3372,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -3656,6 +3672,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -4041,6 +4061,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -4305,6 +4329,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -4585,6 +4613,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote + git repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_componentdefinitions.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_componentdefinitions.yaml index a29c120d1..c8edcfbc4 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_componentdefinitions.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_componentdefinitions.yaml @@ -179,6 +179,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -463,6 +467,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_definitionrevisions.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_definitionrevisions.yaml index a58389fd2..8ffc3eaac 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_definitionrevisions.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_definitionrevisions.yaml @@ -222,6 +222,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -506,6 +510,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -783,6 +791,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -1041,6 +1053,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git + repository. It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_policydefinitions.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_policydefinitions.yaml index 8f71e4c52..925e30f5f 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_policydefinitions.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_policydefinitions.yaml @@ -151,6 +151,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_traitdefinitions.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_traitdefinitions.yaml index 5cce855a2..3b54c2a6e 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_traitdefinitions.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_traitdefinitions.yaml @@ -188,6 +188,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -468,6 +472,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_workflowstepdefinitions.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_workflowstepdefinitions.yaml index 91c8228f7..3d2de420f 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_workflowstepdefinitions.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_workflowstepdefinitions.yaml @@ -148,6 +148,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_workloaddefinitions.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_workloaddefinitions.yaml index 419a9e8f0..9b48f018f 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_workloaddefinitions.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_workloaddefinitions.yaml @@ -193,6 +193,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider @@ -454,6 +458,10 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + path: + description: Path is the sub-directory of remote git repository. + It's valid when remote is set + type: string providerRef: description: ProviderReference specifies the reference to Provider diff --git a/pkg/appfile/appfile.go b/pkg/appfile/appfile.go index 89e78d3c7..32b97801c 100644 --- a/pkg/appfile/appfile.go +++ b/pkg/appfile/appfile.go @@ -669,6 +669,7 @@ func generateTerraformConfigurationWorkload(wl *Workload, ns string) (*unstructu configuration.Spec.JSON = wl.FullTemplate.Terraform.Configuration case "remote": configuration.Spec.Remote = wl.FullTemplate.Terraform.Configuration + configuration.Spec.Path = wl.FullTemplate.Terraform.Path } if wl.FullTemplate.Terraform.ProviderReference != nil { diff --git a/vela-templates/addons/auto-gen/terraform-provider-alibaba.yaml b/vela-templates/addons/auto-gen/terraform-provider-alibaba.yaml index 635f926aa..b7238aa06 100644 --- a/vela-templates/addons/auto-gen/terraform-provider-alibaba.yaml +++ b/vela-templates/addons/auto-gen/terraform-provider-alibaba.yaml @@ -13,7 +13,7 @@ spec: apiVersion: v1 kind: Secret metadata: - name: alibaba-provider-secret + name: alibaba-account-creds namespace: vela-system stringData: credentials: | diff --git a/vela-templates/addons/auto-gen/terraform-provider-aws.yaml b/vela-templates/addons/auto-gen/terraform-provider-aws.yaml new file mode 100644 index 000000000..1eaf203a9 --- /dev/null +++ b/vela-templates/addons/auto-gen/terraform-provider-aws.yaml @@ -0,0 +1,49 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + annotations: + addons.oam.dev/description: Kubernetes Terraform Controller for AWS + addons.oam.dev/name: terraform/provider-aws + name: terraform-provider-aws + namespace: default +spec: + components: + - name: aws-account-creds + properties: + apiVersion: v1 + kind: Secret + metadata: + name: aws-account-creds + namespace: vela-system + stringData: + credentials: | + awsAccessKeyID: [[ index .Args "AWS_ACCESS_KEY_ID" ]] + awsSecretAccessKey: [[ index .Args "AWS_SECRET_ACCESS_KEY" ]] + awsSessionToken: [[ index .Args "AWS_SESSION_TOKEN" ]] + type: Opaque + type: raw + - name: aws + properties: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Provider + metadata: + name: aws + namespace: default + spec: + credentials: + secretRef: + key: credentials + name: aws-account-creds + namespace: vela-system + source: Secret + provider: aws + region: '[[ index .Args "AWS_DEFAULT_REGION" ]]' + type: raw +status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 diff --git a/vela-templates/addons/auto-gen/terraform.yaml b/vela-templates/addons/auto-gen/terraform.yaml index 81c37e153..b3f724a10 100644 --- a/vela-templates/addons/auto-gen/terraform.yaml +++ b/vela-templates/addons/auto-gen/terraform.yaml @@ -20,7 +20,7 @@ spec: chart: terraform-controller repoType: helm url: https://charts.kubevela.net/addons - version: 0.1.19 + version: 0.2.6 type: helm - name: alibaba-ack properties: @@ -37,199 +37,9 @@ spec: spec: schematic: terraform: - configuration: | - module "kubernetes" { - source = "github.com/zzxwill/terraform-alicloud-kubernetes" - new_nat_gateway = true - vpc_name = var.vpc_name - vpc_cidr = var.vpc_cidr - vswitch_name_prefix = var.vswitch_name_prefix - vswitch_cidrs = var.vswitch_cidrs - master_instance_types = var.master_instance_types - worker_instance_types = var.worker_instance_types - k8s_pod_cidr = var.k8s_pod_cidr - k8s_service_cidr = var.k8s_service_cidr - k8s_worker_number = var.k8s_worker_number - cpu_core_count = var.cpu_core_count - memory_size = var.memory_size - zone_id = var.zone_id - k8s_version = var.k8s_version - k8s_name_prefix = var.k8s_name_prefix - } - ###################### - # Instance types variables - ###################### - variable "cpu_core_count" { - description = "CPU core count is used to fetch instance types." - type = number - default = 4 - } - variable "memory_size" { - description = "Memory size used to fetch instance types." - type = number - default = 8 - } - ###################### - # VPC variables - ###################### - variable "vpc_name" { - description = "The vpc name used to create a new vpc when 'vpc_id' is not specified. Default to variable `example_name`" - type = string - default = "tf-k8s-vpc" - } - variable "vpc_cidr" { - description = "The cidr block used to launch a new vpc when 'vpc_id' is not specified." - type = string - default = "10.0.0.0/8" - } - ###################### - # VSwitch variables - ###################### - variable "vswitch_name_prefix" { - type = string - description = "The vswitch name prefix used to create several new vswitches. Default to variable 'example_name'." - default = "tf-k8s-vsw" - } - variable "number_format" { - description = "The number format used to output." - type = string - default = "%02d" - } - variable "vswitch_ids" { - description = "List of existing vswitch id." - type = list - default = [] - } - variable "vswitch_cidrs" { - description = "List of cidr blocks used to create several new vswitches when 'vswitch_ids' is not specified." - type = list - default = [ - "10.1.0.0/16", - "10.2.0.0/16", - "10.3.0.0/16"] - } - variable "k8s_name_prefix" { - description = "The name prefix used to create several kubernetes clusters. Default to variable `example_name`" - type = string - default = "poc" - } - variable "new_nat_gateway" { - type = bool - description = "Whether to create a new nat gateway. In this template, a new nat gateway will create a nat gateway, eip and server snat entries." - default = true - } - variable "master_instance_types" { - description = "The ecs instance types used to launch master nodes." - type = list - default = [ - # hongkong - "ecs.sn1ne.xlarge", - # hongkong - "ecs.c6.xlarge", - # hongkong - "ecs.c4.xlarge", - # hongkong - "ecs.c5.xlarge", - "ecs.n4.xlarge", - # "ecs.n1.large", - # "ecs.sn1.large", - # "ecs.s6-c1m2.xlarge", - # "ecs.c6e.xlarge" - ] - } - variable "worker_instance_types" { - description = "The ecs instance types used to launch worker nodes." - type = list - default = [ - # hongkong - "ecs.sn1ne.xlarge", - # hongkong - "ecs.c6.xlarge", - # hongkong - "ecs.c4.xlarge", - # hongkong - "ecs.c6e.xlarge", - "ecs.n4.xlarge", - // "ecs.n1.large", - // "ecs.sn1.large", - // "ecs.s6-c1m2.xlarge" - ] - } - variable "node_cidr_mask" { - type = number - description = "The node cidr block to specific how many pods can run on single node. Valid values: [24-28]." - default = 24 - } - variable "enable_ssh" { - description = "Enable login to the node through SSH." - type = bool - default = true - } - variable "install_cloud_monitor" { - description = "Install cloud monitor agent on ECS." - type = bool - default = true - } - variable "cpu_policy" { - type = string - description = "kubelet cpu policy. Valid values: 'none','static'. Default to 'none'." - default = "none" - } - variable "proxy_mode" { - description = "Proxy mode is option of kube-proxy. Valid values: 'ipvs','iptables'. Default to 'iptables'." - type = string - default = "iptables" - } - variable "password" { - description = "The password of ECS instance." - type = string - default = "Just4Test" - } - variable "k8s_worker_number" { - description = "The number of worker nodes in kubernetes cluster." - type = number - default = 2 - } - # k8s_pod_cidr is only for flannel network - variable "k8s_pod_cidr" { - description = "The kubernetes pod cidr block. It cannot be equals to vpc's or vswitch's and cannot be in them." - type = string - default = "172.20.0.0/16" - } - variable "k8s_service_cidr" { - description = "The kubernetes service cidr block. It cannot be equals to vpc's or vswitch's or pod's and cannot be in them." - type = string - default = "192.168.0.0/16" - } - variable "k8s_version" { - description = "The version of the kubernetes version. Valid values: '1.16.6-aliyun.1','1.14.8-aliyun.1'. Default to '1.16.6-aliyun.1'." - type = string - default = "1.20.4-aliyun.1" - } - variable "zone_id" { - description = "Availability Zone ID" - type = string - default = "cn-hongkong-b" - # "cn-beijing-a" - } - output "name" { - value = module.kubernetes.name - } - output "kubeconfig" { - value = module.kubernetes.kubeconfig - } - output "cluster_ca_cert" { - value = module.kubernetes.cluster_ca_cert - } - output "client_cert" { - value = module.kubernetes.client_cert - } - output "client_key" { - value = module.kubernetes.client_key - } - output "api_server_internet" { - value = module.kubernetes.api_server_internet - } + configuration: https://github.com/kubevela-contrib/terraform-modules.git + path: alibaba/cs/dedicated-kubernetes + type: remote workload: definition: apiVersion: terraform.core.oam.dev/v1beta1 @@ -301,7 +111,7 @@ spec: terraform: configuration: | module "rds" { - source = "terraform-alicloud-modules/rds/alicloud" + source = "github.com/kubevela-contrib/terraform-alicloud-rds" engine = "MySQL" engine_version = "8.0" instance_type = "rds.mysql.c1.large" @@ -309,6 +119,8 @@ spec: instance_name = var.instance_name account_name = var.account_name password = var.password + allocate_public_connection = var.allocate_public_connection + security_ips = ["0.0.0.0/0",] } output "DB_NAME" { @@ -326,6 +138,9 @@ spec: output "DB_PASSWORD" { value = var.password } + output "DB_PUBLIC_HOST" { + value = module.rds.db_public_connection_string + } variable "instance_name" { description = "RDS instance name" @@ -344,6 +159,52 @@ spec: type = string default = "Xyfff83jfewGGfaked" } + + variable "allocate_public_connection" { + description = "Whether to allocate public connection for a RDS instance." + type = bool + default = true + } + workload: + definition: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Configuration + type: raw + - name: aws-s3 + properties: + apiVersion: core.oam.dev/v1alpha2 + kind: ComponentDefinition + metadata: + annotations: + definition.oam.dev/description: Terraform configuration for AWS S3 + 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 diff --git a/vela-templates/addons/terraform-provider-alibaba/template.yaml b/vela-templates/addons/terraform-provider-alibaba/template.yaml index ef0636fda..a77f6075f 100644 --- a/vela-templates/addons/terraform-provider-alibaba/template.yaml +++ b/vela-templates/addons/terraform-provider-alibaba/template.yaml @@ -13,7 +13,7 @@ spec: apiVersion: v1 kind: Secret metadata: - name: alibaba-provider-secret + name: alibaba-account-creds namespace: vela-system type: Opaque stringData: diff --git a/vela-templates/addons/terraform-provider-aws/template.yaml b/vela-templates/addons/terraform-provider-aws/template.yaml new file mode 100644 index 000000000..c997ac499 --- /dev/null +++ b/vela-templates/addons/terraform-provider-aws/template.yaml @@ -0,0 +1,51 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + annotations: + addons.oam.dev/description: Kubernetes Terraform Controller for AWS + addons.oam.dev/name: terraform/provider-aws + name: terraform-provider-aws + namespace: default +spec: + components: + - name: aws-account-creds + properties: + apiVersion: v1 + kind: Secret + metadata: + name: aws-account-creds + namespace: vela-system + type: Opaque + stringData: + credentials: | + awsAccessKeyID: [[ index .Args "AWS_ACCESS_KEY_ID" ]] + awsSecretAccessKey: [[ index .Args "AWS_SECRET_ACCESS_KEY" ]] + awsSessionToken: [[ index .Args "AWS_SESSION_TOKEN" ]] + type: raw + - name: aws + type: raw + properties: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Provider + metadata: + name: aws + namespace: default + spec: + provider: aws + region: '[[ index .Args "AWS_DEFAULT_REGION" ]]' + credentials: + source: Secret + secretRef: + namespace: vela-system + name: aws-account-creds + key: credentials +{{ range .ResourceFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 8 }} {{ end }} +{{ range .DefinitionFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 8 }} {{ end }} diff --git a/vela-templates/addons/terraform/definitions/terraform-alibaba-ack.yaml b/vela-templates/addons/terraform/definitions/terraform-alibaba-ack.yaml index a0ffa90d0..7458a93ca 100644 --- a/vela-templates/addons/terraform/definitions/terraform-alibaba-ack.yaml +++ b/vela-templates/addons/terraform/definitions/terraform-alibaba-ack.yaml @@ -14,196 +14,6 @@ spec: kind: Configuration schematic: terraform: - configuration: | - module "kubernetes" { - source = "github.com/zzxwill/terraform-alicloud-kubernetes" - new_nat_gateway = true - vpc_name = var.vpc_name - vpc_cidr = var.vpc_cidr - vswitch_name_prefix = var.vswitch_name_prefix - vswitch_cidrs = var.vswitch_cidrs - master_instance_types = var.master_instance_types - worker_instance_types = var.worker_instance_types - k8s_pod_cidr = var.k8s_pod_cidr - k8s_service_cidr = var.k8s_service_cidr - k8s_worker_number = var.k8s_worker_number - cpu_core_count = var.cpu_core_count - memory_size = var.memory_size - zone_id = var.zone_id - k8s_version = var.k8s_version - k8s_name_prefix = var.k8s_name_prefix - } - ###################### - # Instance types variables - ###################### - variable "cpu_core_count" { - description = "CPU core count is used to fetch instance types." - type = number - default = 4 - } - variable "memory_size" { - description = "Memory size used to fetch instance types." - type = number - default = 8 - } - ###################### - # VPC variables - ###################### - variable "vpc_name" { - description = "The vpc name used to create a new vpc when 'vpc_id' is not specified. Default to variable `example_name`" - type = string - default = "tf-k8s-vpc" - } - variable "vpc_cidr" { - description = "The cidr block used to launch a new vpc when 'vpc_id' is not specified." - type = string - default = "10.0.0.0/8" - } - ###################### - # VSwitch variables - ###################### - variable "vswitch_name_prefix" { - type = string - description = "The vswitch name prefix used to create several new vswitches. Default to variable 'example_name'." - default = "tf-k8s-vsw" - } - variable "number_format" { - description = "The number format used to output." - type = string - default = "%02d" - } - variable "vswitch_ids" { - description = "List of existing vswitch id." - type = list - default = [] - } - variable "vswitch_cidrs" { - description = "List of cidr blocks used to create several new vswitches when 'vswitch_ids' is not specified." - type = list - default = [ - "10.1.0.0/16", - "10.2.0.0/16", - "10.3.0.0/16"] - } - variable "k8s_name_prefix" { - description = "The name prefix used to create several kubernetes clusters. Default to variable `example_name`" - type = string - default = "poc" - } - variable "new_nat_gateway" { - type = bool - description = "Whether to create a new nat gateway. In this template, a new nat gateway will create a nat gateway, eip and server snat entries." - default = true - } - variable "master_instance_types" { - description = "The ecs instance types used to launch master nodes." - type = list - default = [ - # hongkong - "ecs.sn1ne.xlarge", - # hongkong - "ecs.c6.xlarge", - # hongkong - "ecs.c4.xlarge", - # hongkong - "ecs.c5.xlarge", - "ecs.n4.xlarge", - # "ecs.n1.large", - # "ecs.sn1.large", - # "ecs.s6-c1m2.xlarge", - # "ecs.c6e.xlarge" - ] - } - variable "worker_instance_types" { - description = "The ecs instance types used to launch worker nodes." - type = list - default = [ - # hongkong - "ecs.sn1ne.xlarge", - # hongkong - "ecs.c6.xlarge", - # hongkong - "ecs.c4.xlarge", - # hongkong - "ecs.c6e.xlarge", - "ecs.n4.xlarge", - // "ecs.n1.large", - // "ecs.sn1.large", - // "ecs.s6-c1m2.xlarge" - ] - } - variable "node_cidr_mask" { - type = number - description = "The node cidr block to specific how many pods can run on single node. Valid values: [24-28]." - default = 24 - } - variable "enable_ssh" { - description = "Enable login to the node through SSH." - type = bool - default = true - } - variable "install_cloud_monitor" { - description = "Install cloud monitor agent on ECS." - type = bool - default = true - } - variable "cpu_policy" { - type = string - description = "kubelet cpu policy. Valid values: 'none','static'. Default to 'none'." - default = "none" - } - variable "proxy_mode" { - description = "Proxy mode is option of kube-proxy. Valid values: 'ipvs','iptables'. Default to 'iptables'." - type = string - default = "iptables" - } - variable "password" { - description = "The password of ECS instance." - type = string - default = "Just4Test" - } - variable "k8s_worker_number" { - description = "The number of worker nodes in kubernetes cluster." - type = number - default = 2 - } - # k8s_pod_cidr is only for flannel network - variable "k8s_pod_cidr" { - description = "The kubernetes pod cidr block. It cannot be equals to vpc's or vswitch's and cannot be in them." - type = string - default = "172.20.0.0/16" - } - variable "k8s_service_cidr" { - description = "The kubernetes service cidr block. It cannot be equals to vpc's or vswitch's or pod's and cannot be in them." - type = string - default = "192.168.0.0/16" - } - variable "k8s_version" { - description = "The version of the kubernetes version. Valid values: '1.16.6-aliyun.1','1.14.8-aliyun.1'. Default to '1.16.6-aliyun.1'." - type = string - default = "1.20.4-aliyun.1" - } - variable "zone_id" { - description = "Availability Zone ID" - type = string - default = "cn-hongkong-b" - # "cn-beijing-a" - } - output "name" { - value = module.kubernetes.name - } - output "kubeconfig" { - value = module.kubernetes.kubeconfig - } - output "cluster_ca_cert" { - value = module.kubernetes.cluster_ca_cert - } - output "client_cert" { - value = module.kubernetes.client_cert - } - output "client_key" { - value = module.kubernetes.client_key - } - output "api_server_internet" { - value = module.kubernetes.api_server_internet - } + configuration: https://github.com/kubevela-contrib/terraform-modules.git + type: remote + path: alibaba/cs/dedicated-kubernetes diff --git a/vela-templates/addons/terraform/definitions/terraform-alibaba-rds.yaml b/vela-templates/addons/terraform/definitions/terraform-alibaba-rds.yaml index deb8393b8..cfa273519 100644 --- a/vela-templates/addons/terraform/definitions/terraform-alibaba-rds.yaml +++ b/vela-templates/addons/terraform/definitions/terraform-alibaba-rds.yaml @@ -16,7 +16,7 @@ spec: terraform: configuration: | module "rds" { - source = "terraform-alicloud-modules/rds/alicloud" + source = "github.com/kubevela-contrib/terraform-alicloud-rds" engine = "MySQL" engine_version = "8.0" instance_type = "rds.mysql.c1.large" @@ -24,6 +24,8 @@ spec: instance_name = var.instance_name account_name = var.account_name password = var.password + allocate_public_connection = var.allocate_public_connection + security_ips = ["0.0.0.0/0",] } output "DB_NAME" { @@ -41,6 +43,9 @@ spec: output "DB_PASSWORD" { value = var.password } + output "DB_PUBLIC_HOST" { + value = module.rds.db_public_connection_string + } variable "instance_name" { description = "RDS instance name" @@ -59,3 +64,9 @@ spec: type = string default = "Xyfff83jfewGGfaked" } + + variable "allocate_public_connection" { + description = "Whether to allocate public connection for a RDS instance." + type = bool + default = true + } diff --git a/vela-templates/addons/terraform/definitions/terraform-aws-s3.yaml b/vela-templates/addons/terraform/definitions/terraform-aws-s3.yaml new file mode 100644 index 000000000..7e63c6548 --- /dev/null +++ b/vela-templates/addons/terraform/definitions/terraform-aws-s3.yaml @@ -0,0 +1,37 @@ +apiVersion: core.oam.dev/v1alpha2 +kind: ComponentDefinition +metadata: + name: aws-s3 + namespace: vela-system + annotations: + definition.oam.dev/description: Terraform configuration for AWS S3 + labels: + type: terraform +spec: + workload: + definition: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Configuration + 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 + } diff --git a/vela-templates/addons/terraform/template.yaml b/vela-templates/addons/terraform/template.yaml index 3bc2ed9fb..3cf3c338f 100644 --- a/vela-templates/addons/terraform/template.yaml +++ b/vela-templates/addons/terraform/template.yaml @@ -33,7 +33,7 @@ spec: repoType: helm url: https://charts.kubevela.net/addons chart: terraform-controller - version: 0.1.19 + version: 0.2.6 {{ range .ResourceFiles }} - name: {{ .Name }} type: raw