Issues using for_each to create names
Could anyone advise the how or why it does the following:
You have two of the same resources named different
Inside the module
resource “aws_s3_bucket” “example1” {
bucket = var.example1 # Replace with your desired bucket name
}
resource “aws_s3_bucket” “example2” {
bucket = var.example2
}
variable “example1” {
type = string
description = “S3 bucket name”
default = “example1”
}
variable “example2” {
type = string
description = “naming for s3 buckets”
}
Inside the main
module “example1” {
source = “…/…/modules/s3”
example1 = “example1”
environment = local.environment
}
module “example2” {
source = “…/…/modules/s3”
for_each = toset([“test1”, “test2”, “test3”])
example2 = “${each.key}_bucket”
environment = local.environment
}
I believe it is cause inside the main.tf it does associate with the resource but just the folder itself but unsure
Was using this documentation from terraform referencing the child module: with an additional resource in my code block The for_each Meta-Argument - Configuration Language | Terraform | HashiCorp Developer
5 posts - 2 participants