HI
Im a new in Terraform, so mb do not understand everything
Right now im trying to set Tags for “aws_lb” resources using Dynamic blocks.
I have a main.tf where using module and sending pre-defined Tags list into the module
module "webserver_cluster" {
source = "../../../../Modules/services/webserver-cluster"
...
custom_tags = {
Owner = "IEA"
DeployedBy = "Terraform"
}
}
In the module I use dynamic block to set the tags for “aws_autoscaling_group” and “aws_lb”:
resource "aws_autoscaling_group" "Ter_T1_ASG" {
...
dynamic "tag" {
for_each = var.custom_tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
}
...
resource "aws_lb" "Ter_ALB_T1" {
...
dynamic "tag" {
for_each = var.custom_tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
Mb its important, the “custom_tags” is defined in variables.tf module as:
variable "custom_tags" {
description = "Custom tags to set on"
type = map(string)
default = {}
}
While for “aws_autoscaling_group” resource the structure is OK, for “aws_lb” there is an error:
│ Error: Unsupported block type
│
│ on ../../../../Modules/services/webserver-cluster/main.tf line 121, in resource "aws_lb" "Ter_ALB_T1":
│ 121: dynamic "tag" {
│
│ Blocks of type "tag" are not expected here.
I do not understand why?