Capturing multiple outputs from Module -Terraform

  1. Can create as many policies depending on the input arguments, dynamic provisioning.we don't need to know the count.
  2. Same code can be re used for N number of policies.Small and efficient code. No redudancy.
  3. We have greater control over what an IAM role with this policy can access since we have passed the variable name as input to resources accessed.(resources = [“arn:aws:s3:::${var.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"] }
}

--

--

--

All things Data| Lead Data Platform @ Razorpay | Ex-MongoDB

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Official WooCommerce Mobile App Review

Avoid conditional GET request issue with cache mediator in WSO2 ESB

Cryptographic Hash Functions

Revisiting OS

Translate articles easily with Amazon Translate and R

Evangelicalism in America is nearing extinction due to the movement’s devotion to politics at the…

Apache Spark 3.0 Review–What the Spark is all about

Why Software Developers Are Crucial for Improving Quantum Computers

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
Harry Singh

Harry Singh

All things Data| Lead Data Platform @ Razorpay | Ex-MongoDB

More from Medium

Model Monitoring with AWS Sagemaker Studio

Authenticate Apache NiFi Users via Okta OIDC (OpenID Connect)

KWOC | Kharagpur Winter of Code Project Report

Access AWS s3 bucket files and integration with the Test framework