From ca2476d743da1c8b9f622af071506d5299e3ceb6 Mon Sep 17 00:00:00 2001 From: shanye Date: Mon, 4 Nov 2024 16:56:26 +0800 Subject: [PATCH] Module: add outputs.tf; example/complete: improve the examples --- examples/complete/main.tf | 25 +++++++++++++++---------- examples/complete/versions.tf | 3 +++ main.tf | 4 ++-- outputs.tf | 4 ++++ variables.tf | 24 ------------------------ 5 files changed, 24 insertions(+), 36 deletions(-) create mode 100644 examples/complete/versions.tf create mode 100644 outputs.tf diff --git a/examples/complete/main.tf b/examples/complete/main.tf index b7a00a4..2226e7e 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -6,29 +6,34 @@ data "alicloud_images" "default" { } data "alicloud_instance_types" "default" { - availability_zone = data.alicloud_zones.default.zones.0.id + availability_zone = data.alicloud_zones.default.zones[0].id } module "vpc" { - source = "alibaba/vpc/alicloud" + source = "alibaba/vpc/alicloud" + version = "~>1.11.0" + create = true vpc_cidr = "172.16.0.0/16" vswitch_cidrs = ["172.16.0.0/21"] - availability_zones = [data.alicloud_zones.default.zones.0.id] + availability_zones = [data.alicloud_zones.default.zones[0].id] } module "security_group" { - source = "alibaba/security-group/alicloud" + source = "alibaba/security-group/alicloud" + version = "~>2.4.0" + vpc_id = module.vpc.this_vpc_id } module "ecs-instance" { - source = "alibaba/ecs-instance/alicloud" + source = "alibaba/ecs-instance/alicloud" + version = "~>2.12.0" number_of_instances = 1 - instance_type = data.alicloud_instance_types.default.instance_types.0.id - image_id = data.alicloud_images.default.images.0.id + instance_type = data.alicloud_instance_types.default.instance_types[0].id + image_id = data.alicloud_images.default.images[0].id vswitch_ids = [module.vpc.this_vswitch_ids[0]] security_group_ids = [module.security_group.this_security_group_id] associate_public_ip_address = false @@ -47,9 +52,9 @@ resource "alicloud_nat_gateway" "this" { } module "eip" { - source = "terraform-alicloud-modules/eip/alicloud" + source = "terraform-alicloud-modules/eip/alicloud" + version = "~>2.1.0" - create = true number_of_eips = 1 bandwidth = var.eip_bandwidth internet_charge_type = "PayByTraffic" @@ -75,4 +80,4 @@ module "complete" { internal_ip = module.ecs-instance.this_private_ip[0] entries = var.entries -} \ No newline at end of file +} diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf new file mode 100644 index 0000000..684b365 --- /dev/null +++ b/examples/complete/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.13" +} \ No newline at end of file diff --git a/main.tf b/main.tf index d15cd9d..9b54a5c 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,5 @@ locals { - dnat_table_id = var.dnat_table_id != "" ? var.dnat_table_id : var.nat_gateway_id != "" ? concat(data.alicloud_nat_gateways.this.gateways.*.dnat_table_id, [""])[0] : "" + dnat_table_id = var.dnat_table_id != "" ? var.dnat_table_id : var.nat_gateway_id != "" ? concat(data.alicloud_nat_gateways.this.gateways[*].dnat_table_id, [""])[0] : "" } data "alicloud_nat_gateways" "this" { @@ -15,6 +15,6 @@ resource "alicloud_forward_entry" "this" { external_ip = lookup(var.entries[count.index], "external_ip", var.external_ip) external_port = lookup(var.entries[count.index], "external_port", "any") internal_ip = lookup(var.entries[count.index], "internal_ip", var.internal_ip) - // Default to external_port + # Default to external_port internal_port = lookup(var.entries[count.index], "internal_port", lookup(var.entries[count.index], "external_port", "any")) } \ No newline at end of file diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..dc7fe1f --- /dev/null +++ b/outputs.tf @@ -0,0 +1,4 @@ +output "this_forward_entry_id" { + description = "The ID of the forward entrys" + value = alicloud_forward_entry.this[*].id +} diff --git a/variables.tf b/variables.tf index 05e7f4b..58cc454 100644 --- a/variables.tf +++ b/variables.tf @@ -1,28 +1,4 @@ -################# -# Provider -################# -variable "region" { - description = "(Deprecated from version 1.1.0) The region used to launch this module resources." - type = string - default = "" -} - -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 "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 -} ################# # Dnat Entries