Closed mordowiciel closed 3 years ago
Try changing this part of your terragrunt.hcl:
arguments = [
"-var", "vpc_id=${local.region_vars.locals.vpc_id}",
"-var", "region=${local.region_vars.locals.region}"
]
@lorengordon Thanks, that did the trick!
However, isn't it inconsistent with the Terraform command template? When you'll call terraform apply --help
:
Usage: terraform apply [options] [DIR-OR-PLAN]
Builds or changes infrastructure according to Terraform configuration
files in DIR.
By default, apply scans the current directory for the configuration
and applies the changes appropriately. However, a path to another
configuration or an execution plan can be provided. Execution plans can be
used to only execute a pre-determined set of actions.
Options:
(...)
-var 'foo=bar' Set a variable in the Terraform configuration. This
flag can be set multiple times.
You can clearly see that the passed variable needs to be surrounded by single quotes. I think it would be nice to mention the auto-completion of single quotes in Terragrunt documentation, or just allow both notations (with and without quotes) to be used.
No, this is a shell interpolation thing. Has nothing to do with terragrunt at all. The problem was your prior syntax was passing the literal string to the shell, e.g. terraform "-var 'vpc_id=us-east-1'"
. "-var 'vpc_id=us-east-1'"
is not a valid argument to terraform.
The single quotes are needed when you have values with spaces or some kind of other complexity that the shell might interpret funny. You can still do that with terragrunt, if you want:
arguments = [
"-var", "'vpc_id=${local.region_vars.locals.vpc_id}'",
"-var", "'region=${local.region_vars.locals.region}'"
]
The syntax requirement here is just separating the list items, so the terraform argument, -var
, and the argument value, 'vpc_id=${local.region_vars.locals.vpc_id}'
, are separate items in the list.
Closing this as the original question has been answered. If there are any follow ups, please open a new ticket with updated context. Thanks!
Background: I'd like to create one security group with one rule attached and then pass its ARN to another module. I think that creating another Terraform module for such small task is a bit overkill, so I've decided to put regular Terraform files together with terragrunt.hcl in one of the directories.
Working environment: The directory structure is following:
providers.tf:
sg.tf:
variables.tf:
terragrunt.hcl:
environment.hcl:
region.hcl:
terragrunt.hcl (root):
Problem: While performing
terragrunt apply
in the security-group module, Terraform returns the message similar to the one where you call it with the wrong parameters:However, calling the same command in the same directory, which was produced by the Terragrunt at the end of the run, using the vanilla Terraform, finishes without error:
Component versions: