Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only set associate_public_ip_address if it's explicitly set #10157

Merged
merged 5 commits into from
Nov 27, 2019

Conversation

ryndaniels
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Closes #6777

Release note for CHANGELOG:

BUG FIXES:
* resource/aws_launch_template: Only set associate_public_ip_address on network interfaces if it's explicitly set to avoid problems with multiple network interfaces

Output from acceptance testing:

Test to catch this problem - commented out because of problems with TF destroy when it passes

$ make testacc TESTARGS="-run=TestAccAWSEc2Fleet_TemplateMultipleNetworkInterfaces"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSEc2Fleet_TemplateMultipleNetworkInterfaces -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSEc2Fleet_TemplateMultipleNetworkInterfaces
=== PAUSE TestAccAWSEc2Fleet_TemplateMultipleNetworkInterfaces
=== CONT  TestAccAWSEc2Fleet_TemplateMultipleNetworkInterfaces
fleet id: fleet-b7d98d6c-bc90-4ef2-b246-70449d1a395b
--- FAIL: TestAccAWSEc2Fleet_TemplateMultipleNetworkInterfaces (203.10s)
    testing.go:569: Step 0 error: Check failed: Check 3/3 error: Error The associatePublicIPAddress parameter cannot be specified when launching with multiple network interfaces found in fleet history event
FAIL
FAIL    github.com/terraform-providers/terraform-provider-aws/aws       204.383s
make: *** [testacc] Error 1

All other tests with the new code:

