aws_batch_job_definition reosurce is always shows destory/create without any changes to this resource. This was also preiously reported #11998 and fixed in #12000
terraform --version
Terraform v0.12.26
+ provider.aws v2.65.0
terraform {
backend "local" {
path = ".terraform/state/terraform.tfstate"
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_iam_role" "role" {
name = "role-test"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
}
}
]
}
EOF
}
resource "aws_ecr_repository" "ecr" {
name = "my-app"
}
resource "aws_batch_job_definition" "batch-job-definition" {
name = "test-job-definition"
type = "container"
container_properties = <<CONTAINER_PROPERTIES
{
"image": "${aws_ecr_repository.ecr.name}:image",
"memory": 4096,
"vcpus": 1,
"jobRoleArn": "${aws_iam_role.role.arn}"
"environment": [
{
"name": "ENVIRONMENT",
"value": "test"
}
]
}
CONTAINER_PROPERTIES
}
https://gist.github.com/RishikeshDarandale/5f183623e095905ecd8af50c5b211d12
Resource should not be always recreated.
Resource is always recreated.
terraform initterraform applyterraform plan@RishikeshDarandale Thanks for raising this.
I can reproduce this problem with an internal unit test:
$ go test ./aws/internal/service/batch/equivalency
2020/06/05 10:51:15 [DEBUG] Canonical Batch Container Properties JSON are not equal.
First: {"environment":[{"name":"ENVIRONMENT","value":"test"}],"image":"123.dkr.ecr.us-east-1.amazonaws.com/my-app","jobRoleArn":"arn:aws:iam::123:role/role-test","memory":4096,"vcpus":1}
Second: {"command":[],"environment":[{"name":"ENVIRONMENT","value":"test"}],"image":"123.dkr.ecr.us-east-1.amazonaws.com/my-app","jobRoleArn":"arn:aws:iam::123:role/role-test","memory":4096,"vcpus":1}
--- FAIL: TestEquivalentBatchContainerPropertiesJSON (0.00s)
--- FAIL: TestEquivalentBatchContainerPropertiesJSON/empty_command,_mountPoints,_resourceRequirements,_ulimits,_volumes (0.00s)
container_properties_test.go:258: got false, expected true
FAIL
FAIL github.com/terraform-providers/terraform-provider-aws/aws/internal/service/batch/equivalency 0.005s
FAIL
https://github.com/terraform-providers/terraform-provider-aws/pull/13634 has been submitted to address this.
The above fix for this has been merged and will release with version 2.66.0 of the Terraform AWS Provider, later next week. 👍
Thanks @ewbankkit for quick resolution.
Is it the problem with only command property? What about the others like volumes, etc?
@RishikeshDarandale We were already correctly handling the other array attributes (volumes etc.) when they were empty.
This has been released in version 2.66.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.
For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!
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!
Most helpful comment
The above fix for this has been merged and will release with version 2.66.0 of the Terraform AWS Provider, later next week. 👍