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

r/aws_subnet: Resource-based naming is not available in the ap-southeast-3 region #22531

Merged
merged 4 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/22531.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_subnet: Resource-based naming is not available in the `ap-southeast-3` region
```
16 changes: 16 additions & 0 deletions internal/service/ec2/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,22 @@ func StatusSubnetMapPublicIPOnLaunch(conn *ec2.EC2, id string) resource.StateRef
}
}

func StatusSubnetPrivateDNSHostnameTypeOnLaunch(conn *ec2.EC2, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindSubnetByID(conn, id)

if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return output, aws.StringValue(output.PrivateDnsNameOptionsOnLaunch.HostnameType), nil
}
}

func StatusTransitGatewayPrefixListReferenceState(conn *ec2.EC2, transitGatewayRouteTableID string, prefixListID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
transitGatewayPrefixListReference, err := FindTransitGatewayPrefixListReference(conn, transitGatewayRouteTableID, prefixListID)
Expand Down
13 changes: 12 additions & 1 deletion internal/service/ec2/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func resourceSubnetCreate(d *schema.ResourceData, meta interface{}) error {
input := &ec2.CreateSubnetInput{
AvailabilityZone: aws.String(d.Get("availability_zone").(string)),
AvailabilityZoneId: aws.String(d.Get("availability_zone_id").(string)),
Ipv6Native: aws.Bool(d.Get("ipv6_native").(bool)),
TagSpecifications: ec2TagSpecificationsFromKeyValueTags(tags, ec2.ResourceTypeSubnet),
VpcId: aws.String(d.Get("vpc_id").(string)),
}
Expand All @@ -160,6 +159,10 @@ func resourceSubnetCreate(d *schema.ResourceData, meta interface{}) error {
input.Ipv6CidrBlock = aws.String(v.(string))
}

if v, ok := d.GetOk("ipv6_native"); ok {
input.Ipv6Native = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("outpost_arn"); ok {
input.OutpostArn = aws.String(v.(string))
}
Expand Down Expand Up @@ -291,6 +294,10 @@ func resourceSubnetCreate(d *schema.ResourceData, meta interface{}) error {
if _, err := conn.ModifySubnetAttribute(input); err != nil {
return fmt.Errorf("error setting EC2 Subnet (%s) PrivateDnsHostnameTypeOnLaunch: %w", d.Id(), err)
}

if _, err := WaitSubnetPrivateDNSHostnameTypeOnLaunchUpdated(conn, d.Id(), d.Get("private_dns_hostname_type_on_launch").(string)); err != nil {
return fmt.Errorf("error waiting for EC2 Subnet (%s) PrivateDnsHostnameTypeOnLaunch update: %w", d.Id(), err)
}
}

return resourceSubnetRead(d, meta)
Expand Down Expand Up @@ -480,6 +487,10 @@ func resourceSubnetUpdate(d *schema.ResourceData, meta interface{}) error {
if _, err := conn.ModifySubnetAttribute(input); err != nil {
return fmt.Errorf("error setting EC2 Subnet (%s) PrivateDnsHostnameTypeOnLaunch: %w", d.Id(), err)
}

if _, err := WaitSubnetPrivateDNSHostnameTypeOnLaunchUpdated(conn, d.Id(), d.Get("private_dns_hostname_type_on_launch").(string)); err != nil {
return fmt.Errorf("error waiting for EC2 Subnet (%s) PrivateDnsHostnameTypeOnLaunch update: %w", d.Id(), err)
}
}

if d.HasChange("ipv6_cidr_block") {
Expand Down
18 changes: 18 additions & 0 deletions internal/service/ec2/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,24 @@ func WaitSubnetMapPublicIPOnLaunchUpdated(conn *ec2.EC2, subnetID string, expect
return nil, err
}

func WaitSubnetPrivateDNSHostnameTypeOnLaunchUpdated(conn *ec2.EC2, subnetID string, expectedValue string) (*ec2.Subnet, error) {
stateConf := &resource.StateChangeConf{
Target: []string{expectedValue},
Refresh: StatusSubnetPrivateDNSHostnameTypeOnLaunch(conn, subnetID),
Timeout: SubnetAttributePropagationTimeout,
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*ec2.Subnet); ok {
return output, err
}

return nil, err
}

const (
TransitGatewayPrefixListReferenceTimeout = 5 * time.Minute
)
Expand Down