make testacc TESTARGS="-run=TestAccAWSEc2Fleet_"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSEc2Fleet_ -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSEc2Fleet_basic
=== PAUSE TestAccAWSEc2Fleet_basic
=== RUN   TestAccAWSEc2Fleet_disappears
=== PAUSE TestAccAWSEc2Fleet_disappears
=== RUN   TestAccAWSEc2Fleet_ExcessCapacityTerminationPolicy
=== PAUSE TestAccAWSEc2Fleet_ExcessCapacityTerminationPolicy
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_LaunchTemplateId
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_LaunchTemplateId
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_LaunchTemplateName
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_LaunchTemplateName
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_Version
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_Version
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_AvailabilityZone
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_AvailabilityZone
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_InstanceType
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_InstanceType
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_MaxPrice
--- SKIP: TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_MaxPrice (0.00s)
    resource_aws_ec2_fleet_test.go:337: EC2 API is not correctly returning MaxPrice override
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_Priority
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_Priority
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_Priority_Multiple
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_Priority_Multiple
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_SubnetId
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_SubnetId
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_WeightedCapacity
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_WeightedCapacity
=== RUN   TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_WeightedCapacity_Multiple
=== PAUSE TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_WeightedCapacity_Multiple
=== RUN   TestAccAWSEc2Fleet_OnDemandOptions_AllocationStrategy
=== PAUSE TestAccAWSEc2Fleet_OnDemandOptions_AllocationStrategy
=== RUN   TestAccAWSEc2Fleet_ReplaceUnhealthyInstances
=== PAUSE TestAccAWSEc2Fleet_ReplaceUnhealthyInstances
=== RUN   TestAccAWSEc2Fleet_SpotOptions_AllocationStrategy
=== PAUSE TestAccAWSEc2Fleet_SpotOptions_AllocationStrategy
=== RUN   TestAccAWSEc2Fleet_SpotOptions_InstanceInterruptionBehavior
=== PAUSE TestAccAWSEc2Fleet_SpotOptions_InstanceInterruptionBehavior
=== RUN   TestAccAWSEc2Fleet_SpotOptions_InstancePoolsToUseCount
=== PAUSE TestAccAWSEc2Fleet_SpotOptions_InstancePoolsToUseCount
=== RUN   TestAccAWSEc2Fleet_Tags
=== PAUSE TestAccAWSEc2Fleet_Tags
=== RUN   TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType
=== PAUSE TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType
=== RUN   TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType_OnDemand
=== PAUSE TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType_OnDemand
=== RUN   TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType_Spot
=== PAUSE TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType_Spot
=== RUN   TestAccAWSEc2Fleet_TargetCapacitySpecification_TotalTargetCapacity
=== PAUSE TestAccAWSEc2Fleet_TargetCapacitySpecification_TotalTargetCapacity
=== RUN   TestAccAWSEc2Fleet_TerminateInstancesWithExpiration
=== PAUSE TestAccAWSEc2Fleet_TerminateInstancesWithExpiration
=== RUN   TestAccAWSEc2Fleet_Type
=== PAUSE TestAccAWSEc2Fleet_Type
=== CONT  TestAccAWSEc2Fleet_basic
=== CONT  TestAccAWSEc2Fleet_OnDemandOptions_AllocationStrategy
=== CONT  TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_WeightedCapacity_Multiple
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_WeightedCapacity
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_SubnetId
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_Priority_Multiple
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_Priority
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_InstanceType
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_AvailabilityZone
=== CONT  TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType_OnDemand
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_Version
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_LaunchTemplateName
=== CONT  TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_LaunchTemplateId
=== CONT  TestAccAWSEc2Fleet_ExcessCapacityTerminationPolicy
=== CONT  TestAccAWSEc2Fleet_Type
=== CONT  TestAccAWSEc2Fleet_TerminateInstancesWithExpiration
=== CONT  TestAccAWSEc2Fleet_TargetCapacitySpecification_TotalTargetCapacity
=== CONT  TestAccAWSEc2Fleet_disappears
=== CONT  TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType_Spot
--- PASS: TestAccAWSEc2Fleet_disappears (52.44s)
=== CONT  TestAccAWSEc2Fleet_SpotOptions_AllocationStrategy
--- PASS: TestAccAWSEc2Fleet_Type (52.68s)
=== CONT  TestAccAWSEc2Fleet_Tags
--- PASS: TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType_OnDemand (53.23s)
=== CONT  TestAccAWSEc2Fleet_ReplaceUnhealthyInstances
--- PASS: TestAccAWSEc2Fleet_basic (53.27s)
=== CONT  TestAccAWSEc2Fleet_SpotOptions_InstancePoolsToUseCount
--- PASS: TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType_Spot (53.37s)
=== CONT  TestAccAWSEc2Fleet_SpotOptions_InstanceInterruptionBehavior
--- PASS: TestAccAWSEc2Fleet_TargetCapacitySpecification_DefaultTargetCapacityType (92.85s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_InstanceType (94.09s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_LaunchTemplateName (94.43s)
--- PASS: TestAccAWSEc2Fleet_TerminateInstancesWithExpiration (94.54s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_Priority_Multiple (94.68s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_LaunchTemplateId (95.14s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_WeightedCapacity (95.57s)
--- PASS: TestAccAWSEc2Fleet_OnDemandOptions_AllocationStrategy (95.57s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_WeightedCapacity_Multiple (95.58s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_AvailabilityZone (95.63s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_Priority (96.97s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_LaunchTemplateSpecification_Version (97.10s)
--- PASS: TestAccAWSEc2Fleet_ExcessCapacityTerminationPolicy (124.79s)
--- PASS: TestAccAWSEc2Fleet_LaunchTemplateConfig_Override_SubnetId (130.06s)
--- PASS: TestAccAWSEc2Fleet_Tags (93.38s)
--- PASS: TestAccAWSEc2Fleet_SpotOptions_AllocationStrategy (94.62s)
--- PASS: TestAccAWSEc2Fleet_SpotOptions_InstancePoolsToUseCount (93.88s)
--- PASS: TestAccAWSEc2Fleet_SpotOptions_InstanceInterruptionBehavior (93.79s)
--- PASS: TestAccAWSEc2Fleet_ReplaceUnhealthyInstances (94.10s)
--- PASS: TestAccAWSEc2Fleet_TargetCapacitySpecification_TotalTargetCapacity (497.61s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       499.024s

make testacc TESTARGS="-run=TestAccAWSLaunchTemplate_"   ==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSLaunchTemplate_ -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSLaunchTemplate_importBasic
=== PAUSE TestAccAWSLaunchTemplate_importBasic
=== RUN   TestAccAWSLaunchTemplate_importData
=== PAUSE TestAccAWSLaunchTemplate_importData
=== RUN   TestAccAWSLaunchTemplate_basic
=== PAUSE TestAccAWSLaunchTemplate_basic
=== RUN   TestAccAWSLaunchTemplate_disappears
=== PAUSE TestAccAWSLaunchTemplate_disappears
=== RUN   TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS
=== PAUSE TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS
=== RUN   TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_DeleteOnTermination
=== PAUSE TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_DeleteOnTermination
=== RUN   TestAccAWSLaunchTemplate_EbsOptimized
=== PAUSE TestAccAWSLaunchTemplate_EbsOptimized
=== RUN   TestAccAWSLaunchTemplate_ElasticInferenceAccelerator
=== PAUSE TestAccAWSLaunchTemplate_ElasticInferenceAccelerator
=== RUN   TestAccAWSLaunchTemplate_data
=== PAUSE TestAccAWSLaunchTemplate_data
=== RUN   TestAccAWSLaunchTemplate_description
=== PAUSE TestAccAWSLaunchTemplate_description
=== RUN   TestAccAWSLaunchTemplate_update
=== PAUSE TestAccAWSLaunchTemplate_update
=== RUN   TestAccAWSLaunchTemplate_tags
=== PAUSE TestAccAWSLaunchTemplate_tags
=== RUN   TestAccAWSLaunchTemplate_capacityReservation_preference
=== PAUSE TestAccAWSLaunchTemplate_capacityReservation_preference
=== RUN   TestAccAWSLaunchTemplate_capacityReservation_target
=== PAUSE TestAccAWSLaunchTemplate_capacityReservation_target
=== RUN   TestAccAWSLaunchTemplate_creditSpecification_nonBurstable
=== PAUSE TestAccAWSLaunchTemplate_creditSpecification_nonBurstable
=== RUN   TestAccAWSLaunchTemplate_creditSpecification_t2
=== PAUSE TestAccAWSLaunchTemplate_creditSpecification_t2
=== RUN   TestAccAWSLaunchTemplate_creditSpecification_t3
=== PAUSE TestAccAWSLaunchTemplate_creditSpecification_t3
=== RUN   TestAccAWSLaunchTemplate_IamInstanceProfile_EmptyConfigurationBlock
=== PAUSE TestAccAWSLaunchTemplate_IamInstanceProfile_EmptyConfigurationBlock
=== RUN   TestAccAWSLaunchTemplate_networkInterface
=== PAUSE TestAccAWSLaunchTemplate_networkInterface
=== RUN   TestAccAWSLaunchTemplate_networkInterface_ipv6Addresses
=== PAUSE TestAccAWSLaunchTemplate_networkInterface_ipv6Addresses
=== RUN   TestAccAWSLaunchTemplate_networkInterface_ipv6AddressCount
=== PAUSE TestAccAWSLaunchTemplate_networkInterface_ipv6AddressCount
=== RUN   TestAccAWSLaunchTemplate_instanceMarketOptions
=== PAUSE TestAccAWSLaunchTemplate_instanceMarketOptions
=== RUN   TestAccAWSLaunchTemplate_licenseSpecification
=== PAUSE TestAccAWSLaunchTemplate_licenseSpecification
=== CONT  TestAccAWSLaunchTemplate_importBasic
=== CONT  TestAccAWSLaunchTemplate_licenseSpecification
=== CONT  TestAccAWSLaunchTemplate_update
=== CONT  TestAccAWSLaunchTemplate_tags
=== CONT  TestAccAWSLaunchTemplate_IamInstanceProfile_EmptyConfigurationBlock
=== CONT  TestAccAWSLaunchTemplate_creditSpecification_t3
=== CONT  TestAccAWSLaunchTemplate_instanceMarketOptions
=== CONT  TestAccAWSLaunchTemplate_creditSpecification_t2
=== CONT  TestAccAWSLaunchTemplate_networkInterface_ipv6AddressCount
=== CONT  TestAccAWSLaunchTemplate_creditSpecification_nonBurstable
=== CONT  TestAccAWSLaunchTemplate_networkInterface_ipv6Addresses
=== CONT  TestAccAWSLaunchTemplate_capacityReservation_target
=== CONT  TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_DeleteOnTermination
=== CONT  TestAccAWSLaunchTemplate_description
=== CONT  TestAccAWSLaunchTemplate_data
=== CONT  TestAccAWSLaunchTemplate_capacityReservation_preference
=== CONT  TestAccAWSLaunchTemplate_EbsOptimized
=== CONT  TestAccAWSLaunchTemplate_disappears
=== CONT  TestAccAWSLaunchTemplate_networkInterface
=== CONT  TestAccAWSLaunchTemplate_ElasticInferenceAccelerator
--- PASS: TestAccAWSLaunchTemplate_disappears (21.94s)
=== CONT  TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS
--- PASS: TestAccAWSLaunchTemplate_networkInterface_ipv6AddressCount (26.70s)
=== CONT  TestAccAWSLaunchTemplate_basic
--- PASS: TestAccAWSLaunchTemplate_IamInstanceProfile_EmptyConfigurationBlock (26.82s)
=== CONT  TestAccAWSLaunchTemplate_importData
--- PASS: TestAccAWSLaunchTemplate_creditSpecification_t2 (26.94s)
--- PASS: TestAccAWSLaunchTemplate_data (27.11s)
--- PASS: TestAccAWSLaunchTemplate_creditSpecification_t3 (27.13s)
--- PASS: TestAccAWSLaunchTemplate_networkInterface_ipv6Addresses (27.13s)
--- PASS: TestAccAWSLaunchTemplate_creditSpecification_nonBurstable (27.35s)
--- PASS: TestAccAWSLaunchTemplate_capacityReservation_preference (27.38s)
--- PASS: TestAccAWSLaunchTemplate_licenseSpecification (30.62s)
--- PASS: TestAccAWSLaunchTemplate_importBasic (31.55s)
--- PASS: TestAccAWSLaunchTemplate_capacityReservation_target (37.52s)
--- PASS: TestAccAWSLaunchTemplate_description (45.69s)
--- PASS: TestAccAWSLaunchTemplate_ElasticInferenceAccelerator (49.20s)
--- PASS: TestAccAWSLaunchTemplate_tags (49.21s)
--- PASS: TestAccAWSLaunchTemplate_basic (26.33s)
--- PASS: TestAccAWSLaunchTemplate_importData (27.91s)
--- PASS: TestAccAWSLaunchTemplate_networkInterface (61.59s)
--- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS (51.53s)
--- PASS: TestAccAWSLaunchTemplate_update (82.10s)
--- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_DeleteOnTermination (83.31s)
--- PASS: TestAccAWSLaunchTemplate_instanceMarketOptions (92.07s)
--- PASS: TestAccAWSLaunchTemplate_EbsOptimized (109.33s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       110.236s

@ryndaniels ryndaniels requested review from nywilken and a team September 19, 2019 09:50
@ghost ghost added size/L Managed by automation to categorize the size of a PR. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Sep 19, 2019
@ryndaniels ryndaniels requested review from bflad and removed request for nywilken October 16, 2019 13:36
@bflad
Copy link
Contributor

bflad commented Nov 19, 2019

Hey @ryndaniels 👋 This resource has been a good candidate for highlighting some limitations in the Terraform Plugin SDK type system. In EC2 Launch Templates, many of the boolean type fields actually have three states:

  • enabled (true)
  • disabled (false)
  • unset (for example, determined by upstream AMI and unable to be determined by the SDK TypeBool)

To work around this limitation, we introduced a workaround with TypeString (#5632), e.g.

https://github.com/terraform-providers/terraform-provider-aws/blob/1963850753be507dd4f6fa1f2238ed3e4b6c9385/aws/resource_aws_launch_template.go#L92-L101

Is this type of workaround more appropriate in this case? Removing the ability to specify false does not necessarily feel right in this case. While the EC2 API Reference doesn't necessarily clue into this too well, the EC2 web console does tend to show these enabled/disabled/unset configurations so it might be good verifying there if false and "unset" are valid.

For acceptance testing here, we should try to ensure there is covering of all attribute states (using ExpectError in the test framework if necessary). 👍

@ghost ghost removed the size/L Managed by automation to categorize the size of a PR. label Nov 21, 2019
@ghost
Copy link

ghost commented Nov 21, 2019

Hello, and thank you for your contribution!

This project recently migrated to the standalone Terraform Plugin SDK. While the migration helps speed up future feature requests and bug fixes to the Terraform AWS Provider's interface with Terraform, it has the unfortunate consequence of requiring minor changes to pull requests created using the old SDK.

This pull request appears to include the Go import path "github.com/hashicorp/terraform/helper/acctest", which was from the older SDK. The newer SDK uses import paths beginning with github.com/hashicorp/terraform-plugin-sdk/.

To resolve this situation without losing any existing work, you may be able to Git rebase your branch against the current master branch (example below); replacing any remaining old import paths with the newer ones.

$ git fetch --all
$ git rebase origin/master

Another option is to create a new branch from the current master with the same code changes (replacing the import paths), submit a new pull request, and close this existing pull request.

We apologize for this inconvenience and appreciate your effort. Thank you for contributing and helping make the Terraform AWS Provider better for everyone.

@ghost ghost added size/XL Managed by automation to categorize the size of a PR. terraform-plugin-sdk-migration labels Nov 21, 2019
@ghost ghost added size/L Managed by automation to categorize the size of a PR. and removed size/XL Managed by automation to categorize the size of a PR. labels Nov 21, 2019
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. and removed size/L Managed by automation to categorize the size of a PR. labels Nov 21, 2019
@ryndaniels
Copy link
Contributor Author

@bflad it took a minute but I think I've got this working using the TypeString workaround now, with an additional couple more tests!

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the testing changes noted below, I think this is good to go. 👍

@@ -1077,6 +1125,80 @@ resource "aws_launch_template" "test" {
}
`

const testAccAWSLaunchTemplateConfig_associatePublicIpAddressTrue = `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This can be simplified into a single test configuration function by passing in the parameter, e.g.

func testAccAWSLaunchTemplateConfig_associatePublicIpAddress(associatePublicIpAddress string) string {
  return fmt.Sprintf(`
# ...
resource "aws_launch_template" "test" {
  name = "network-interface-launch-template"

  network_interfaces {
    associate_public_ip_address = %[1]s
    network_interface_id        = "${aws_network_interface.test.id}"
    ipv4_address_count          = 2
  }
}
`, associatePublicIpAddress)

Where that is populated via:

Config: testAccAWSLaunchTemplateConfig_associatePublicIpAddress("true"),
Config: testAccAWSLaunchTemplateConfig_associatePublicIpAddress("false"),
Config: testAccAWSLaunchTemplateConfig_associatePublicIpAddress("null"),

}

resource "aws_launch_template" "test" {
name = "network-interface-launch-template"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name needs to be randomized to prevent issues like:

--- FAIL: TestAccAWSLaunchTemplate_networkInterface (23.50s)
    testing.go:635: Step 0 error: errors during apply:

        Error: InvalidLaunchTemplateName.AlreadyExistsException: Launch template name already in use.

Combining with the suggested update above:

func testAccAWSLaunchTemplateConfig_associatePublicIpAddress(rName, associatePublicIpAddress string) string {
  return fmt.Sprintf(`
# ...
resource "aws_launch_template" "test" {
  name = %[1]q

  network_interfaces {
    associate_public_ip_address = %[2]s
    network_interface_id        = "${aws_network_interface.test.id}"
    ipv4_address_count          = 2
  }
}
`, rName, associatePublicIpAddress)

@bflad bflad added bug Addresses a defect in current functionality. and removed terraform-plugin-sdk-migration labels Nov 26, 2019
@ryndaniels ryndaniels added this to the v2.41.0 milestone Nov 27, 2019
@ryndaniels ryndaniels merged commit 59e99f2 into master Nov 27, 2019
@ghost
Copy link

ghost commented Dec 4, 2019

This has been released in version 2.41.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Mar 28, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 28, 2020
@bflad bflad deleted the rfd-at6777 branch April 23, 2020 03:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_launch_template network interfaces associate_public_ip_address default should not be set
2 participants