Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Generate dynamic cached HCL based on .tfvars formatted / predefined structure #983

Open
eistrati opened this issue Jan 8, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@eistrati
Copy link
Contributor

eistrati commented Jan 8, 2020

Describe the Feature

Generate dynamic cached HCL based on .tfvars formatted / predefined structure

Expected Behavior

Let's take a look at the following basic example: https://www.terraform.io/docs/providers/aws/r/lambda_function.html#basic-example

In this case, .terrahub.yml should look like this:

component:
  name: my_lambda_function
  template:
    dynamic:
      tfvars:
        - default.tfvars

And default.tfvars should looks like this:

# @resource aws_iam_role.iam_for_lambda
name = "iam_for_lambda"
assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
EOF

# @resource
# aws_lambda_function.test_lambda
filename      = "lambda_function_payload.zip"
function_name = "lambda_function_name"
role          = aws_iam_role.iam_for_lambda.arn
handler       = "exports.test"
runtime       = "nodejs8.10"
source_code_hash = "${filebase64sha256("lambda_function_payload.zip")}"
environment = {
  variables = {
    foo = "bar"
  }
}

Generated HCL should look like this:

resource "aws_iam_role" "iam_for_lambda" {
  name = var.name
  assume_role_policy = var.assume_role_policy
}

resource "aws_lambda_function" "test_lambda" {
  filename      = var.filename
  function_name = var.function_name
  role          = aws_iam_role.iam_for_lambda.arn
  handler       = var.handler
  runtime       = var.runtime
  source_code_hash = var.source_code_hash
  environment   = var.environment
}

NOTE: In case a much more complex syntax is required, something that cannot be expressed through a pair of key and value in.tfvars file, the configuration template.dynamic.tfvars.* from terrahub could be anytime combined with template.resource.* or template.data.* constructs for further extension and support of terraform features.

@eistrati eistrati added the enhancement New feature or request label Jan 8, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants