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"] }
}

--

--

--

Data Engineering

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

Recommended from Medium

Data Structure — Linked List

Widgets in Flutter

Test Slow to Go Faster

Let’s Encrypt Wildcard Certificate | Route53, NGINX, CentOS/RHEL 7

Connecting the Dots: The Met and Google Maps API mashup

CI/CD and Change Management for Pipelines — Part 3

5 Code Editors Every New Developer Should Know About

Illustration of five text editors: sublime text, atom, codepen, colaboratory, jetbrains by Ruben A Sanchez.

Become a Full Stack Web Developer | Practical Step by Step Frontend and Backend Guide

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

Data Engineering

More from Medium

Istio Service Mesh by Practical Example

Helm and Charts in Kubernetes.

Helm and Charts in Kubernetes.

Build Private Cloud with OpenStack Kolla-ansible Step by Step Guide 1.0