From 214bd7aa61675d4ebcf7a4b9ff19c39f41eb18e2 Mon Sep 17 00:00:00 2001 From: shanye Date: Tue, 10 Sep 2024 15:53:42 +0800 Subject: [PATCH] module: support alicloud_adb_db_cluster instead of alicloud_adb_cluster --- examples/complete/main.tf | 21 ++++++++++-------- locals.tf | 4 ++-- main.tf | 6 +++--- outputs.tf | 20 ++++++++--------- variables.tf | 45 +++++++++------------------------------ 5 files changed, 37 insertions(+), 59 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 5fcff2a..e12d2a7 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -1,26 +1,29 @@ -data "alicloud_vpcs" "default" { - name_regex = "default-NODELETING" +variable "name" { + default = "terraform-example" } +data "alicloud_adb_zones" "default" {} + +data "alicloud_vpcs" "default" { + name_regex = "^default-NODELETING$" +} data "alicloud_vswitches" "default" { - name_regex = "default-zone-g" - vpc_id = data.alicloud_vpcs.default.vpcs.0.id + vpc_id = data.alicloud_vpcs.default.ids.0 + zone_id = data.alicloud_adb_zones.default.ids.0 } module "adb_example" { source = "../.." - create_cluster = true - vswitch_id = data.alicloud_vswitches.default.vswitches.0.id availability_zone = data.alicloud_vswitches.default.vswitches.0.zone_id db_cluster_version = "3.0" db_cluster_category = "Cluster" db_node_class = "C8" - db_node_count = 2 + db_node_count = 1 db_node_storage = var.db_node_storage mode = "reserver" - pay_type = "PostPaid" + payment_type = "PayAsYouGo" description = var.description -} \ No newline at end of file +} diff --git a/locals.tf b/locals.tf index 94e463d..b8a2227 100644 --- a/locals.tf +++ b/locals.tf @@ -1,4 +1,4 @@ locals { # Get ID of ADB cluster - this_cluster_id = var.existing_cluster_id != "" ? var.existing_cluster_id : concat(alicloud_adb_cluster.this.*.id, [""])[0] -} \ No newline at end of file + this_cluster_id = var.create_cluster ? alicloud_adb_db_cluster.this[0].id : var.existing_cluster_id +} diff --git a/main.tf b/main.tf index 8bf975c..a0606e6 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,4 @@ -resource "alicloud_adb_cluster" "this" { +resource "alicloud_adb_db_cluster" "this" { count = var.create_cluster ? 1 : 0 vswitch_id = var.vswitch_id zone_id = var.availability_zone @@ -8,6 +8,6 @@ resource "alicloud_adb_cluster" "this" { db_node_count = var.db_node_count db_node_storage = var.db_node_storage mode = var.mode - pay_type = var.pay_type + payment_type = var.payment_type description = var.description -} \ No newline at end of file +} diff --git a/outputs.tf b/outputs.tf index e403e89..b9bbbdb 100644 --- a/outputs.tf +++ b/outputs.tf @@ -6,45 +6,45 @@ output "this_adb_cluster_id" { output "this_adb_description" { description = "The description of ADB cluster." - value = concat(alicloud_adb_cluster.this.*.description, [""])[0] + value = alicloud_adb_db_cluster.this[*].description } output "this_adb_cluster_zone_id" { description = "The Zone to launch the ADB cluster." - value = concat(alicloud_adb_cluster.this.*.zone_id, [""])[0] + value = alicloud_adb_db_cluster.this[*].zone_id } output "this_adb_cluster_vswitch_id" { description = "The virtual switch ID to launch ADB cluster in one VPC. " - value = concat(alicloud_adb_cluster.this.*.vswitch_id, [""])[0] + value = alicloud_adb_db_cluster.this[*].vswitch_id } output "this_adb_cluster_db_cluster_version" { description = "The version of the ADB cluster." - value = concat(alicloud_adb_cluster.this.*.db_cluster_version, [""])[0] + value = alicloud_adb_db_cluster.this[*].db_cluster_version } output "this_adb_cluster_db_cluster_category" { description = "The catrgory type of the ADB cluster. " - value = concat(alicloud_adb_cluster.this.*.db_cluster_category, [""])[0] + value = alicloud_adb_db_cluster.this[*].db_cluster_category } output "this_adb_cluster_db_node_class" { description = "The node class of the core node. " - value = concat(alicloud_adb_cluster.this.*.db_node_class, [""])[0] + value = alicloud_adb_db_cluster.this[*].db_node_class } output "this_adb_cluster_db_node_count" { description = "The node count of the ADB cluster. " - value = concat(alicloud_adb_cluster.this.*.db_node_count, [""])[0] + value = alicloud_adb_db_cluster.this[*].db_node_count } output "this_adb_cluster_db_node_storage" { description = "The node storage size of the ADB cluster. " - value = concat(alicloud_adb_cluster.this.*.db_node_storage, [""])[0] + value = alicloud_adb_db_cluster.this[*].db_node_storage } output "this_adb_cluster_pay_type" { description = "The pay type." - value = concat(alicloud_adb_cluster.this.*.pay_type, [""])[0] -} \ No newline at end of file + value = alicloud_adb_db_cluster.this[*].pay_type +} diff --git a/variables.tf b/variables.tf index 6bbd95c..da246de 100644 --- a/variables.tf +++ b/variables.tf @@ -1,51 +1,26 @@ -# Provider -variable "profile" { - description = "(Deprecated from version 1.1.0) The profile name as set in the shared credentials file. If not set, it will be sourced from the ALICLOUD_PROFILE environment variable." - type = string - default = "" -} - -variable "shared_credentials_file" { - description = "(Deprecated from version 1.1.0) This is the path to the shared credentials file. If this is not set and a profile is specified, $HOME/.aliyun/config.json will be used." - type = string - default = "" -} - -variable "region" { - description = "(Deprecated from version 1.1.0) The region used to launch this module resources." - type = string - default = "" -} - -variable "skip_region_validation" { - description = "(Deprecated from version 1.1.0) Skip static validation of region ID. Used by users of alternative AlibabaCloud-like APIs or users w/ access to regions that are not public (yet)." - type = bool - default = false -} - # ADB Cluster variable "create_cluster" { description = "Whether to create ADB cluster. If false, you can use a existing ADB cluster by setting 'existing_cluster_id'." type = bool - default = false + default = true } variable "existing_cluster_id" { description = "The Id of an existing ADB cluster. It will be ignored when create_cluster = true." type = string - default = "" + default = null } variable "vswitch_id" { description = "VSwitch variables, if vswitch_id is empty, then the net_type = classic." type = string - default = "" + default = null } variable "availability_zone" { description = "The available zone to launch ADB cluster." type = string - default = "" + default = null } variable "db_cluster_version" { @@ -81,17 +56,17 @@ variable "db_node_storage" { variable "mode" { description = " The mode of the cluster. Valid values: reserver, flexible." type = string - default = "reserver" + default = null } -variable "pay_type" { - description = "pay type, Valid value:Prepaid: The subscription billing method is used, Postpaid: The pay-as-you-go billing method is used." +variable "payment_type" { + description = "The payment type of the resource. Valid values: `PayAsYouGo` and `Subscription`. Default Value: `PayAsYouGo`" type = string - default = "PostPaid" + default = null } variable "description" { description = "Display name of the cluster, [2, 128] English or Chinese characters, must start with a letter or Chinese in size, can contain numbers, '_' or '.', '-'." type = string - default = "" -} \ No newline at end of file + default = null +}