Skip to content

Commit

Permalink
Merge pull request #11057 from theophilechevalier/batch-launch-templa…
Browse files Browse the repository at this point in the history
…te-force-new-resources

Recreate batch_compute_environment when updating launch_template
  • Loading branch information
gdavison authored Nov 28, 2019
2 parents 4f8e0b0 + 641c04e commit f5fb1f2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aws/resource_aws_batch_compute_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down
61 changes: 61 additions & 0 deletions aws/resource_aws_batch_compute_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
}

0 comments on commit f5fb1f2

Please sign in to comment.