hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
41.72k stars 9.42k forks source link

Pass in resource/module arguments with a single map #27524

Open nitrocode opened 3 years ago

nitrocode commented 3 years ago

It would be nice to pass in a single argument to a resource using a map.

For instance, in python

def test(arg1, arg2, arg3):
  pass

args = {"arg1": True, "arg2": True, "arg3": False}

test(**args)

Perhaps something like this in terraform

locals {
  test_role_args = {
    name = "test_role"

    assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "ec2.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
EOF

    tags = {
      tag-key = "tag-value"
    }
  }
}

resource "aws_iam_role" "test_role" {
  args = local.test_role_args
}
jcarpenter12 commented 1 year ago

I would also love to see this feature. Would be really handy for creating resources from a list of maps that have slightly different requirements (I.e some default values need to be overridden using additional map keys).

daltschu22 commented 1 week ago

THis is one of the single biggest downsides to using terraform at the moment. If I want to extend a resource using arbitrary terraform code I currently cannot do so. I need to define a dynamic with every single possible attribute defined underneath. You need to know exactly what could be passed in.

I would really like to be able to pass in arbitrary HCL and have that executed in place.