hashicorp/vault-guides

There seems to be issue with variable section and also multi-line syntax

Balakirshna-devops opened this issue · 17 comments

[root@ip-172-31-25-193 terraform-aws]# terraform init
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Reserved argument name in module block

on main.tf line 148, in module "consul_aws":
148: count = var.consul_servers

The name "count" is reserved for use in a future version of Terraform.

Error: Reserved argument name in module block

on main.tf line 199, in module "vault_aws":
199: count = var.vault_servers

The name "count" is reserved for use in a future version of Terraform.

Error: Invalid variable name

on variables.tf line 16, in variable "provider":
16: variable "provider" {

The variable name "provider" is reserved due to its special meaning inside
module blocks.

Error: Invalid multi-line string

on outputs.tf line 29, in output "zREADME":
29:
30:

Quoted strings may not be split over multiple lines. To produce a multi-line
string, either use the \n escape to represent a newline character or use the
"heredoc" multi-line template syntax.

Error: Invalid multi-line string

on outputs.tf line 30, in output "zREADME":
30:
31:

Quoted strings may not be split over multiple lines. To produce a multi-line
string, either use the \n escape to represent a newline character or use the
"heredoc" multi-line template syntax.

Error: Invalid multi-line string

on outputs.tf line 31, in output "zREADME":
31:
33:

Quoted strings may not be split over multiple lines. To produce a multi-line
string, either use the \n escape to represent a newline character or use the
"heredoc" multi-line template syntax.

Can someone help to fix this?

@Balakirshna-devops Which Terraform version are you running? I'm not sure which guide this is about, but if you're running Terraform v0.12.x, you might want to try terraform 0.12upgrade command first, and see if it solves the issue.

mushi commented

I also encountered this. terraform 0.12upgrade did not fix it, but downgrading to Terraform v0.11.14 did.

@Balakirshna-devops As @mushi said, use Terraform v0.11.x is probably the only workaround at the moment. I ended up installing homebrew-core so that I can switch between Terraform v0.12 and v0.11.x.

Is there any progress on that? It is actually blocking us from upgrading to terraform v0.12. I think this is not a bug in vault but rather in terraform v0.12, isn't it?

Hi @Balakirshna-devops. It looks like you are trying to migrate the example code in this repository to Terraform 0.12. The first two errors are clearly caused by variable names that are not valid in 0.12. You could change those wherever they are used. The third error is a bit mysterious since HEREDOC notation is already being used in the file where the error occurred. If you want to do a PR to update the code, that would be great. It would help us diagnose the third error if you provided your modified outputs.tf file so we can see the exact line where the error occurred. The line number given in your error messages does not line up with what I see under https://github.com/hashicorp/vault-guides/blob/master/operations/provision-vault/quick-start/terraform-aws/outputs.tf#L2.

Also, I assume the lines with the original variables that gave the first two errors were

and https://github.com/hashicorp/vault-guides/blob/master/operations/provision-vault/quick-start/terraform-aws/variables.tf#L7.

That assumes you are using the code under https://github.com/hashicorp/vault-guides/tree/master/operations/provision-vault/quick-start/terraform-aws. Let us know if you are using code from a different part of the repository.

Is there any progress on that? It is actually blocking us from upgrading to terraform v0.12. I think this is not a bug in vault but rather in terraform v0.12, isn't it?

I am sorry, I need to revert this comment, I was using a module and haven't run terraform 0.12upgrade command in that module folder. Running it, fixed my issues.

If you change the variable count in here, I think you would need to update:

Agreed above. I edited the variables after my upgrade 0.12 and while the upgrade seems to ahve fixed SOME things, the variables used are no longer allowed (due to the words being set aside) and since those variables are used in multiple places, changing them (to something like consulcount or vaultcount) basically breaks everything. After trying to edit therm I get key errors on almost all the builds.

Any plans to upgrade that script to terraform 0.12?

Is there any update to this issue? After updating to terraform 0.12 when I attempt to run terraform init/plan I get:

PS C:\Users\bsherman\Documents\Terraform\Vault> terraform plan

Error: Reserved argument name in module block

on main.tf line 116, in module "consul_aws":
116: count = var.consul_servers

The name "count" is reserved for use in a future version of Terraform.

Error: Reserved argument name in module block

on main.tf line 158, in module "vault_aws":
158: count = var.vault_servers

The name "count" is reserved for use in a future version of Terraform.

Error: Invalid variable name

on variables.tf line 16, in variable "provider":
16: variable "provider" {

The variable name "provider" is reserved due to its special meaning inside
module blocks.

PS C:\Users\bsherman\Documents\Terraform\Vault>

I was able to get terraform plan to produce a plan using the terraform-aws best practices guide with something like the steps below.

The reasons for the hedge in that statement are the following:

  1. We are running Terraform v0.12.19. Your results may differ if you're using something else.
  2. A lot of my choices were "error-message driven development." (Thanks to the Hashicorp team for providing such good error messages.) I tried to take some notes while I was going through them, but I definitely failed at that. So this is more a source of inspiration than a runbook.
  3. Given the fact that some folks responding here said "I got it" and left at that might mean I've drastically overcomplicated things.
  4. I'm trying to incorporate this guide into our existing tf codebase as a POC for Vault. As a result, I didn't just clone the repo. Instead, I copied the main.tf, outputs.tf, variables.tf files, and the templates directory into our repo and invoked that module in the "main" file that we use to control our infra. So at the end of the work, here's what our directory structure looks like:
terraform/
|- modules/
|-- vault/
|--- main.tf, outputs.tf, variables.tf
|- templates/
|- dev/
|-- main.tf
|-- .terraform
|--- modules, plugins # all relating to vault

With all that said, here's basically what it took:

  1. update path to template file in main.tf
  2. remove all the line breaks in the ternary in outputs.tf and replace them with line breaks (\n)
  3. in my dev directory, run terraform init
  4. essentially go into each of the downloaded modules in dev/.terraform and do some or all of the following:
  • run terraform 0.12upgrade -yes . or terraform 0.12upgrade -yes .terraform/modules/path-to-module
  • if the previous gave error messages about not having downloaded modules, cd into the downloaded module and run terraform init
  • manually fix the changed syntax for things like "map" to "map(string)"
  • sometimes go back to the old syntax from var.attribute to "${var.attribute}"
  1. at this point, I think I was able to start running terraform plan in my dev directory and it would start collecting state. Then I started working through the following (not in order):
  • commenting out blocks annotated with TF-UPGRADE-TODO
  • fixing the var.count naming issues in the vault.vault_aws and vault.consul_aws modules and all the errors that generates
  • changing all the count = var.create ? 1 : 0 statements to count = var.create, unless changing it gave an error message
  • dealing with a lot of funny stuff that had to do with using lists, which I think centered on parts marked TODO: Workaround for issue #11210
  • dealing with the vault.network_aws.subnet_private_ids and public by (hopefully) standardizing the fact that that value is a list and not a string separated by commas

At the end of all of this, I got the expected success message:

$ terraform plan --target=module.vault
...
Plan: 126 to add, 0 to change, 0 to destroy.

But having not applied these changes, it's possible there are other issues resulting from the hacking described above.

The other issue with this is that having aggressively modified my local .terraform to get this to work, I'm not sure how to share this with others. However, that's only going to matter if Vault works for us so I figure for now it's good enough to cross that bridge when we come to it.

Hopefully this helps other folks make some progress.

I am using terraform 0.12.X version and while using the replace function(replace(var.filepath,"","/")) getting the error-
Error: Invalid multi-line string

on linuxvm.tf line 103, in resource "null_resource" "copy-file":
103:
104:

Quoted strings may not be split over multiple lines. To produce a multi-line
string, either use the \n escape to represent a newline character or use the
"heredoc" multi-line template syntax.

Hi, was this ever resolved? I'm using Terraform v0.12.25 and when I try to set up autoscaling in TF, I get this error on one of the lines:

Error: Invalid multi-line string

on main.tf line 83, in resource "google_compute_instance_template" "foobar":
83:

Quoted strings may not be split over multiple lines. To produce a multi-line
string, either use the \n escape to represent a newline character or use the
"heredoc" multi-line template syntax.

Someone did a global replace on a variable in the outputs.tf
${var.download_certs ?
Needs closing bracket
${var.download_certs}
Unfortunately it's in all the sub modules too.

2023 and the guide is still unusable 😞
I'd love to contribute, but it looks like a deeper issue that's spanning multiple referenced modules, so even 0.12upgrade doesn't go through