Skip to content

Commit 9f2eb75

Browse files
DrFaust92adamdecaf
authored andcommitted
resource/aws_launch_template: Prevent downstream resource errors with unconfigured partition numbers (hashicorp#13239)
Output from acceptance testing: ``` --- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups (171.95s) --- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity (285.70s) --- PASS: TestAccAWSAutoScalingGroup_autoGeneratedName (118.21s) --- PASS: TestAccAWSAutoScalingGroup_basic (289.54s) --- PASS: TestAccAWSAutoScalingGroup_classicVpcZoneIdentifier (126.69s) --- PASS: TestAccAWSAutoScalingGroup_emptyAvailabilityZones (78.93s) --- PASS: TestAccAWSAutoScalingGroup_enablingMetrics (236.84s) --- PASS: TestAccAWSAutoScalingGroup_initialLifecycleHook (254.46s) --- PASS: TestAccAWSAutoScalingGroup_launchTemplate (39.84s) --- PASS: TestAccAWSAutoScalingGroup_LaunchTemplate_IAMInstanceProfile (63.24s) --- PASS: TestAccAWSAutoScalingGroup_launchTemplate_update (196.20s) --- PASS: TestAccAWSAutoScalingGroup_launchTempPartitionNum (170.82s) --- PASS: TestAccAWSAutoScalingGroup_LoadBalancers (693.58s) --- PASS: TestAccAWSAutoScalingGroup_MaxInstanceLifetime (79.29s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy (49.05s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandAllocationStrategy (42.20s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandBaseCapacity (106.01s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandPercentageAboveBaseCapacity (51.32s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotAllocationStrategy (170.25s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotInstancePools (74.39s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotMaxPrice (49.26s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_LaunchTemplateName (48.53s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_Version (68.41s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_InstanceType (73.56s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_WeightedCapacity (142.65s) --- PASS: TestAccAWSAutoScalingGroup_namePrefix (47.08s) --- PASS: TestAccAWSAutoScalingGroup_serviceLinkedRoleARN (76.81s) --- PASS: TestAccAWSAutoScalingGroup_suspendingProcesses (237.62s) --- PASS: TestAccAWSAutoScalingGroup_tags (199.87s) --- PASS: TestAccAWSAutoScalingGroup_TargetGroupArns (341.68s) --- PASS: TestAccAWSAutoScalingGroup_terminationPolicies (114.77s) --- PASS: TestAccAWSAutoScalingGroup_VpcUpdates (78.67s) --- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer (642.03s) --- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup (320.77s) --- PASS: TestAccAWSAutoScalingGroup_withMetrics (70.40s) --- PASS: TestAccAWSAutoScalingGroup_withPlacementGroup (166.42s) --- PASS: TestAccAWSLaunchTemplate_associatePublicIPAddress (26.93s) --- PASS: TestAccAWSLaunchTemplate_basic (7.90s) --- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS (43.93s) --- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_DeleteOnTermination (70.32s) --- PASS: TestAccAWSLaunchTemplate_capacityReservation_preference (8.37s) --- PASS: TestAccAWSLaunchTemplate_capacityReservation_target (10.16s) --- PASS: TestAccAWSLaunchTemplate_cpuOptions (7.90s) --- PASS: TestAccAWSLaunchTemplate_creditSpecification_nonBurstable (8.79s) --- PASS: TestAccAWSLaunchTemplate_creditSpecification_t2 (8.45s) --- PASS: TestAccAWSLaunchTemplate_creditSpecification_t3 (8.57s) --- PASS: TestAccAWSLaunchTemplate_data (8.40s) --- PASS: TestAccAWSLaunchTemplate_description (13.69s) --- PASS: TestAccAWSLaunchTemplate_disappears (6.42s) --- PASS: TestAccAWSLaunchTemplate_EbsOptimized (30.29s) --- PASS: TestAccAWSLaunchTemplate_ElasticInferenceAccelerator (13.65s) --- PASS: TestAccAWSLaunchTemplate_hibernation (18.80s) --- PASS: TestAccAWSLaunchTemplate_IamInstanceProfile_EmptyConfigurationBlock (7.20s) --- PASS: TestAccAWSLaunchTemplate_instanceMarketOptions (51.48s) --- PASS: TestAccAWSLaunchTemplate_licenseSpecification (8.73s) --- PASS: TestAccAWSLaunchTemplate_metadataOptions (8.15s) --- PASS: TestAccAWSLaunchTemplate_networkInterface (12.63s) --- PASS: TestAccAWSLaunchTemplate_networkInterface_ipv6AddressCount (8.55s) --- PASS: TestAccAWSLaunchTemplate_networkInterface_ipv6Addresses (9.18s) --- PASS: TestAccAWSLaunchTemplate_networkInterfaceAddresses (12.71s) --- PASS: TestAccAWSLaunchTemplate_placement_partitionNum (14.94s) --- PASS: TestAccAWSLaunchTemplate_tags (13.82s) --- PASS: TestAccAWSLaunchTemplate_update (47.24s) --- PASS: TestAccAWSLaunchTemplateDataSource_associatePublicIPAddress (26.16s) --- PASS: TestAccAWSLaunchTemplateDataSource_basic (13.70s) --- PASS: TestAccAWSLaunchTemplateDataSource_filter_basic (13.86s) --- PASS: TestAccAWSLaunchTemplateDataSource_filter_tags (13.62s) --- PASS: TestAccAWSLaunchTemplateDataSource_metadataOptions (13.55s) ```
1 parent e488bec commit 9f2eb75

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

aws/resource_aws_autoscaling_group_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,41 @@ func TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_Wei
20612061
})
20622062
}
20632063

