Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

aws_ecr_lifecycle_policy creation does not allow variable assignment to countNumber parameter #3002

Closed
proj4spes opened this issue Jan 16, 2018 · 5 comments
Labels
service/ecr Issues and PRs that pertain to the ecr service.

Comments

@proj4spes
Copy link

proj4spes commented Jan 16, 2018

aws_ecr_lifecycle_policy does not allow variable assignment to countNumber parameter.

here it is the code

variable "number" {
description = "a number"
default = 10
}
resource "aws_ecr_repository" "foo" {
name = "bar"
}

resource "aws_ecr_lifecycle_policy" "foopolicy" {
repository = "${aws_ecr_repository.foo.name}"

policy = <<EOF
{
"rules": [
{
"rulePriority": 1,
"description": "Expire images older than 14 days",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": "${var.number}"
},
"action": {
"type": "expire"
}
}
]
}
EOF
}
THIS is THE RESULT
1 error(s) occurred:

  • aws_ecr_lifecycle_policy.foopolicy: 1 error(s) occurred:

  • aws_ecr_lifecycle_policy.foopolicy: InvalidParameterException: Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: 'Lifecycle policy valiation failure: instance type (string) does not match any allowed primitive type (allowed: ["integer"])
    '
    status code: 400, request id: 5042a1bc-fa93-11e7-b3cc-c9977d1470fa

and here there is the trace showing that CountNumber is treated as a string

policy: "" => "{\n "rules": [\n {\n "rulePriority": 1,\n "description": "Expire images older than 14 days",\n "selection": {\n "tagStatus": "untagged",\n "countType": "sinceImagePushed",\n "countUnit": "days",\n "countNumber": "10"\n },\n "action": {\n "type": "expire"\n }\n }\n ]\n}\n"
registry_id: "" => ""
repository: "" => "bar"

@bflad
Copy link
Contributor

bflad commented Jan 16, 2018

Hi @proj4spes! Does it work if you modify your policy to be (note removal of quotes):

"countNumber": ${var.number}

@bflad bflad added waiting-response Maintainers are waiting on response from community or contributor. service/ecr Issues and PRs that pertain to the ecr service. labels Jan 16, 2018
@proj4spes
Copy link
Author

Thanks , anyway I believed that "$t..." were the only way to interpolate and the string to int would be automatically done ...(as in other cases ..) OK it runs as it would,,

@bflad
Copy link
Contributor

bflad commented Jan 19, 2018

The lines between the <<EOF and EOF used here is the heredoc notation inside Terraform's configuration language and automatically interpolates variables. This is similar behavior to the heredoc notation in Bash shell scripts or Ruby. Think of it like "s being around the whole lines (so anything inside interpolates) and without requiring escaping for any quotes inside (for readability).

We can likely improve the documentation here a little bit to explain this better in: https://www.terraform.io/docs/configuration/syntax.html

@bflad
Copy link
Contributor

bflad commented May 31, 2018

Closing as this appears to be resolved.

@bflad bflad closed this as completed May 31, 2018
@ghost
Copy link

ghost commented Apr 5, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 5, 2020
@breathingdust breathingdust removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/ecr Issues and PRs that pertain to the ecr service.
Projects
None yet
Development

No branches or pull requests

3 participants