Terraform Imports: Resources, Modules, for_each, and Count | by Tyler DeKnecht | The Startup | Medium
"child" module
medium_demo.tf
variable "user_name" {}
resource "aws_iam_user" "user" {
for_each = toset(var.user_name) # receiving var values list
name = each.value # "iterator", creating iam users from list
# ...
}
}
"parent" block, "calling" child module medium_demo.tf
main.tf
source = "../modules/iam/medium_demo"
user_name = ["bill"] # defines list of values passed to module
# ...
}
}
Final "bill" is AWS IAM ID of resource being imported, in this case username
> terraform import module.iam.aws_iam_user.user[\"bill\"] bill
No comments:
Post a Comment