Hello… terraform newbie here =)
I’m trying to follow this doc using for_each
. Heres my twist:
data "aws_subnet_ids" "public" {
vpc_id = aws_vpc.js_vpc.id
tags = {
Scope = "Public"
}
}
resource "aws_route_table_association" "public" {
depends_on = [aws_subnet.public_subnets]
for_each = data.aws_subnet_ids.public.ids
subnet_id = each.value
route_table_id = aws_route_table.public.id
}
Understandably for_each
doesnt know whats going on and screamed at me with…
$ terraform plan
...
------------------------------------------------------------------------
Error: Invalid for_each argument
on ../../modules/vpc/route-tables.tf line 88, in resource "aws_route_table_association" "public":
88: for_each = data.aws_subnet_ids.public.ids
The "for_each" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the for_each depends on.
So I proceed to append -target
into the cmd
$ terraform plan -target=aws_subnet.public_subnets
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
No changes. Infrastructure is up-to-date.
This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.
Warning: Resource targeting is in effect
You are creating a plan with the -target option, which means that the result
of this plan may not represent all of the changes requested by the current
configuration.
The -target option is not for routine use, and is provided only for
exceptional situations such as recovering from errors or mistakes, or when
Terraform specifically suggests to use it as part of an error message.
This seems to me that terraform didnt do anything… Whats the recommended cmd to go about this?