From 641c04e441d47f6a4d884db8c49fdc9afdfd58b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Chevalier?= Date: Thu, 28 Nov 2019 17:10:28 +0100 Subject: [PATCH] Recreate batch_compute_environment when updating launch_template Addresses #11012. Forces to recreate a new batch_compute_environment when the associated launch_template is updated. --- aws/resource_aws_batch_compute_environment.go | 3 + ...urce_aws_batch_compute_environment_test.go | 61 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/aws/resource_aws_batch_compute_environment.go b/aws/resource_aws_batch_compute_environment.go index 8b70cce76de3..f7cae2d6b194 100644 --- a/aws/resource_aws_batch_compute_environment.go +++ b/aws/resource_aws_batch_compute_environment.go @@ -75,15 +75,18 @@ func resourceAwsBatchComputeEnvironment() *schema.Resource { Type: schema.TypeString, Optional: true, ConflictsWith: []string{"compute_resources.0.launch_template.0.launch_template_name"}, + ForceNew: true, }, "launch_template_name": { Type: schema.TypeString, Optional: true, ConflictsWith: []string{"compute_resources.0.launch_template.0.launch_template_id"}, + ForceNew: true, }, "version": { Type: schema.TypeString, Optional: true, + ForceNew: true, }, }, }, diff --git a/aws/resource_aws_batch_compute_environment_test.go b/aws/resource_aws_batch_compute_environment_test.go index 3a0c0a27d332..776227940580 100644 --- a/aws/resource_aws_batch_compute_environment_test.go +++ b/aws/resource_aws_batch_compute_environment_test.go @@ -276,6 +276,32 @@ func TestAccAWSBatchComputeEnvironment_launchTemplate(t *testing.T) { }) } +func TestAccAWSBatchComputeEnvironment_UpdateLaunchTemplate(t *testing.T) { + rInt := acctest.RandInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSBatch(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBatchComputeEnvironmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSBatchComputeEnvironmentUpdateLaunchTemplateInExistingComputeEnvironment(rInt, "$Default"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsBatchComputeEnvironmentExists(), + resource.TestCheckResourceAttr("aws_batch_compute_environment.ec2", "compute_resources.0.launch_template.0.version", "$Default"), + ), + }, + { + Config: testAccAWSBatchComputeEnvironmentUpdateLaunchTemplateInExistingComputeEnvironment(rInt, "$Latest"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsBatchComputeEnvironmentExists(), + resource.TestCheckResourceAttr("aws_batch_compute_environment.ec2", "compute_resources.0.launch_template.0.version", "$Latest"), + ), + }, + }, + }) +} + func TestAccAWSBatchComputeEnvironment_createSpotWithoutBidPercentage(t *testing.T) { rInt := acctest.RandInt() @@ -799,3 +825,38 @@ resource "aws_batch_compute_environment" "ec2" { } `, rInt, rInt) } + +func testAccAWSBatchComputeEnvironmentUpdateLaunchTemplateInExistingComputeEnvironment(rInt int, version string) string { + return testAccAWSBatchComputeEnvironmentConfigBase(rInt) + fmt.Sprintf(` +resource "aws_launch_template" "foo" { + name = "tf_acc_test_%d" +} + +resource "aws_batch_compute_environment" "ec2" { + compute_environment_name = "tf_acc_test_%d" + compute_resources { + instance_role = "${aws_iam_instance_profile.ecs_instance_role.arn}" + instance_type = [ + "c4.large", + ] + launch_template { + launch_template_name = "${aws_launch_template.foo.name}" + version = "%s" + } + max_vcpus = 16 + min_vcpus = 0 + security_group_ids = [ + "${aws_security_group.test_acc.id}" + ] + spot_iam_fleet_role = "${aws_iam_role.aws_ec2_spot_fleet_role.arn}" + subnets = [ + "${aws_subnet.test_acc.id}" + ] + type = "SPOT" + } + service_role = "${aws_iam_role.aws_batch_service_role.arn}" + type = "MANAGED" + depends_on = ["aws_iam_role_policy_attachment.aws_batch_service_role"] +} +`, rInt, rInt, version) +}