@@ -1609,6 +1609,46 @@ func TestAccBatchComputeEnvironment_updateLaunchTemplate(t *testing.T) {
1609
1609
})
1610
1610
}
1611
1611
1612
+ // https://github.com/hashicorp/terraform-provider-aws/issues/39470.
1613
+ func TestAccBatchComputeEnvironment_updateLaunchTemplateID (t * testing.T ) {
1614
+ ctx := acctest .Context (t )
1615
+ var ce awstypes.ComputeEnvironmentDetail
1616
+ rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
1617
+ resourceName := "aws_batch_compute_environment.test"
1618
+
1619
+ resource .ParallelTest (t , resource.TestCase {
1620
+ PreCheck : func () { acctest .PreCheck (ctx , t ); testAccPreCheck (ctx , t ) },
1621
+ ErrorCheck : acctest .ErrorCheck (t , names .BatchServiceID ),
1622
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
1623
+ CheckDestroy : testAccCheckComputeEnvironmentDestroy (ctx ),
1624
+ Steps : []resource.TestStep {
1625
+ {
1626
+ Config : testAccComputeEnvironmentConfig_launchTemplateWithVersion (rName , "foo" ),
1627
+ Check : resource .ComposeAggregateTestCheckFunc (
1628
+ testAccCheckComputeEnvironmentExists (ctx , resourceName , & ce ),
1629
+ ),
1630
+ ConfigPlanChecks : resource.ConfigPlanChecks {
1631
+ PreApply : []plancheck.PlanCheck {
1632
+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionCreate ),
1633
+ },
1634
+ },
1635
+ },
1636
+ // Swap to version 2 of the launch template
1637
+ {
1638
+ Config : testAccComputeEnvironmentConfig_launchTemplateWithVersion (rName , "bar" ),
1639
+ Check : resource .ComposeAggregateTestCheckFunc (
1640
+ testAccCheckComputeEnvironmentExists (ctx , resourceName , & ce ),
1641
+ ),
1642
+ ConfigPlanChecks : resource.ConfigPlanChecks {
1643
+ PreApply : []plancheck.PlanCheck {
1644
+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionReplace ),
1645
+ },
1646
+ },
1647
+ },
1648
+ },
1649
+ })
1650
+ }
1651
+
1612
1652
func TestAccBatchComputeEnvironment_UpdateSecurityGroupsAndSubnets_fargate (t * testing.T ) {
1613
1653
ctx := acctest .Context (t )
1614
1654
var ce awstypes.ComputeEnvironmentDetail
@@ -2999,6 +3039,65 @@ resource "aws_batch_compute_environment" "test" {
2999
3039
` , rName , version ))
3000
3040
}
3001
3041
3042
+ func testAccComputeEnvironmentConfig_launchTemplateWithVersion (rName , userDataSeed string ) string {
3043
+ return acctest .ConfigCompose (testAccComputeEnvironmentConfig_base (rName ), fmt .Sprintf (`
3044
+ locals {
3045
+ user_data = <<-EOF
3046
+ Content-Type: multipart/mixed; boundary="//"
3047
+ MIME-Version: 1.0
3048
+
3049
+ --//
3050
+ Content-Type: text/x-shellscript; charset="us-ascii"
3051
+ MIME-Version: 1.0
3052
+ Content-Transfer-Encoding: 7bit
3053
+ Content-Disposition: attachment; filename="userdata.txt"
3054
+
3055
+ #!/bin/bash
3056
+ echo hello
3057
+ echo %[2]q
3058
+ --//--
3059
+ EOF
3060
+ }
3061
+
3062
+ resource "aws_launch_template" "test" {
3063
+ name = %[1]q
3064
+ user_data = base64encode(local.user_data)
3065
+ }
3066
+
3067
+ resource "aws_batch_compute_environment" "test" {
3068
+ name = %[1]q
3069
+
3070
+ compute_resources {
3071
+ allocation_strategy = "SPOT_PRICE_CAPACITY_OPTIMIZED"
3072
+ instance_role = aws_iam_instance_profile.ecs_instance.arn
3073
+ instance_type = [
3074
+ "c4.large",
3075
+ ]
3076
+
3077
+ launch_template {
3078
+ launch_template_id = aws_launch_template.test.id
3079
+ version = aws_launch_template.test.latest_version
3080
+ }
3081
+
3082
+ max_vcpus = 16
3083
+ min_vcpus = 0
3084
+ security_group_ids = [
3085
+ aws_security_group.test.id
3086
+ ]
3087
+ spot_iam_fleet_role = aws_iam_role.ec2_spot_fleet.arn
3088
+ subnets = [
3089
+ aws_subnet.test.id
3090
+ ]
3091
+ type = "SPOT"
3092
+ }
3093
+
3094
+ service_role = aws_iam_role.batch_service.arn
3095
+ type = "MANAGED"
3096
+ depends_on = [aws_iam_role_policy_attachment.batch_service]
3097
+ }
3098
+ ` , rName , userDataSeed ))
3099
+ }
3100
+
3002
3101
func testAccComputeEnvironmentConfig_ec2Configuration (rName string ) string {
3003
3102
return acctest .ConfigCompose (testAccComputeEnvironmentConfig_base (rName ), acctest .ConfigLatestAmazonLinux2HVMEBSX8664AMI (), fmt .Sprintf (`
3004
3103
resource "aws_batch_compute_environment" "test" {
0 commit comments