diff --git a/apis/core.oam.dev/common/types.go b/apis/core.oam.dev/common/types.go index 12943a525..a7fa1321a 100644 --- a/apis/core.oam.dev/common/types.go +++ b/apis/core.oam.dev/common/types.go @@ -20,6 +20,8 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" + types "github.com/oam-dev/terraform-controller/api/types/crossplane-runtime" + "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/standard.oam.dev/v1alpha1" @@ -109,6 +111,9 @@ type Terraform struct { // +kubebuilder:default:=hcl // +kubebuilder:validation:Enum:=hcl;json;remote Type string `json:"type,omitempty"` + + // ProviderReference specifies the reference to Provider + ProviderReference *types.Reference `json:"providerRef,omitempty"` } // A WorkloadTypeDescriptor refer to a Workload Type diff --git a/apis/core.oam.dev/common/zz_generated.deepcopy.go b/apis/core.oam.dev/common/zz_generated.deepcopy.go index c83bfe988..dcbf9e834 100644 --- a/apis/core.oam.dev/common/zz_generated.deepcopy.go +++ b/apis/core.oam.dev/common/zz_generated.deepcopy.go @@ -21,6 +21,7 @@ limitations under the License. package common import ( + crossplane_runtime "github.com/oam-dev/terraform-controller/api/types/crossplane-runtime" v1 "k8s.io/api/core/v1" ) @@ -439,7 +440,7 @@ func (in *Schematic) DeepCopyInto(out *Schematic) { if in.Terraform != nil { in, out := &in.Terraform, &out.Terraform *out = new(Terraform) - **out = **in + (*in).DeepCopyInto(*out) } } @@ -529,6 +530,11 @@ func (in *SubStepsStatus) DeepCopy() *SubStepsStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Terraform) DeepCopyInto(out *Terraform) { *out = *in + if in.ProviderReference != nil { + in, out := &in.ProviderReference, &out.ProviderReference + *out = new(crossplane_runtime.Reference) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Terraform. diff --git a/charts/oam-runtime/crds/core.oam.dev_traitdefinitions.yaml b/charts/oam-runtime/crds/core.oam.dev_traitdefinitions.yaml index bc30ce8e4..6d694258f 100644 --- a/charts/oam-runtime/crds/core.oam.dev_traitdefinitions.yaml +++ b/charts/oam-runtime/crds/core.oam.dev_traitdefinitions.yaml @@ -188,6 +188,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -454,6 +468,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/oam-runtime/crds/core.oam.dev_workloaddefinitions.yaml b/charts/oam-runtime/crds/core.oam.dev_workloaddefinitions.yaml index 26487a53f..80d37924e 100644 --- a/charts/oam-runtime/crds/core.oam.dev_workloaddefinitions.yaml +++ b/charts/oam-runtime/crds/core.oam.dev_workloaddefinitions.yaml @@ -193,6 +193,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -440,6 +454,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml b/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml index 9a1193c0f..306b2ace4 100644 --- a/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml +++ b/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml @@ -1232,6 +1232,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -1621,6 +1635,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -1908,6 +1936,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -3318,6 +3360,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -3600,6 +3656,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -3971,6 +4041,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -4221,6 +4305,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -4487,6 +4585,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml b/charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml index d10e8e6ae..10530b945 100644 --- a/charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml @@ -179,6 +179,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -449,6 +463,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-core/crds/core.oam.dev_definitionrevisions.yaml b/charts/vela-core/crds/core.oam.dev_definitionrevisions.yaml index 150b5df80..4e81135c2 100644 --- a/charts/vela-core/crds/core.oam.dev_definitionrevisions.yaml +++ b/charts/vela-core/crds/core.oam.dev_definitionrevisions.yaml @@ -222,6 +222,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -492,6 +506,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -755,6 +783,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -999,6 +1041,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-core/crds/core.oam.dev_policydefinitions.yaml b/charts/vela-core/crds/core.oam.dev_policydefinitions.yaml index b37983de0..07169c704 100644 --- a/charts/vela-core/crds/core.oam.dev_policydefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_policydefinitions.yaml @@ -151,6 +151,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml b/charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml index bc30ce8e4..6d694258f 100644 --- a/charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml @@ -188,6 +188,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -454,6 +468,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-core/crds/core.oam.dev_workflowstepdefinitions.yaml b/charts/vela-core/crds/core.oam.dev_workflowstepdefinitions.yaml index 9b9464f22..025dee2f1 100644 --- a/charts/vela-core/crds/core.oam.dev_workflowstepdefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_workflowstepdefinitions.yaml @@ -148,6 +148,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml b/charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml index 26487a53f..80d37924e 100644 --- a/charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml +++ b/charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml @@ -193,6 +193,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -440,6 +454,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-core/templates/addons/terraform-provider-azure.yaml b/charts/vela-core/templates/addons/terraform-provider-azure.yaml new file mode 100644 index 000000000..1a9ddc806 --- /dev/null +++ b/charts/vela-core/templates/addons/terraform-provider-azure.yaml @@ -0,0 +1,65 @@ +apiVersion: v1 +data: + initializer: | + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + metadata: + annotations: + addons.oam.dev/description: Kubernetes Terraform Controller for Azure + addons.oam.dev/name: terraform/provider-azure + name: terraform-provider-azure + namespace: default + spec: + appTemplate: + spec: + components: + - name: azure-account-creds + properties: + apiVersion: v1 + kind: Secret + metadata: + name: azure-account-creds + namespace: vela-system + stringData: + credentials: | + armClientID: [[ index .Args "ARM_CLIENT_ID" ]] + armClientSecret: [[ index .Args "ARM_CLIENT_SECRET" ]] + armSubscriptionID: [[ index .Args "ARM_SUBSCRIPTION_ID" ]] + armTenantID: [[ index .Args "ARM_TENANT_ID" ]] + type: Opaque + type: raw + - name: azure + properties: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Provider + metadata: + name: azure + namespace: default + spec: + credentials: + secretRef: + key: credentials + name: azure-account-creds + namespace: vela-system + source: Secret + provider: azure + type: raw + status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 + status: + observedGeneration: 0 +kind: ConfigMap +metadata: + annotations: + addons.oam.dev/description: Kubernetes Terraform Controller for Azure + addons.oam.dev/name: terraform/provider-azure + labels: + addons.oam.dev/type: terraform-provider-azure + name: terraform-provider-azure + namespace: {{.Values.systemDefinitionNamespace}} diff --git a/charts/vela-core/templates/addons/terraform.yaml b/charts/vela-core/templates/addons/terraform.yaml index 1d1071006..9f22d12a3 100644 --- a/charts/vela-core/templates/addons/terraform.yaml +++ b/charts/vela-core/templates/addons/terraform.yaml @@ -354,6 +354,83 @@ data: apiVersion: terraform.core.oam.dev/v1beta1 kind: Configuration type: raw + - name: azure-database-mariadb + properties: + apiVersion: core.oam.dev/v1alpha2 + kind: ComponentDefinition + metadata: + annotations: + definition.oam.dev/description: Terraform configuration for Azure Database + Mariadb + provider: azure + labels: + type: terraform + name: azure-database-mariadb + namespace: vela-system + spec: + schematic: + terraform: + configuration: | + # Configure the Microsoft Azure Provider + provider "azurerm" { + features {} + } + + resource "azurerm_resource_group" "example" { + name = "tfex-mariadb-database-RG" + location = "West Europe" + } + + resource "azurerm_mariadb_server" "example" { + name = "mariadb-svr-sample" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + + sku_name = "B_Gen5_2" + + storage_mb = 51200 + backup_retention_days = 7 + geo_redundant_backup_enabled = false + + administrator_login = var.username + administrator_login_password = var.password + version = "10.2" + ssl_enforcement_enabled = true + } + + resource "azurerm_mariadb_database" "example" { + name = var.name + resource_group_name = azurerm_resource_group.example.name + server_name = azurerm_mariadb_server.example.name + charset = "utf8" + collation = "utf8_general_ci" + } + + variable "name" { + default = "mariadb_database" + type = string + description = "Database instance name" + } + + variable "username" { + default = "acctestun" + type = string + description = "Database instance username" + } + + variable "password" { + default = "H@Sh1CoR3!faked" + type = string + description = "Database instance password" + } + providerRef: + name: azure + namespace: default + workload: + definition: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Configuration + type: raw status: rollout: batchRollingState: "" diff --git a/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml b/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml index 9a1193c0f..306b2ace4 100644 --- a/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml @@ -1232,6 +1232,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -1621,6 +1635,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -1908,6 +1936,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -3318,6 +3360,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -3600,6 +3656,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -3971,6 +4041,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -4221,6 +4305,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -4487,6 +4585,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-minimal/crds/core.oam.dev_definitionrevisions.yaml b/charts/vela-minimal/crds/core.oam.dev_definitionrevisions.yaml index 150b5df80..4e81135c2 100644 --- a/charts/vela-minimal/crds/core.oam.dev_definitionrevisions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_definitionrevisions.yaml @@ -222,6 +222,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -492,6 +506,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -755,6 +783,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -999,6 +1041,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-minimal/crds/core.oam.dev_policydefinitions.yaml b/charts/vela-minimal/crds/core.oam.dev_policydefinitions.yaml index b37983de0..07169c704 100644 --- a/charts/vela-minimal/crds/core.oam.dev_policydefinitions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_policydefinitions.yaml @@ -151,6 +151,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-minimal/crds/core.oam.dev_traitdefinitions.yaml b/charts/vela-minimal/crds/core.oam.dev_traitdefinitions.yaml index bc30ce8e4..6d694258f 100644 --- a/charts/vela-minimal/crds/core.oam.dev_traitdefinitions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_traitdefinitions.yaml @@ -188,6 +188,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -454,6 +468,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-minimal/crds/core.oam.dev_workflowstepdefinitions.yaml b/charts/vela-minimal/crds/core.oam.dev_workflowstepdefinitions.yaml index 9b9464f22..025dee2f1 100644 --- a/charts/vela-minimal/crds/core.oam.dev_workflowstepdefinitions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_workflowstepdefinitions.yaml @@ -148,6 +148,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/charts/vela-minimal/crds/core.oam.dev_workloaddefinitions.yaml b/charts/vela-minimal/crds/core.oam.dev_workloaddefinitions.yaml index 26487a53f..80d37924e 100644 --- a/charts/vela-minimal/crds/core.oam.dev_workloaddefinitions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_workloaddefinitions.yaml @@ -193,6 +193,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -440,6 +454,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/go.mod b/go.mod index 8f7ca34ed..613d24921 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.0 + github.com/oam-dev/terraform-controller v0.2.1 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 4bf5acbb3..7c29e0ffe 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.0 h1:GBQ+CvXtY9bcRkwGaPYHbYFkbVWzDExc05hz0NL0rqs= -github.com/oam-dev/terraform-controller v0.2.0/go.mod h1:wd4rnqnJzz274Sg1/qoeIhBx1rvTZ/ECzXoMff0ucR0= +github.com/oam-dev/terraform-controller v0.2.1 h1:gGXcUDBMWKfWet84STm99RX6gXo89pyTRsgQSLq2mog= +github.com/oam-dev/terraform-controller v0.2.1/go.mod h1:5Vy6jLx9fjotEd6E005Ve1f0x3fEpVlG/DVjmqLjAq0= 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 fd2b5be20..5813fd711 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,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -1621,6 +1635,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -1908,6 +1936,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -3318,6 +3360,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -3600,6 +3656,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -3971,6 +4041,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -4221,6 +4305,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -4487,6 +4585,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration 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 38b02444c..a29c120d1 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,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -449,6 +463,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration 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 e1e0d870c..a58389fd2 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,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -492,6 +506,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -755,6 +783,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -999,6 +1041,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference + to Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration 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 84c93c8c3..8f71e4c52 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,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration 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 2e6ae3bf9..5cce855a2 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,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -454,6 +468,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration 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 7313a1301..91c8228f7 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,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration 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 3e1a61b67..419a9e8f0 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,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration @@ -440,6 +454,20 @@ spec: configuration: description: Configuration is Terraform Configuration type: string + providerRef: + description: ProviderReference specifies the reference to + Provider + properties: + name: + description: Name of the referenced object. + type: string + namespace: + default: default + description: Namespace of the secret. + type: string + required: + - name + type: object type: default: hcl description: Type specifies which Terraform configuration diff --git a/pkg/appfile/appfile.go b/pkg/appfile/appfile.go index c05b61ab3..8ec7aacbd 100644 --- a/pkg/appfile/appfile.go +++ b/pkg/appfile/appfile.go @@ -649,7 +649,7 @@ func generateComponentFromKubeModule(wl *Workload, appName, revision, ns string) } func generateTerraformConfigurationWorkload(wl *Workload, ns string) (*unstructured.Unstructured, error) { - if wl.FullTemplate.Terraform.Configuration == "" { + if wl.FullTemplate == nil || wl.FullTemplate.Terraform == nil || wl.FullTemplate.Terraform.Configuration == "" { return nil, errors.New(errTerraformConfigurationIsNotSet) } params, err := json.Marshal(wl.Params) @@ -671,6 +671,10 @@ func generateTerraformConfigurationWorkload(wl *Workload, ns string) (*unstructu configuration.Spec.Remote = wl.FullTemplate.Terraform.Configuration } + if wl.FullTemplate.Terraform.ProviderReference != nil { + configuration.Spec.ProviderReference = wl.FullTemplate.Terraform.ProviderReference + } + // 1. parse writeConnectionSecretToRef if err := json.Unmarshal(params, &configuration.Spec); err != nil { return nil, errors.Wrap(err, errFailToConvertTerraformComponentProperties) diff --git a/pkg/appfile/appfile_test.go b/pkg/appfile/appfile_test.go index 457faa375..ade79bb76 100644 --- a/pkg/appfile/appfile_test.go +++ b/pkg/appfile/appfile_test.go @@ -909,6 +909,7 @@ func TestGenerateTerraformConfigurationWorkload(t *testing.T) { hcl string remote string params map[string]interface{} + providerRef *terraformtypes.Reference } type want struct { @@ -967,7 +968,18 @@ func TestGenerateTerraformConfigurationWorkload(t *testing.T) { params: badParam, hcl: "abc", }, - want: want{err: errors.Wrap(badParamMarshalError, errFailToConvertTerraformComponentProperties)}}, + want: want{err: errors.Wrap(badParamMarshalError, errFailToConvertTerraformComponentProperties)}, + }, + + "terraform workload has a provider reference": { + + args: args{ + params: badParam, + hcl: "abc", + providerRef: &terraformtypes.Reference{Name: "azure", Namespace: "default"}, + }, + want: want{err: errors.Wrap(badParamMarshalError, errFailToConvertTerraformComponentProperties)}, + }, } for tcName, tc := range testcases { @@ -1027,6 +1039,9 @@ func TestGenerateTerraformConfigurationWorkload(t *testing.T) { WriteConnectionSecretToReference: tc.args.writeConnectionSecretToRef, } } + if tc.args.providerRef != nil { + template.Terraform.ProviderReference = tc.args.providerRef + } wl := &Workload{ FullTemplate: template, diff --git a/vela-templates/addons/auto-gen/terraform-provider-azure.yaml b/vela-templates/addons/auto-gen/terraform-provider-azure.yaml new file mode 100644 index 000000000..d62ec670f --- /dev/null +++ b/vela-templates/addons/auto-gen/terraform-provider-azure.yaml @@ -0,0 +1,53 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Initializer +metadata: + annotations: + addons.oam.dev/description: Kubernetes Terraform Controller for Azure + addons.oam.dev/name: terraform/provider-azure + name: terraform-provider-azure + namespace: default +spec: + appTemplate: + spec: + components: + - name: azure-account-creds + properties: + apiVersion: v1 + kind: Secret + metadata: + name: azure-account-creds + namespace: vela-system + stringData: + credentials: | + armClientID: [[ index .Args "ARM_CLIENT_ID" ]] + armClientSecret: [[ index .Args "ARM_CLIENT_SECRET" ]] + armSubscriptionID: [[ index .Args "ARM_SUBSCRIPTION_ID" ]] + armTenantID: [[ index .Args "ARM_TENANT_ID" ]] + type: Opaque + type: raw + - name: azure + properties: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Provider + metadata: + name: azure + namespace: default + spec: + credentials: + secretRef: + key: credentials + name: azure-account-creds + namespace: vela-system + source: Secret + provider: azure + type: raw + status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 +status: + observedGeneration: 0 diff --git a/vela-templates/addons/auto-gen/terraform.yaml b/vela-templates/addons/auto-gen/terraform.yaml index 633d2a6fc..1a60a4c55 100644 --- a/vela-templates/addons/auto-gen/terraform.yaml +++ b/vela-templates/addons/auto-gen/terraform.yaml @@ -351,6 +351,83 @@ spec: apiVersion: terraform.core.oam.dev/v1beta1 kind: Configuration type: raw + - name: azure-database-mariadb + properties: + apiVersion: core.oam.dev/v1alpha2 + kind: ComponentDefinition + metadata: + annotations: + definition.oam.dev/description: Terraform configuration for Azure Database + Mariadb + provider: azure + labels: + type: terraform + name: azure-database-mariadb + namespace: vela-system + spec: + schematic: + terraform: + configuration: | + # Configure the Microsoft Azure Provider + provider "azurerm" { + features {} + } + + resource "azurerm_resource_group" "example" { + name = "tfex-mariadb-database-RG" + location = "West Europe" + } + + resource "azurerm_mariadb_server" "example" { + name = "mariadb-svr-sample" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + + sku_name = "B_Gen5_2" + + storage_mb = 51200 + backup_retention_days = 7 + geo_redundant_backup_enabled = false + + administrator_login = var.username + administrator_login_password = var.password + version = "10.2" + ssl_enforcement_enabled = true + } + + resource "azurerm_mariadb_database" "example" { + name = var.name + resource_group_name = azurerm_resource_group.example.name + server_name = azurerm_mariadb_server.example.name + charset = "utf8" + collation = "utf8_general_ci" + } + + variable "name" { + default = "mariadb_database" + type = string + description = "Database instance name" + } + + variable "username" { + default = "acctestun" + type = string + description = "Database instance username" + } + + variable "password" { + default = "H@Sh1CoR3!faked" + type = string + description = "Database instance password" + } + providerRef: + name: azure + namespace: default + workload: + definition: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Configuration + type: raw status: rollout: batchRollingState: "" diff --git a/vela-templates/addons/terraform-provider-azure/template.yaml b/vela-templates/addons/terraform-provider-azure/template.yaml new file mode 100644 index 000000000..21f0f67a6 --- /dev/null +++ b/vela-templates/addons/terraform-provider-azure/template.yaml @@ -0,0 +1,53 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Initializer +metadata: + annotations: + addons.oam.dev/description: Kubernetes Terraform Controller for Azure + addons.oam.dev/name: terraform/provider-azure + name: terraform-provider-azure + namespace: default +spec: + appTemplate: + spec: + components: + - name: azure-account-creds + properties: + apiVersion: v1 + kind: Secret + metadata: + name: azure-account-creds + namespace: vela-system + type: Opaque + stringData: + credentials: | + armClientID: [[ index .Args "ARM_CLIENT_ID" ]] + armClientSecret: [[ index .Args "ARM_CLIENT_SECRET" ]] + armSubscriptionID: [[ index .Args "ARM_SUBSCRIPTION_ID" ]] + armTenantID: [[ index .Args "ARM_TENANT_ID" ]] + type: raw + - name: azure + type: raw + properties: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Provider + metadata: + name: azure + namespace: default + spec: + provider: azure + credentials: + source: Secret + secretRef: + namespace: vela-system + name: azure-account-creds + key: credentials +{{ range .ResourceFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 12 }} {{ end }} +{{ range .DefinitionFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 12 }} {{ end }} diff --git a/vela-templates/addons/terraform/definitions/terraform-azure-database-mariadb.yaml b/vela-templates/addons/terraform/definitions/terraform-azure-database-mariadb.yaml new file mode 100644 index 000000000..24daaa7ed --- /dev/null +++ b/vela-templates/addons/terraform/definitions/terraform-azure-database-mariadb.yaml @@ -0,0 +1,73 @@ +apiVersion: core.oam.dev/v1alpha2 +kind: ComponentDefinition +metadata: + name: azure-database-mariadb + namespace: vela-system + annotations: + provider: azure + definition.oam.dev/description: Terraform configuration for Azure Database Mariadb + labels: + type: terraform +spec: + workload: + definition: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Configuration + schematic: + terraform: + configuration: | + # Configure the Microsoft Azure Provider + provider "azurerm" { + features {} + } + + resource "azurerm_resource_group" "example" { + name = "tfex-mariadb-database-RG" + location = "West Europe" + } + + resource "azurerm_mariadb_server" "example" { + name = "mariadb-svr-sample" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + + sku_name = "B_Gen5_2" + + storage_mb = 51200 + backup_retention_days = 7 + geo_redundant_backup_enabled = false + + administrator_login = var.username + administrator_login_password = var.password + version = "10.2" + ssl_enforcement_enabled = true + } + + resource "azurerm_mariadb_database" "example" { + name = var.name + resource_group_name = azurerm_resource_group.example.name + server_name = azurerm_mariadb_server.example.name + charset = "utf8" + collation = "utf8_general_ci" + } + + variable "name" { + default = "mariadb_database" + type = string + description = "Database instance name" + } + + variable "username" { + default = "acctestun" + type = string + description = "Database instance username" + } + + variable "password" { + default = "H@Sh1CoR3!faked" + type = string + description = "Database instance password" + } + providerRef: + name: azure + namespace: default