Capturing multiple outputs from Module -Terraform

resource “aws_iam_policy” “my_custom_policy” {
name = “custom_policy”
description = “custom_policy , tf code for medium”
policy = data.aws_iam_policy_document.custom_policy.json
}

#the policy json for above policy
data “aws_iam_policy_document” “custom_policy_doc” {
statement {
sid = “Alpha1”
effect = “Allow”
actions = [
“s3:ListBucket”,
“s3:ListAllMyBuckets”,
]
resources = [“arn:aws:s3:::bucket-85”]
}

//main.tf
resource “aws_iam_policy” “my_custom_policy” {
name = “custom_policy_for_${var.bucket_name}”
description = “custom_policy for bucket — ${var.bucket_name}, tf code for medium”
policy = data.aws_iam_policy_document.custom_policy.json
}

#the policy json for above policy
data “aws_iam_policy_document” “custom_policy_doc” {
statement {
sid = “Alpha1”
effect = “Allow”
actions = [
“s3:ListBucket”,
“s3:ListAllMyBuckets”,
]
resources = [“arn:aws:s3:::${var.bucket_name}*”]
}

// variables.tf
variable “bucket_name” {
type = string
description = “bucket name”
}

module  "my_custom_policies_based_on_input" {
for_each = var.buckets
source = "./modules/templated_policies"
bucket_name = each.value
}
output "my_custom_policy_name" {
value = aws_iam_policy.my_custom_policy.name
description = "the single policy we created"
}
output "my_custom_policy_arn" {
value = aws_iam_policy.my_custom_policy.arn
description = "the single policy we created"
}
output "my_custom_policies_details" {
value = zipmap( values(module.my_custom_policies_based_on_input)[*].my_custom_policy_name,
values(module.my_custom_policies_based_on_input)[*])
}
resource ".." "..."{
for_each = module.medium_module.my_custom_policies_details
data = {
POLICY_NAME = each.key
POLICY_ARN = each.value["my_custom_policy_arn"] }
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store