I am getting an unexpected error using !terraform....
# atmos
d
I am getting an unexpected error using !terraform.state and !terraform.output. I am trying to gather ARNs from a set or ECR repositories to add them to a policy allowing a CI/CD user to push images. I cannot find a syntax that works. Here is the original attempt (with names redacted/changed to protect the innocent):
Copy code
import:
  - ./_defaults
  - path: catalog/ecr-deployer-role
    context:
      ecr_repository_arns:
        - !terraform.state image1-ecr global repository_arn
        - !terraform.state image2-ecr global repository_arn
      git_repository: bogus_repo_name
when atmos processes this file, I get: "invalid number of arguments in the Atmos YAML function !terraform.state image1- ecr global repository_arn !terraform.state image2-ecr global repository_arn"
I have tried replacing the list with JSON format:
Copy code
ecr_repository_arns: [
  "!terraform.state image1-ecr global repository_arn",
  "!terraform.state image2-ecr global repository_arn"
]
the same error occurs
I feel this has something to do with the processor that parses the
!
command/object. There needs to be some delimiter to identify the end of the arguments it should process or something. I have not found a canonical YAML syntax for doing this
I've cracked open code and am seeing
processTagTerraformState
in
atmos/internal/exec/yaml_func_terraform_state.go
. It is processing the !terraform.state tag and its arguments. If my suspicion is correct, then this call to getStringAfterTag could be overgenerating inputs to the !terraform.state function. I don't know the contract to the methods i'm looking at - this is just a hunch.
e
@Andriy Knysh (Cloud Posse)
this looks right to me.
Copy code
- path: catalog/ecr-deployer-role
    context:
      ecr_repository_arns:
        - !terraform.state image1-ecr global repository_arn
        - !terraform.state image2-ecr global repository_arn
this should not work:
Copy code
ecr_repository_arns: [
  "!terraform.state image1-ecr global repository_arn",
  "!terraform.state image2-ecr global repository_arn"
]
"!<something>" is a directive to the YAML parser
putting it in quotes should neuter the directive 😃
d
Well, then there may be are two bugs 😄 1. the first example does not work 2. the second example attempts to process the directive
i get the same error message in both instances
in either case, once I put a
!terraform.state
directive in an item in a list, all remaining items in the list are included mistakenly as arguments to the directive. It is as though the
\n
is not considered a valid separator and the directive is not terminating at the correct number of arguments.
I am working around this for now. I will try to come up with a simple test case. but am under the gun to deliver infrastructure at the moment
a
@Duffy Gillman thanks for reporting this. There’s probably a bug detecting the yaml tags inside a list. We’ll review it, update and add tests
🙌 1
d
thanks, @Andriy Knysh (Cloud Posse)
e
Duffy could I bother you to create the issue with logs. I will task this to get addressed, if there is indeed a bug
I was able to reproduce it by creating a test for it.
🙌 1
d
that's awesome, @Erik Osterman (Cloud Posse). Let me know if you still need me to chime in or add a ticket