Skip to content

Commit

Permalink
fix: http endpoint not defaulted (#24774)
Browse files Browse the repository at this point in the history
* fix: http endpoint not defaulted

* Add changelog entry

* Fix attribute name

* chore: adjust changelog

* r/aws_instance(test): metadata_options defaults

---------

Co-authored-by: Andy Haynssen <[email protected]>
Co-authored-by: Jared Baker <[email protected]>
  • Loading branch information
3 people authored Jun 9, 2023
1 parent 2ad3dd6 commit e1f2849
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changelog/24774.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_instance: Fix default for `metadata_options.http_endpoint` argument.
```

```release-note:note
resource/aws_instance: The `metadata_options.http_endpoint` argument now correctly defaults to `enabled`.
```
2 changes: 1 addition & 1 deletion internal/service/ec2/ec2_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func ResourceInstance() *schema.Resource {
"http_endpoint": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Default: ec2.InstanceMetadataEndpointStateEnabled,
ValidateFunc: validation.StringInSlice(ec2.InstanceMetadataEndpointState_Values(), false),
},
"http_put_response_hop_limit": {
Expand Down
35 changes: 33 additions & 2 deletions internal/service/ec2/ec2_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4999,7 +4999,18 @@ func TestAccEC2Instance_metadataOptions(t *testing.T) {
CheckDestroy: testAccCheckInstanceDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInstanceConfig_metadataOptions(rName),
Config: testAccInstanceConfig_metadataOptionsDefaults(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "metadata_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "metadata_options.0.http_endpoint", "enabled"),
resource.TestCheckResourceAttr(resourceName, "metadata_options.0.http_tokens", "optional"),
resource.TestCheckResourceAttr(resourceName, "metadata_options.0.http_put_response_hop_limit", "1"),
resource.TestCheckResourceAttr(resourceName, "metadata_options.0.instance_metadata_tags", "disabled"),
),
},
{
Config: testAccInstanceConfig_metadataOptionsDisabled(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "metadata_options.#", "1"),
Expand Down Expand Up @@ -8469,7 +8480,27 @@ resource "aws_instance" "test" {
`, rName, hibernation))
}

func testAccInstanceConfig_metadataOptions(rName string) string {
func testAccInstanceConfig_metadataOptionsDefaults(rName string) string {
return acctest.ConfigCompose(
acctest.ConfigLatestAmazonLinuxHVMEBSAMI(),
testAccInstanceVPCConfig(rName, false, 0),
acctest.AvailableEC2InstanceTypeForRegion("t3.micro", "t2.micro"),
fmt.Sprintf(`
resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = data.aws_ec2_instance_type_offering.available.instance_type
subnet_id = aws_subnet.test.id
tags = {
Name = %[1]q
}
metadata_options {}
}
`, rName))
}

func testAccInstanceConfig_metadataOptionsDisabled(rName string) string {
return acctest.ConfigCompose(
acctest.ConfigLatestAmazonLinuxHVMEBSAMI(),
testAccInstanceVPCConfig(rName, false, 0),
Expand Down

0 comments on commit e1f2849

Please sign in to comment.