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

New resource: aws_ec2_managed_prefix_list #14068

Merged
merged 4 commits into from
Dec 17, 2020
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
17 changes: 17 additions & 0 deletions aws/internal/service/ec2/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,20 @@ func VpnGatewayByID(conn *ec2.EC2, id string) (*ec2.VpnGateway, error) {

return output.VpnGateways[0], nil
}

func ManagedPrefixListByID(conn *ec2.EC2, id string) (*ec2.ManagedPrefixList, error) {
input := &ec2.DescribeManagedPrefixListsInput{
PrefixListIds: aws.StringSlice([]string{id}),
}

output, err := conn.DescribeManagedPrefixLists(input)
if err != nil {
return nil, err
}

if output == nil || len(output.PrefixLists) == 0 {
return nil, nil
}

return output.PrefixLists[0], nil
}
19 changes: 19 additions & 0 deletions aws/internal/service/ec2/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,22 @@ func VpnGatewayVpcAttachmentState(conn *ec2.EC2, vpnGatewayID, vpcID string) res
return vpcAttachment, aws.StringValue(vpcAttachment.State), nil
}
}

const (
managedPrefixListStateNotFound = "NotFound"
managedPrefixListStateUnknown = "Unknown"
)

func ManagedPrefixListState(conn *ec2.EC2, prefixListId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
managedPrefixList, err := finder.ManagedPrefixListByID(conn, prefixListId)
if err != nil {
return nil, managedPrefixListStateUnknown, err
}
if managedPrefixList == nil {
return nil, managedPrefixListStateNotFound, nil
}

return managedPrefixList, aws.StringValue(managedPrefixList.State), nil
}
}
60 changes: 60 additions & 0 deletions aws/internal/service/ec2/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

Expand Down Expand Up @@ -244,3 +245,62 @@ func VpnGatewayVpcAttachmentDetached(conn *ec2.EC2, vpnGatewayID, vpcID string)

return nil, err
}

const (
ManagedPrefixListTimeout = 15 * time.Minute
)

func ManagedPrefixListCreated(conn *ec2.EC2, prefixListId string) (*ec2.ManagedPrefixList, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{ec2.PrefixListStateCreateInProgress},
Target: []string{ec2.PrefixListStateCreateComplete},
Timeout: ManagedPrefixListTimeout,
Refresh: ManagedPrefixListState(conn, prefixListId),
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}

func ManagedPrefixListModified(conn *ec2.EC2, prefixListId string) (*ec2.ManagedPrefixList, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{ec2.PrefixListStateModifyInProgress},
Target: []string{ec2.PrefixListStateModifyComplete},
Timeout: ManagedPrefixListTimeout,
Refresh: ManagedPrefixListState(conn, prefixListId),
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}

func ManagedPrefixListDeleted(conn *ec2.EC2, prefixListId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{ec2.PrefixListStateDeleteInProgress},
Target: []string{ec2.PrefixListStateDeleteComplete},
Timeout: ManagedPrefixListTimeout,
Refresh: ManagedPrefixListState(conn, prefixListId),
}

_, err := stateConf.WaitForState()

if tfawserr.ErrCodeEquals(err, "InvalidPrefixListID.NotFound") {
return nil
}

if err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ func Provider() *schema.Provider {
"aws_ec2_fleet": resourceAwsEc2Fleet(),
"aws_ec2_local_gateway_route": resourceAwsEc2LocalGatewayRoute(),
"aws_ec2_local_gateway_route_table_vpc_association": resourceAwsEc2LocalGatewayRouteTableVpcAssociation(),
"aws_ec2_managed_prefix_list": resourceAwsEc2ManagedPrefixList(),
"aws_ec2_tag": resourceAwsEc2Tag(),
"aws_ec2_traffic_mirror_filter": resourceAwsEc2TrafficMirrorFilter(),
"aws_ec2_traffic_mirror_filter_rule": resourceAwsEc2TrafficMirrorFilterRule(),
Expand Down
Loading