hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.82k stars 9.17k forks source link

[Bug]: aws_batch_job_queue - Inconsistent results after apply #33376

Closed olivia-dataskeptics closed 1 year ago

olivia-dataskeptics commented 1 year ago

Terraform Core Version

1.5.7

AWS Provider Version

2.7.9, 5.16.0

Affected Resource(s)

aws_batch_job_queue

Expected Behavior

Terraform apply should complete.

Actual Behavior

Provider produced inconsistent results after apply.

Relevant Error/Panic Output Snippet

│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to aws_batch_job_queue.simple_flask_app_job_queue, provider
│ "provider[\"registry.terraform.io/hashicorp/aws\"]" produced an unexpected new value:
│ .compute_environments[0]: was cty.StringVal("flask-app-compute-env"), but now
│ cty.StringVal("arn:aws:batch:us-west-2:<id>:compute-environment/flask-app-compute-env").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Terraform Configuration Files

provider "aws" {
  region = "us-west-2"
  profile="terraform-profile"
}

resource "aws_vpc" "simple_flask_app_vpc" {
  cidr_block = "10.0.0.0/16"
  enable_dns_support = true
  enable_dns_hostnames = true
  tags = {
    Name = "flask-app-vpc"
  }
}

resource "aws_subnet" "simple_flask_app_subnet" {
  count = 1
  vpc_id = aws_vpc.simple_flask_app_vpc.id
  cidr_block = "10.0.1.0/24"
  availability_zone = "us-west-2a"
  map_public_ip_on_launch = true
  tags = {
    Name = "flask-app-1"
  }
}

resource "aws_security_group" "simple_flask_app_sg" {
  name_prefix = "flask-app-sg"
  vpc_id = aws_vpc.simple_flask_app_vpc.id

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"] # Allow traffic from any IP address (Internet)
  }

  ingress {
    from_port   = 4000
    to_port     = 4000
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"] # Allow traffic from any IP address (Internet)
  }
}

resource "aws_ecs_task_definition" "simple_flask_app_task" {
  family                   = "flask-app-task"
  network_mode             = "awsvpc"
  requires_compatibilities = ["EC2"]
  execution_role_arn        = aws_iam_role.simple_flask_app_iam.arn

  container_definitions = jsonencode([
    {
      memory = 512
      cpu = 10
      name  = "flask-app-container"
      image = "<account-id>.dkr.ecr.us-west-2.amazonaws.com/simple-flask-app:latest" # TODO: Update here
      portMappings = [
        {
          containerPort = 80
          hostPort      = 80
        }
      ]
    }
  ])
}

resource "aws_iam_role" "simple_flask_app_iam" {
  name = "flask-app-iam"

  assume_role_policy = jsonencode({
    Version = "2012-10-17",
    Statement = [
      {
        "Action": "sts:AssumeRole"
        "Effect": "Allow",
        "Principal": {
            "Service": ["ecs-tasks.amazonaws.com", "batch.amazonaws.com"]
        },
      }
    ]
  })
}

resource "aws_iam_instance_profile" "simple_flask_app_instance_profile" {
  name = "flask-app-instance-profile"
  role = aws_iam_role.simple_flask_app_iam.name
}

resource "aws_batch_compute_environment" "simple_flask_app_batch_env" {
  compute_environment_name = "flask-app-compute-env"
  lifecycle {
    create_before_destroy = true
  }
  compute_resources {
    instance_role = aws_iam_instance_profile.simple_flask_app_instance_profile.arn
    instance_type = ["m3.large"]
    min_vcpus    = 0
    desired_vcpus = 2
    max_vcpus    = 64
    subnets      = aws_subnet.simple_flask_app_subnet[*].id
    security_group_ids = [aws_security_group.simple_flask_app_sg.id]
    type = "EC2"
  }
  service_role = aws_iam_role.simple_flask_app_iam.arn
  type         = "MANAGED"
}

resource "aws_batch_job_queue" "simple_flask_app_job_queue" {
  name = "flask-app-job-queue"
  priority = 1
  compute_environments = [aws_batch_compute_environment.simple_flask_app_batch_env.compute_environment_name]
  state = "ENABLED"
}

resource "aws_batch_job_definition" "simple_flask_app_job_definition" {
  name = "flask-app-job-definition"
  type = "container"

  container_properties = jsonencode({
    image       = aws_ecs_task_definition.simple_flask_app_task.family
    resourceRequirements = [
          { type = "VCPU", value = "1" },
          { type = "MEMORY", value = "1024" }
        ]
    command     = []
  })
}

Steps to Reproduce

  1. terraform init
  2. terraform plan
  3. terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

github-actions[bot] commented 1 year ago

This functionality has been released in v5.19.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. Thank you!

github-actions[bot] commented 1 year ago

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.