Skip to content

Commit

Permalink
r/aws_launch_template: Tidy up expanders.
Browse files Browse the repository at this point in the history
Acceptance test output:

% make testacc TESTARGS='-run=TestAccEC2LaunchTemplate_' PKG=ec2 ACCTEST_PARALLELISM=3
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 3  -run=TestAccEC2LaunchTemplate_ -timeout 180m
=== RUN   TestAccEC2LaunchTemplate_basic
=== PAUSE TestAccEC2LaunchTemplate_basic
=== RUN   TestAccEC2LaunchTemplate_Name_generated
=== PAUSE TestAccEC2LaunchTemplate_Name_generated
=== RUN   TestAccEC2LaunchTemplate_Name_prefix
=== PAUSE TestAccEC2LaunchTemplate_Name_prefix
=== RUN   TestAccEC2LaunchTemplate_disappears
=== PAUSE TestAccEC2LaunchTemplate_disappears
=== RUN   TestAccEC2LaunchTemplate_BlockDeviceMappings_ebs
=== PAUSE TestAccEC2LaunchTemplate_BlockDeviceMappings_ebs
=== RUN   TestAccEC2LaunchTemplate_BlockDeviceMappingsEBS_deleteOnTermination
=== PAUSE TestAccEC2LaunchTemplate_BlockDeviceMappingsEBS_deleteOnTermination
=== RUN   TestAccEC2LaunchTemplate_BlockDeviceMappingsEBS_gp3
=== PAUSE TestAccEC2LaunchTemplate_BlockDeviceMappingsEBS_gp3
=== RUN   TestAccEC2LaunchTemplate_ebsOptimized
=== PAUSE TestAccEC2LaunchTemplate_ebsOptimized
=== RUN   TestAccEC2LaunchTemplate_elasticInferenceAccelerator
=== PAUSE TestAccEC2LaunchTemplate_elasticInferenceAccelerator
=== RUN   TestAccEC2LaunchTemplate_NetworkInterfaces_deleteOnTermination
=== PAUSE TestAccEC2LaunchTemplate_NetworkInterfaces_deleteOnTermination
=== RUN   TestAccEC2LaunchTemplate_data
=== PAUSE TestAccEC2LaunchTemplate_data
=== RUN   TestAccEC2LaunchTemplate_description
=== PAUSE TestAccEC2LaunchTemplate_description
=== RUN   TestAccEC2LaunchTemplate_update
=== PAUSE TestAccEC2LaunchTemplate_update
=== RUN   TestAccEC2LaunchTemplate_tags
=== PAUSE TestAccEC2LaunchTemplate_tags
=== RUN   TestAccEC2LaunchTemplate_CapacityReservation_preference
=== PAUSE TestAccEC2LaunchTemplate_CapacityReservation_preference
=== RUN   TestAccEC2LaunchTemplate_CapacityReservation_target
=== PAUSE TestAccEC2LaunchTemplate_CapacityReservation_target
=== RUN   TestAccEC2LaunchTemplate_cpuOptions
=== PAUSE TestAccEC2LaunchTemplate_cpuOptions
=== RUN   TestAccEC2LaunchTemplate_CreditSpecification_nonBurstable
=== PAUSE TestAccEC2LaunchTemplate_CreditSpecification_nonBurstable
=== RUN   TestAccEC2LaunchTemplate_CreditSpecification_t2
=== PAUSE TestAccEC2LaunchTemplate_CreditSpecification_t2
=== RUN   TestAccEC2LaunchTemplate_CreditSpecification_t3
=== PAUSE TestAccEC2LaunchTemplate_CreditSpecification_t3
=== RUN   TestAccEC2LaunchTemplate_IAMInstanceProfile_emptyBlock
=== PAUSE TestAccEC2LaunchTemplate_IAMInstanceProfile_emptyBlock
=== RUN   TestAccEC2LaunchTemplate_networkInterface
=== PAUSE TestAccEC2LaunchTemplate_networkInterface
=== RUN   TestAccEC2LaunchTemplate_networkInterfaceAddresses
=== PAUSE TestAccEC2LaunchTemplate_networkInterfaceAddresses
=== RUN   TestAccEC2LaunchTemplate_networkInterfaceType
=== PAUSE TestAccEC2LaunchTemplate_networkInterfaceType
=== RUN   TestAccEC2LaunchTemplate_networkInterfaceCardIndex
=== PAUSE TestAccEC2LaunchTemplate_networkInterfaceCardIndex
=== RUN   TestAccEC2LaunchTemplate_associatePublicIPAddress
=== PAUSE TestAccEC2LaunchTemplate_associatePublicIPAddress
=== RUN   TestAccEC2LaunchTemplate_associateCarrierIPAddress
=== PAUSE TestAccEC2LaunchTemplate_associateCarrierIPAddress
=== RUN   TestAccEC2LaunchTemplate_Placement_hostResourceGroupARN
=== PAUSE TestAccEC2LaunchTemplate_Placement_hostResourceGroupARN
=== RUN   TestAccEC2LaunchTemplate_Placement_partitionNum
=== PAUSE TestAccEC2LaunchTemplate_Placement_partitionNum
=== RUN   TestAccEC2LaunchTemplate_NetworkInterface_ipv6Addresses
=== PAUSE TestAccEC2LaunchTemplate_NetworkInterface_ipv6Addresses
=== RUN   TestAccEC2LaunchTemplate_NetworkInterface_ipv6AddressCount
=== PAUSE TestAccEC2LaunchTemplate_NetworkInterface_ipv6AddressCount
=== RUN   TestAccEC2LaunchTemplate_instanceMarketOptions
=== PAUSE TestAccEC2LaunchTemplate_instanceMarketOptions
=== RUN   TestAccEC2LaunchTemplate_licenseSpecification
=== PAUSE TestAccEC2LaunchTemplate_licenseSpecification
=== RUN   TestAccEC2LaunchTemplate_metadataOptions
=== PAUSE TestAccEC2LaunchTemplate_metadataOptions
=== RUN   TestAccEC2LaunchTemplate_enclaveOptions
=== PAUSE TestAccEC2LaunchTemplate_enclaveOptions
=== RUN   TestAccEC2LaunchTemplate_hibernation
=== PAUSE TestAccEC2LaunchTemplate_hibernation
=== RUN   TestAccEC2LaunchTemplate_defaultVersion
=== PAUSE TestAccEC2LaunchTemplate_defaultVersion
=== RUN   TestAccEC2LaunchTemplate_updateDefaultVersion
=== PAUSE TestAccEC2LaunchTemplate_updateDefaultVersion
=== CONT  TestAccEC2LaunchTemplate_basic
=== CONT  TestAccEC2LaunchTemplate_updateDefaultVersion
=== CONT  TestAccEC2LaunchTemplate_CreditSpecification_t3
--- PASS: TestAccEC2LaunchTemplate_basic (17.44s)
=== CONT  TestAccEC2LaunchTemplate_data
--- PASS: TestAccEC2LaunchTemplate_CreditSpecification_t3 (17.64s)
=== CONT  TestAccEC2LaunchTemplate_CreditSpecification_t2
--- PASS: TestAccEC2LaunchTemplate_CreditSpecification_t2 (14.68s)
=== CONT  TestAccEC2LaunchTemplate_CreditSpecification_nonBurstable
--- PASS: TestAccEC2LaunchTemplate_data (15.39s)
=== CONT  TestAccEC2LaunchTemplate_cpuOptions
--- PASS: TestAccEC2LaunchTemplate_cpuOptions (12.43s)
=== CONT  TestAccEC2LaunchTemplate_CapacityReservation_target
--- PASS: TestAccEC2LaunchTemplate_CreditSpecification_nonBurstable (15.37s)
=== CONT  TestAccEC2LaunchTemplate_CapacityReservation_preference
--- PASS: TestAccEC2LaunchTemplate_updateDefaultVersion (49.96s)
=== CONT  TestAccEC2LaunchTemplate_tags
--- PASS: TestAccEC2LaunchTemplate_CapacityReservation_preference (18.14s)
=== CONT  TestAccEC2LaunchTemplate_update
--- PASS: TestAccEC2LaunchTemplate_CapacityReservation_target (20.77s)
=== CONT  TestAccEC2LaunchTemplate_description
--- PASS: TestAccEC2LaunchTemplate_tags (41.01s)
=== CONT  TestAccEC2LaunchTemplate_Placement_partitionNum
--- PASS: TestAccEC2LaunchTemplate_description (26.64s)
=== CONT  TestAccEC2LaunchTemplate_defaultVersion
--- PASS: TestAccEC2LaunchTemplate_Placement_partitionNum (28.90s)
=== CONT  TestAccEC2LaunchTemplate_hibernation
--- PASS: TestAccEC2LaunchTemplate_defaultVersion (36.65s)
=== CONT  TestAccEC2LaunchTemplate_enclaveOptions
--- PASS: TestAccEC2LaunchTemplate_update (88.02s)
=== CONT  TestAccEC2LaunchTemplate_metadataOptions
--- PASS: TestAccEC2LaunchTemplate_hibernation (35.89s)
=== CONT  TestAccEC2LaunchTemplate_licenseSpecification
    acctest.go:1003: skipping test for aws/us-west-2: Error running apply: exit status 1

        Error: Error creating License Manager license configuration: ResourceLimitExceededException: You have reached the maximum allowed number of license configurations created in one day.

          with aws_licensemanager_license_configuration.test,
          on terraform_plugin_test.tf line 2, in resource "aws_licensemanager_license_configuration" "test":
           2: resource "aws_licensemanager_license_configuration" "test" {

--- SKIP: TestAccEC2LaunchTemplate_licenseSpecification (6.34s)
=== CONT  TestAccEC2LaunchTemplate_instanceMarketOptions
--- PASS: TestAccEC2LaunchTemplate_enclaveOptions (35.55s)
=== CONT  TestAccEC2LaunchTemplate_NetworkInterface_ipv6AddressCount
--- PASS: TestAccEC2LaunchTemplate_NetworkInterface_ipv6AddressCount (15.88s)
=== CONT  TestAccEC2LaunchTemplate_NetworkInterface_ipv6Addresses
--- PASS: TestAccEC2LaunchTemplate_metadataOptions (39.31s)
=== CONT  TestAccEC2LaunchTemplate_networkInterfaceCardIndex
--- PASS: TestAccEC2LaunchTemplate_NetworkInterface_ipv6Addresses (14.36s)
=== CONT  TestAccEC2LaunchTemplate_Placement_hostResourceGroupARN
--- PASS: TestAccEC2LaunchTemplate_networkInterfaceCardIndex (14.32s)
=== CONT  TestAccEC2LaunchTemplate_associateCarrierIPAddress
--- PASS: TestAccEC2LaunchTemplate_Placement_hostResourceGroupARN (16.75s)
=== CONT  TestAccEC2LaunchTemplate_associatePublicIPAddress
--- PASS: TestAccEC2LaunchTemplate_instanceMarketOptions (84.42s)
=== CONT  TestAccEC2LaunchTemplate_elasticInferenceAccelerator
--- PASS: TestAccEC2LaunchTemplate_associateCarrierIPAddress (50.11s)
=== CONT  TestAccEC2LaunchTemplate_NetworkInterfaces_deleteOnTermination
--- PASS: TestAccEC2LaunchTemplate_associatePublicIPAddress (49.28s)
=== CONT  TestAccEC2LaunchTemplate_networkInterfaceAddresses
--- PASS: TestAccEC2LaunchTemplate_elasticInferenceAccelerator (24.21s)
=== CONT  TestAccEC2LaunchTemplate_networkInterfaceType
--- PASS: TestAccEC2LaunchTemplate_networkInterfaceAddresses (20.70s)
=== CONT  TestAccEC2LaunchTemplate_networkInterface
--- PASS: TestAccEC2LaunchTemplate_networkInterfaceType (13.90s)
=== CONT  TestAccEC2LaunchTemplate_ebsOptimized
--- PASS: TestAccEC2LaunchTemplate_NetworkInterfaces_deleteOnTermination (45.98s)
=== CONT  TestAccEC2LaunchTemplate_IAMInstanceProfile_emptyBlock
--- PASS: TestAccEC2LaunchTemplate_networkInterface (22.62s)
=== CONT  TestAccEC2LaunchTemplate_disappears
--- PASS: TestAccEC2LaunchTemplate_disappears (10.63s)
=== CONT  TestAccEC2LaunchTemplate_BlockDeviceMappings_ebs
--- PASS: TestAccEC2LaunchTemplate_IAMInstanceProfile_emptyBlock (12.57s)
=== CONT  TestAccEC2LaunchTemplate_BlockDeviceMappingsEBS_gp3
--- PASS: TestAccEC2LaunchTemplate_ebsOptimized (57.64s)
=== CONT  TestAccEC2LaunchTemplate_Name_prefix
--- PASS: TestAccEC2LaunchTemplate_Name_prefix (15.80s)
=== CONT  TestAccEC2LaunchTemplate_Name_generated
--- PASS: TestAccEC2LaunchTemplate_BlockDeviceMappings_ebs (51.32s)
=== CONT  TestAccEC2LaunchTemplate_BlockDeviceMappingsEBS_deleteOnTermination
--- PASS: TestAccEC2LaunchTemplate_BlockDeviceMappingsEBS_gp3 (52.60s)
--- PASS: TestAccEC2LaunchTemplate_Name_generated (14.08s)
--- PASS: TestAccEC2LaunchTemplate_BlockDeviceMappingsEBS_deleteOnTermination (90.63s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	461.096s
  • Loading branch information
ewbankkit committed Mar 16, 2022
1 parent 9710b31 commit a4cebe5
Show file tree
Hide file tree
Showing 3 changed files with 509 additions and 442 deletions.
8 changes: 4 additions & 4 deletions docs/contributing/data-handling-and-conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ To read:
input := service.ExampleOperationInput{}

if v, ok := d.GetOk("attribute_name"); ok {
t, _ := time.Parse(time.RFC3339, v.(string))
v, _ := time.Parse(time.RFC3339, v.(string))

input.AttributeName = aws.Time(t)
input.AttributeName = aws.Time(v)
}
```

Expand Down Expand Up @@ -806,9 +806,9 @@ func expandStructure(tfMap map[string]interface{}) *service.Structure {
// ...

if v, ok := tfMap["nested_attribute_name"].(string); ok && v != "" {
t, _ := time.Parse(time.RFC3339, v.(string))
v, _ := time.Parse(time.RFC3339, v)

apiObject.NestedAttributeName = aws.Time(t)
apiObject.NestedAttributeName = aws.Time(v)
}

// ...
Expand Down
20 changes: 2 additions & 18 deletions internal/service/ec2/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3073,29 +3073,13 @@ func expandCapacityReservationSpecification(crs []interface{}) *ec2.CapacityRese
capacityReservationSpecification.CapacityReservationPreference = aws.String(v.(string))
}

if v, ok := m["capacity_reservation_target"]; ok && v != "" && (len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil) {
capacityReservationSpecification.CapacityReservationTarget = expandCapacityReservationTarget(v.([]interface{}))
if v, ok := m["capacity_reservation_target"].([]interface{}); ok && len(v) > 0 {
capacityReservationSpecification.CapacityReservationTarget = expandCapacityReservationTarget(v[0].(map[string]interface{}))
}

return capacityReservationSpecification
}

func expandCapacityReservationTarget(crt []interface{}) *ec2.CapacityReservationTarget {
if len(crt) < 1 || crt[0] == nil {
return nil
}

m := crt[0].(map[string]interface{})

capacityReservationTarget := &ec2.CapacityReservationTarget{}

if v, ok := m["capacity_reservation_id"]; ok && v != "" {
capacityReservationTarget.CapacityReservationId = aws.String(v.(string))
}

return capacityReservationTarget
}

func flattenEc2InstanceMetadataOptions(opts *ec2.InstanceMetadataOptionsResponse) []interface{} {
if opts == nil {
return nil
Expand Down
Loading

0 comments on commit a4cebe5

Please sign in to comment.