From 1e1c4b978efba13db60c36d1049d7ac066deb7d3 Mon Sep 17 00:00:00 2001 From: x p k Date: Sun, 2 Aug 2020 18:58:41 +0800 Subject: [PATCH] UPD: moved random into a module --- tf-modulised/vpc-subnets/random/main.tf | 17 +++++++++++++++++ tf-modulised/vpc-subnets/vpc.tf | 14 ++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 tf-modulised/vpc-subnets/random/main.tf diff --git a/tf-modulised/vpc-subnets/random/main.tf b/tf-modulised/vpc-subnets/random/main.tf new file mode 100644 index 0000000..6a4d35d --- /dev/null +++ b/tf-modulised/vpc-subnets/random/main.tf @@ -0,0 +1,17 @@ +resource "random_string" "string" { + length = 4 + special = false +} + +resource "random_integer" "number" { + min = 1000 + max = 9999 +} + +output "string" { + value = random_string.string.result +} + +output "number" { + value = random_integer.number.result +} diff --git a/tf-modulised/vpc-subnets/vpc.tf b/tf-modulised/vpc-subnets/vpc.tf index 22ae18f..50de966 100644 --- a/tf-modulised/vpc-subnets/vpc.tf +++ b/tf-modulised/vpc-subnets/vpc.tf @@ -1,25 +1,19 @@ data "aws_availability_zones" "available" {} -#resource "random_string" "suffix" { -# length = 4 -# special = false -#} - -resource "random_integer" "suffix" { - min = 1000 - max = 9999 +module "random" { + source = "./random" } module "vpc" { source = "terraform-aws-modules/vpc/aws" version = "2.6.0" - name = "demo-vpc-${random_integer.suffix.result}" + name = "demo-vpc-${module.random.number}" cidr = "172.16.0.0/16" azs = data.aws_availability_zones.available.names private_subnets = cidrsubnets("172.16.18.0/23", 1, 1) public_subnets = cidrsubnets("172.16.20.0/23", 1, 1) - enable_nat_gateway = true + enable_nat_gateway = false single_nat_gateway = true enable_dns_hostnames = true