2064+
func TestAccAWSAutoScalingGroup_launchTempPartitionNum(t *testing.T) {
2065+
var group autoscaling.Group
2066+
2067+
randName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
2068+
2069+
resource.ParallelTest(t, resource.TestCase{
2070+
PreCheck: func() { testAccPreCheck(t) },
2071+
Providers: testAccProviders,
2072+
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
2073+
DisableBinaryDriver: true,
2074+
Steps: []resource.TestStep{
2075+
{
2076+
Config: testAccAWSAutoScalingGroupPartitionConfig(randName),
2077+
Check: resource.ComposeTestCheckFunc(
2078+
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.test", &group),
2079+
),
2080+
},
2081+
{
2082+
ResourceName: "aws_autoscaling_group.test",
2083+
ImportState: true,
2084+
ImportStateVerify: true,
2085+
ImportStateVerifyIgnore: []string{
2086+
"force_delete",
2087+
"initial_lifecycle_hook",
2088+
"name_prefix",
2089+
"tag",
2090+
"tags",
2091+
"wait_for_capacity_timeout",
2092+
"wait_for_elb_capacity",
2093+
},
2094+
},
2095+
},
2096+
})
2097+
}
2098+
20642099
const testAccAWSAutoScalingGroupConfig_autoGeneratedName = `
20652100
data "aws_ami" "test_ami" {
20662101
most_recent = true
@@ -4035,3 +4070,56 @@ resource "aws_autoscaling_group" "test" {
40354070
}
40364071
`, rName)
40374072
}
4073+
4074+
func testAccAWSAutoScalingGroupPartitionConfig(rName string) string {
4075+
return fmt.Sprintf(`
4076+
data "aws_availability_zones" "available" {
4077+
# t2.micro is not supported in us-west-2d
4078+
blacklisted_zone_ids = ["usw2-az4"]
4079+
state = "available"
4080+
4081+
filter {
4082+
name = "opt-in-status"
4083+
values = ["opt-in-not-required"]
4084+
}
4085+
}
4086+
4087+
data "aws_ami" "test_ami" {
4088+
most_recent = true
4089+
owners = ["amazon"]
4090+
4091+
filter {
4092+
name = "name"
4093+
values = ["amzn-ami-hvm-*-x86_64-gp2"]
4094+
}
4095+
}
4096+
4097+
resource "aws_launch_template" "this" {
4098+
name = %[1]q
4099+
image_id = data.aws_ami.test_ami.id
4100+
instance_type = "m5.large"
4101+
4102+
placement {
4103+
tenancy = "default"
4104+
group_name = aws_placement_group.test.id
4105+
}
4106+
}
4107+
4108+
resource "aws_placement_group" "test" {
4109+
name = %[1]q
4110+
strategy = "cluster"
4111+
}
4112+
4113+
resource "aws_autoscaling_group" "test" {
4114+
name_prefix = "test"
4115+
availability_zones = ["${data.aws_availability_zones.available.names[0]}"]
4116+
min_size = 0
4117+
max_size = 0
4118+
4119+
launch_template {
4120+
id = aws_launch_template.this.id
4121+
version = "$Latest"
4122+
}
4123+
}
4124+
`, rName)
4125+
}

aws/resource_aws_launch_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ func readPlacementFromConfig(p map[string]interface{}) *ec2.LaunchTemplatePlacem
17061706
placement.Tenancy = aws.String(v)
17071707
}
17081708

1709-
if v, ok := p["partition_number"].(int); ok {
1709+
if v, ok := p["partition_number"].(int); ok && v != 0 {
17101710
placement.PartitionNumber = aws.Int64(int64(v))
17111711
}
17121712

0 commit comments

Comments
 (0)