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

name prefix request to aws_batch_compute_environment #3207

Closed
limitusus opened this issue Jan 31, 2018 · 8 comments · Fixed by #10682
Closed

name prefix request to aws_batch_compute_environment #3207

limitusus opened this issue Jan 31, 2018 · 8 comments · Fixed by #10682
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/batch Issues and PRs that pertain to the batch service.
Milestone

Comments

@limitusus
Copy link

Terraform Version

Terraform v0.11.2

Affected Resource(s)

  • aws_batch_compute_environment

Terraform Configuration Files

resource "aws_batch_compute_environment" "env1" {
  compute_environment_name = "env1"

  compute_resources {
    instance_role = "arn:aws:iam::XXXXXXXXXXXX:instance-profile/aws-batch-instance-role-policy"

    instance_type = [
      "optimal",
    ]

    max_vcpus     = 16
    min_vcpus     = 0
    desired_vcpus = 2

    subnets = [
      "${aws_subnet.main.id}",
    ]

    type     = "EC2"
    image_id = "${data.aws_ami.ecs_optimized.image_id}"

    security_group_ids = [
      "${aws_default_security_group.default.id}",
    ]

    ec2_key_pair = "my-key"
  }

  service_role = "arn:aws:iam::XXXXXXXXXXXX:role/service-role/aws-batch-service-role"
  type         = "MANAGED"

  lifecycle {
    create_before_destroy = true
  }
}

data "aws_ami" "ecs_optimized" {
  most_recent = true
  owners      = ["amazon"]

  filter = {
    name   = "name"
    values = ["amzn-ami-*.*.*-amazon-ecs-optimized"]
  }
}

Debug Output

Expected Behavior

I'm using ECS-optimized AMI provided by Amazon, which is sometimes updated.
Then I defined data.aws_ami.ecs_optmized for track the AMI update automatically.

I expect terraform to create new compute environment with the new AMI with new environment name, and then delete the existing compute environment with the old AMI.

Actual Behavior

Terraform fails to create new compute environment with the following error, because it tries to create a new environment with the same name.

* aws_batch_compute_environment.env1: 1 error(s) occurred:

* aws_batch_compute_environment.env1: : Object already exists
	status code: 409, request id: edc9b72d-0645-11e8-a353-cf4b5406a3a1

I expect HCL can define compute environments' prefix, like name_prefix in aws_launch_configuration.
With such feature we can switch to a new compute environment by automating create (new environment), update (job queue), and delete (old environment) to update AMI.

Steps to Reproduce

  1. terraform apply
@radeksimko radeksimko added service/batch Issues and PRs that pertain to the batch service. enhancement Requests to existing resources that expand the functionality or scope. labels Jan 31, 2018
@conzy
Copy link

conzy commented Jun 14, 2018

Here is a "fix" I have been using to simulate the name_prefix functionality. You can use the random resource to create stateful randomness. When you want to create a new compute environment you can just fiddle the random_string length which will cleanly create the new resources then delete the old resource.

resource "random_string" "name" {
  length  = 16
  special = false
  upper   = false
}
resource "aws_batch_compute_environment" "this" {
  compute_environment_name = "${var.name}-${random_string.name.result}"
  # removed for brevity

  lifecycle {
    create_before_destroy = true
  }
}

@lightjacket
Copy link

Going to try and make a pull request to add a compute_environment_name_prefix field. My apologies if I just missed it, but is there a slack org or some sort of forum for this plugin? Was having some trouble running a subset of the tests and figured asking for help would be faster than digging in too far.

@endemics
Copy link

My apologies if I just missed it, but is there a slack org or some sort of forum for this plugin? Was having some trouble running a subset of the tests and figured asking for help would be faster than digging in too far.

Not specific to the terraform provider but have you tried https://gitter.im/hashicorp-terraform/Lobby ?

@rajbettaswamy
Copy link

rajbettaswamy commented Nov 8, 2018

Adding a random_string does fix the issue but it works only once, as the random resource is created only once. So, I usually change the length of the random_string in the next iteration, so that it creates a new prefix for compute_environment_name in every TF runs.

But when you use Terraform in CI/CD pipeline, it becomes increasingly difficult to maintain this. Hence, looking forward for name_prefix implementation (just like in ASG).

@andycui66
Copy link
Contributor

Add keepers to your random_string force a change on every run.

resource "random_string" "random" {
  length = 8
  special = false
  upper = false

  keepers = {
    time = "${timestamp()}"
  }
}

This is not ideal since it forces a recreate when you apply even nothing is changed on your compute environment.

@bflad
Copy link
Contributor

bflad commented Jan 3, 2020

Support for a new compute_environment_name_prefix argument or completely omitting the name has been merged and will release with version 2.44.0 of the Terraform AWS Provider, Thursday next week. Thanks to @marcinwyszynski for the implementation. 👍

@ghost
Copy link

ghost commented Jan 10, 2020

This has been released in version 2.44.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!

@ghost
Copy link

ghost commented Mar 27, 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 Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/batch Issues and PRs that pertain to the batch service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants