terraform

Terraform - loops

大憨熊 提交于 2020-12-15 06:06:25
问题 Is it possible to create a loop that creates this resources? There is a lot of repetition of the same resources. I tried using maps to create a loop but map doesn't accept anything other default block. Or is it normal to manually create all 4 resources? Just some suggestions as answer is enough, I'm trying to learn it myself. resource "aws_subnet" "public-test-a" { vpc_id = aws_vpc.vpc-test-02.id cidr_block = "10.0.0.16/28" map_public_ip_on_launch = true availability_zone = var.AZ[1] tags = {

How to use Terraform modules for code re-use?

浪子不回头ぞ 提交于 2020-12-15 06:05:22
问题 Terraform v0.12.x I thought I understood Terraform modules for code re-use after reading the docs, but apparently not. Say I want to build a target group+EC2 instance infrastructure. I have this directory structure. /terraform /terraform/green.tf /terraform/blue.tf /terraform/module_ec2/ec2.tf /terraform/module_tg/tg.tf For example, /terraform/module_ec2/ec2.tf has this resource "aws_instance" "ec2" { ami = var.ami availability_zone = var.availability_zone .... } and /terraform/module_tg/tg

Create GKE cluster and namespace with Terraform

亡梦爱人 提交于 2020-12-15 01:57:34
问题 I need to create GKE cluster and then create namespace and install db through helm to that namespace. Now I have gke-cluster.tf that creates cluster with node pool and helm.tf, that has kubernetes provider and helm_release resource. It first creates cluster, but then tries to install db but namespace doesn't exist yet, so I have to run terraform apply again and it works. I want to avoid scenario with multiple folder and run terraform apply only once. What's the good practice for situaction

Create GKE cluster and namespace with Terraform

寵の児 提交于 2020-12-15 01:55:33
问题 I need to create GKE cluster and then create namespace and install db through helm to that namespace. Now I have gke-cluster.tf that creates cluster with node pool and helm.tf, that has kubernetes provider and helm_release resource. It first creates cluster, but then tries to install db but namespace doesn't exist yet, so I have to run terraform apply again and it works. I want to avoid scenario with multiple folder and run terraform apply only once. What's the good practice for situaction

Create GKE cluster and namespace with Terraform

余生颓废 提交于 2020-12-15 01:55:04
问题 I need to create GKE cluster and then create namespace and install db through helm to that namespace. Now I have gke-cluster.tf that creates cluster with node pool and helm.tf, that has kubernetes provider and helm_release resource. It first creates cluster, but then tries to install db but namespace doesn't exist yet, so I have to run terraform apply again and it works. I want to avoid scenario with multiple folder and run terraform apply only once. What's the good practice for situaction

Terraform (0.12.29) import not working as expected; import succeeded but plan shows destroy & recreate

不想你离开。 提交于 2020-12-13 03:30:30
问题 Some Background: We have terraform code to create various AWS resources. Some of these resources are created per AWS account and hence are structured to be stored in a account-scope folder in our project. This was when we were only having one AWS region. Now our application is made multi-region and hence these resources are to be created per region for each AWS account. In order to do that we have now moved these TF scripts to region-scope folder which will be run per region. Since these

Terraform (0.12.29) import not working as expected; import succeeded but plan shows destroy & recreate

孤街浪徒 提交于 2020-12-13 03:27:47
问题 Some Background: We have terraform code to create various AWS resources. Some of these resources are created per AWS account and hence are structured to be stored in a account-scope folder in our project. This was when we were only having one AWS region. Now our application is made multi-region and hence these resources are to be created per region for each AWS account. In order to do that we have now moved these TF scripts to region-scope folder which will be run per region. Since these

Terraform (0.12.29) import not working as expected; import succeeded but plan shows destroy & recreate

ぃ、小莉子 提交于 2020-12-13 03:26:15
问题 Some Background: We have terraform code to create various AWS resources. Some of these resources are created per AWS account and hence are structured to be stored in a account-scope folder in our project. This was when we were only having one AWS region. Now our application is made multi-region and hence these resources are to be created per region for each AWS account. In order to do that we have now moved these TF scripts to region-scope folder which will be run per region. Since these

Terraform - Create type constraints for type Map

倾然丶 夕夏残阳落幕 提交于 2020-12-13 03:13:35
问题 What would be the correct way to create type constraints for type map? This doesn't seem valid. variable "vpc_subnets" { type = map( key = {name = string, cidr_block = string, map_public_ip_on_launch = bool, availability_zone = string} ) } Here is what the map looks like.. vpc_subnets = { "public_subnet_a" = {name = "public_test_a", cidr_block = "10.0.0.0/28", map_public_ip_on_launch = true, availability_zone = "ap-south-1a"}, "public_subnet_b" = {name = "public_test_b", cidr_block = "10.0.0

Terraform - conditionally creating a resource within a loop

◇◆丶佛笑我妖孽 提交于 2020-12-10 03:29:13
问题 Is it possible to combine resource creation with a loop (using count) and conditionally skip some resources based on the value of a map? I know we can do these things separately: use count to create resources in a loop. use the variable/count workaround (in place of an 'if' statement) to conditional create a resource To illustrate lets say I have a list of maps: variable "resources" { type = "list" default = [ { name = "kafka" createStorage = true }, { name = "elastic" createStorage = false }