From 94987ef53e770fd50e55ecee4133e6502e749d32 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 09:18:09 -0400 Subject: [PATCH 01/30] initial commit for vpc_attachment and attachment_acceptor --- internal/provider/provider.go | 2 + .../networkmanager/attachment_acceptor.go | 164 +++++++ .../service/networkmanager/vpc_attachment.go | 414 ++++++++++++++++++ .../networkmanager/vpc_attachment_test.go | 221 ++++++++++ ...kmanager_attachment_acceptor.html.markdown | 41 ++ ...etworkmanager_vpc_attachment.html.markdown | 72 +++ 6 files changed, 914 insertions(+) create mode 100644 internal/service/networkmanager/attachment_acceptor.go create mode 100644 internal/service/networkmanager/vpc_attachment.go create mode 100644 internal/service/networkmanager/vpc_attachment_test.go create mode 100644 website/docs/r/networkmanager_attachment_acceptor.html.markdown create mode 100644 website/docs/r/networkmanager_vpc_attachment.html.markdown diff --git a/internal/provider/provider.go b/internal/provider/provider.go index d47b93e53e7..0f65d73adbe 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -1734,6 +1734,7 @@ func New(_ context.Context) (*schema.Provider, error) { "aws_networkfirewall_resource_policy": networkfirewall.ResourceResourcePolicy(), "aws_networkfirewall_rule_group": networkfirewall.ResourceRuleGroup(), + "aws_networkmanager_attachment_acceptor": networkmanager.ResourceAttachmentAcceptor(), "aws_networkmanager_connection": networkmanager.ResourceConnection(), "aws_networkmanager_customer_gateway_association": networkmanager.ResourceCustomerGatewayAssociation(), "aws_networkmanager_device": networkmanager.ResourceDevice(), @@ -1743,6 +1744,7 @@ func New(_ context.Context) (*schema.Provider, error) { "aws_networkmanager_site": networkmanager.ResourceSite(), "aws_networkmanager_transit_gateway_connect_peer_association": networkmanager.ResourceTransitGatewayConnectPeerAssociation(), "aws_networkmanager_transit_gateway_registration": networkmanager.ResourceTransitGatewayRegistration(), + "aws_networkmanager_vpc_attachment": networkmanager.ResourceVpcAttachment(), "aws_opensearch_domain": opensearch.ResourceDomain(), "aws_opensearch_domain_policy": opensearch.ResourceDomainPolicy(), diff --git a/internal/service/networkmanager/attachment_acceptor.go b/internal/service/networkmanager/attachment_acceptor.go new file mode 100644 index 00000000000..6b924a345cc --- /dev/null +++ b/internal/service/networkmanager/attachment_acceptor.go @@ -0,0 +1,164 @@ +package networkmanager + +import ( + "context" + "log" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/networkmanager" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" +) + +func ResourceAttachmentAcceptor() *schema.Resource { + return &schema.Resource{ + CreateWithoutTimeout: ResourceAttachmentAcceptorCreate, + ReadWithoutTimeout: schema.NoopContext, + DeleteWithoutTimeout: ResourceAttachmentAcceptorDelete, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "attachment_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "attachment_policy_rule_number": { + Type: schema.TypeInt, + Computed: true, + }, + + "attachment_type": { + Type: schema.TypeString, + Computed: true, + }, + + "core_network_arn": { + Type: schema.TypeString, + Computed: true, + }, + + "core_network_id": { + Type: schema.TypeString, + Computed: true, + }, + + "edge_location": { + Type: schema.TypeString, + Computed: true, + }, + + "owner_account_id": { + Type: schema.TypeString, + Computed: true, + }, + + "resource_arn": { + Type: schema.TypeString, + Computed: true, + }, + + "segment_name": { + Type: schema.TypeString, + Computed: true, + }, + + "state": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func ResourceAttachmentAcceptorCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).NetworkManagerConn + + attachmentId := d.Get("attachment_id").(string) + + // check status first and set id if already accepted + + input := &networkmanager.AcceptAttachmentInput{ + AttachmentId: aws.String(attachmentId), + } + + log.Printf("[DEBUG] Accepting Network Manager VPC Attachment: %s", input) + a, err := conn.AcceptAttachmentWithContext(ctx, input) + + if err != nil { + output, err := FindVpcAttachmentByID(ctx, conn, attachmentId) + + state := aws.StringValue(output.Attachment.State) + + if state == networkmanager.AttachmentStateAvailable { + log.Printf("[WARN] Attachment (%s) already accepted, importing attributes into state without accepting.", d.Id()) + } else { + return diag.Errorf("error accepting Network Manager VPC Attachment: %s", err) + } + } + + d.SetId(attachmentId) + if _, err := waitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + d.SetId("") + return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) + } + + d.Set("core_network_id", a.Attachment.CoreNetworkId) + d.Set("state", a.Attachment.State) + d.Set("core_network_arn", a.Attachment.CoreNetworkArn) + d.Set("attachment_policy_rule_number", a.Attachment.AttachmentPolicyRuleNumber) + d.Set("attachment_type", a.Attachment.AttachmentType) + d.Set("edge_location", a.Attachment.EdgeLocation) + d.Set("owner_account_id", a.Attachment.OwnerAccountId) + d.Set("resource_arn", a.Attachment.ResourceArn) + d.Set("segment_name", a.Attachment.SegmentName) + + return nil +} + +func ResourceAttachmentAcceptorDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + log.Printf("[WARN] Attachment (%s) not deleted, removing from state.", d.Id()) + + return nil +} + +func statusAttachmentAcceptorState(ctx context.Context, conn *networkmanager.NetworkManager, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := FindVpcAttachmentByID(ctx, conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, aws.StringValue(output.Attachment.State), nil + } +} + +func waitAttachmentAcceptorCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{networkmanager.AttachmentStatePendingAttachmentAcceptance, networkmanager.AttachmentStatePendingNetworkUpdate}, + Target: []string{networkmanager.AttachmentStateAvailable}, + Timeout: timeout, + Refresh: statusVpcAttachmentState(ctx, conn, id), + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkmanager.VpcAttachment); ok { + return output, err + } + + return nil, err +} diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go new file mode 100644 index 00000000000..aee313cc060 --- /dev/null +++ b/internal/service/networkmanager/vpc_attachment.go @@ -0,0 +1,414 @@ +package networkmanager + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/networkmanager" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/flex" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/internal/verify" +) + +func ResourceVpcAttachment() *schema.Resource { + return &schema.Resource{ + CreateWithoutTimeout: resourceVpcAttachmentCreate, + ReadWithoutTimeout: resourceVpcAttachmentRead, + UpdateWithoutTimeout: resourceVpcAttachmentUpdate, + DeleteWithoutTimeout: resourceVpcAttachmentDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + CustomizeDiff: verify.SetTagsDiff, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "attachment_policy_rule_number": { + Type: schema.TypeInt, + Computed: true, + }, + + "attachment_type": { + Type: schema.TypeString, + Computed: true, + }, + + "core_network_arn": { + Type: schema.TypeString, + Computed: true, + }, + + "core_network_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "edge_location": { + Type: schema.TypeString, + Computed: true, + }, + + "options": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ipv6_support": { + Type: schema.TypeBool, + Required: true, + }, + }, + }, + }, + + "owner_account_id": { + Type: schema.TypeString, + Computed: true, + }, + + "resource_arn": { + Type: schema.TypeString, + Computed: true, + }, + + "segment_name": { + Type: schema.TypeString, + Computed: true, + }, + + "state": { + Type: schema.TypeString, + Computed: true, + }, + + "subnet_arns": { + Type: schema.TypeSet, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: verify.ValidARN, + }, + }, + + "tags": tftags.TagsSchema(), + "tags_all": tftags.TagsSchemaComputed(), + + "vpc_arn": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: verify.ValidARN, + }, + }, + } +} + +func resourceVpcAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).NetworkManagerConn + defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) + + input := &networkmanager.CreateVpcAttachmentInput{ + CoreNetworkId: aws.String(d.Get("core_network_id").(string)), + VpcArn: aws.String(d.Get("vpc_arn").(string)), + SubnetArns: flex.ExpandStringSet(d.Get("subnet_arns").(*schema.Set)), + } + + if v, ok := d.GetOk("options"); ok { + optsMap := v.([]interface{})[0].(map[string]interface{}) + input.Options = &networkmanager.VpcOptions{ + Ipv6Support: aws.Bool(optsMap["ipv6_support"].(bool)), + } + } + + if len(tags) > 0 { + input.Tags = Tags(tags.IgnoreAWS()) + } + + log.Printf("[DEBUG] Creating Network Manager VPC Attachment: %s", input) + output, err := conn.CreateVpcAttachmentWithContext(ctx, input) + + if err != nil { + return diag.Errorf("error creating Network Manager VPC Attachment: %s", err) + } + + d.SetId(aws.StringValue(output.VpcAttachment.Attachment.AttachmentId)) + + if _, err := waitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) + } + + return resourceVpcAttachmentRead(ctx, d, meta) +} + +func resourceVpcAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).NetworkManagerConn + defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig + ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig + + vpcAttachment, err := conn.GetVpcAttachment(&networkmanager.GetVpcAttachmentInput{ + AttachmentId: aws.String(d.Id()), + }) + + if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { + log.Printf("[WARN] Network Manager VPC Attachment %s not found, removing from state", d.Id()) + d.SetId("") + return nil + } + + if err != nil { + return diag.Errorf("error reading Network Manager VPC Attachment (%s): %s", d.Id(), err) + } + + a := vpcAttachment.VpcAttachment.Attachment + subnetArns := vpcAttachment.VpcAttachment.SubnetArns + opts := vpcAttachment.VpcAttachment.Options + + d.Set("core_network_id", a.CoreNetworkId) + d.Set("state", a.State) + d.Set("core_network_arn", a.CoreNetworkArn) + d.Set("attachment_policy_rule_number", a.AttachmentPolicyRuleNumber) + d.Set("attachment_type", a.AttachmentType) + d.Set("edge_location", a.EdgeLocation) + d.Set("owner_account_id", a.OwnerAccountId) + d.Set("resource_arn", a.ResourceArn) + d.Set("segment_name", a.SegmentName) + + // VPC arn is not outputted, therefore use resource arn + d.Set("vpc_arn", a.ResourceArn) + + // options + d.Set("options", []interface{}{map[string]interface{}{ + "ipv6_support": aws.BoolValue(opts.Ipv6Support), + }}) + + // subnetArns + d.Set("subnet_arns", subnetArns) + + tags := KeyValueTags(a.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) + + //lintignore:AWSR002 + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { + return diag.Errorf("error setting tags: %s", err) + } + + if err := d.Set("tags_all", tags.Map()); err != nil { + return diag.Errorf("error setting tags_all: %s", err) + } + + return nil +} + +func resourceVpcAttachmentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).NetworkManagerConn + // arn:aws:networkmanager::826255695022:attachment/attachment-0f8fa60d2238d1bd8 + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") + acnt := meta.(*conns.AWSClient).AccountID + arn := fmt.Sprintf("arn:aws:networkmanager::%s:attachment/%s", acnt, d.Id()) + // arn := d.Get("resource_arn").(string) + + if err := UpdateTags(conn, arn, o, n); err != nil { + return diag.Errorf("error updating VPC Attachment (%s) tags: %s", d.Id(), err) + } + } + + if d.HasChangesExcept("tags", "tags_all") { + input := &networkmanager.UpdateVpcAttachmentInput{ + AttachmentId: aws.String(d.Id()), + } + + // TODO: uncomment once service bug is fixed + // if d.HasChange("options") { + // input.Options = expandVpcAttachmentOptions(d.Get("options").([]interface{})) + // } + + if d.HasChange("subnet_arns") { + o, n := d.GetChange("subnet_arns") + if o == nil { + o = new(schema.Set) + } + if n == nil { + n = new(schema.Set) + } + + os := o.(*schema.Set) + ns := n.(*schema.Set) + subnetArnsUpdateAdd := ns.Difference(os) + subnetArnsUpdateRemove := os.Difference(ns) + + if len(subnetArnsUpdateAdd.List()) > 0 { + input.AddSubnetArns = flex.ExpandStringSet(subnetArnsUpdateAdd) + } + + if len(subnetArnsUpdateRemove.List()) > 0 { + input.RemoveSubnetArns = flex.ExpandStringSet(subnetArnsUpdateRemove) + } + } + _, err := conn.UpdateVpcAttachmentWithContext(ctx, input) + + if err != nil { + return diag.Errorf("error updating vpc attachment (%s): %s", d.Id(), err) + } + + if _, err := waitVpcAttachmentUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) update: %s", d.Id(), err) + } + } + + return resourceVpcAttachmentRead(ctx, d, meta) +} + +func expandVpcAttachmentOptions(l []interface{}) *networkmanager.VpcOptions { + if len(l) == 0 || l[0] == nil { + return nil + } + + m := l[0].(map[string]interface{}) + + opts := &networkmanager.VpcOptions{ + Ipv6Support: aws.Bool(bool(m["ipv6_support"].(bool))), + } + + return opts +} + +func resourceVpcAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).NetworkManagerConn + + log.Printf("[DEBUG] Deleting Network Manager VPC Attachment: %s", d.Id()) + + state := d.Get("state").(string) + + if state == networkmanager.AttachmentStatePendingAttachmentAcceptance || state == networkmanager.AttachmentStatePendingTagAcceptance { + return diag.Errorf("error deleting Network Manager VPC Attachment (%s): Cannot delete attachment that is pending acceptance.", d.Id()) + } + + _, err := conn.DeleteAttachmentWithContext(ctx, &networkmanager.DeleteAttachmentInput{ + AttachmentId: aws.String(d.Id()), + }) + + if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { + return nil + } + + if err != nil { + return diag.Errorf("error deleting Network Manager VPC Attachment (%s): %s", d.Id(), err) + } + + if _, err := waitVpcAttachmentDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { + return nil + } + return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) delete: %s", d.Id(), err) + } + + return nil +} + +func VpcAttachmentIDNotFoundError(err error) bool { + return validationExceptionMessageContains(err, networkmanager.ValidationExceptionReasonFieldValidationFailed, "VPC Attachment not found") +} + +func FindVpcAttachmentByID(ctx context.Context, conn *networkmanager.NetworkManager, id string) (*networkmanager.VpcAttachment, error) { + + output, err := conn.GetVpcAttachment(&networkmanager.GetVpcAttachmentInput{ + AttachmentId: aws.String(id), + }) + + if err != nil { + return nil, err + } + + return output.VpcAttachment, nil +} + +func statusVpcAttachmentState(ctx context.Context, conn *networkmanager.NetworkManager, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := FindVpcAttachmentByID(ctx, conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, aws.StringValue(output.Attachment.State), nil + } +} + +func waitVpcAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{networkmanager.AttachmentStateCreating, networkmanager.AttachmentStatePendingNetworkUpdate}, + Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingAttachmentAcceptance}, + Timeout: timeout, + Refresh: statusVpcAttachmentState(ctx, conn, id), + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkmanager.VpcAttachment); ok { + return output, err + } + + return nil, err +} + +func waitVpcAttachmentDeleted(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{networkmanager.AttachmentStateDeleting}, + Target: []string{}, + Timeout: timeout, + Refresh: statusVpcAttachmentState(ctx, conn, id), + NotFoundChecks: 1, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkmanager.VpcAttachment); ok { + return output, err + } + + return nil, err +} + +func waitVpcAttachmentUpdated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{networkmanager.AttachmentStateUpdating}, + Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingTagAcceptance}, + Timeout: timeout, + Refresh: statusVpcAttachmentState(ctx, conn, id), + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkmanager.VpcAttachment); ok { + return output, err + } + + return nil, err +} + +const ( + VpcAttachmentValidationExceptionTimeout = 2 * time.Minute +) diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go new file mode 100644 index 00000000000..c60847a1c0f --- /dev/null +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -0,0 +1,221 @@ +package networkmanager_test + +import ( + "context" + "fmt" + "testing" + + "github.com/aws/aws-sdk-go/service/networkmanager" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + tfnetworkmanager "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" +) + +func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { + resourceName := "aws_networkmanager_vpc_attachment.test" + testExternalProviders := map[string]resource.ExternalProvider{ + "awscc": { + Source: "hashicorp/awscc", + VersionConstraint: "0.29.0", + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ExternalProviders: testExternalProviders, + CheckDestroy: testAccCheckVpcAttachmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCoreNetworkConfig_basicWithOneTag("*", "segment", "shared", false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + ), + }, + { + Config: testAccCoreNetworkConfig_basicWithOneTag("0", "segment", "shared", false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + ), + }, + { + Config: testAccCoreNetworkConfig_basicWithOneTag("*", "segment", "shared", false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + ), + }, + { + Config: testAccCoreNetworkConfig_basicWithTwoTag("*", "segment", "shared", "Name", "test", false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "test"), + ), + }, + { + Config: testAccCoreNetworkConfig_basicWithOneTag("*", "segment", "shared", false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckVpcAttachmentDestroy(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkManagerConn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_networkmanager_vpc_attachment" { + continue + } + + _, err := tfnetworkmanager.FindVpcAttachmentByID(context.TODO(), conn, rs.Primary.ID) + + if tfresource.NotFound(err) { + continue + } + + if err != nil { + return err + } + + return fmt.Errorf("Network Manager Global Network %s still exists", rs.Primary.ID) + } + + return nil +} + +const testAccVpcConfig_multipleSubnets = ` +data "aws_availability_zones" "test" {} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" +} + +variable "subnets" { + default = ["10.0.1.0/24", "10.0.2.0/24"] +} + +resource "aws_subnet" "test" { + count = length(var.subnets) + + vpc_id = aws_vpc.test.id + cidr_block = element(var.subnets, count.index) + availability_zone = "${data.aws_availability_zones.test.names[count.index]}" +} +` + +const testAccCoreNetworkConfig_multipleSubnets = ` +resource "awscc_networkmanager_global_network" "test" {} + +resource "awscc_networkmanager_core_network" "test" { + global_network_id = awscc_networkmanager_global_network.test.id + policy_document = jsonencode(jsondecode(data.aws_networkmanager_core_network_policy_document.test.json)) +} + +data "aws_networkmanager_core_network_policy_document" "test" { + core_network_configuration { + vpn_ecmp_support = false + asn_ranges = ["64512-64555"] + edge_locations { + location = "us-east-1" + asn = 64512 + } + } + + segments { + name = "shared" + description = "SegmentForSharedServices" + require_attachment_acceptance = true + } + + segment_actions { + action = "share" + mode = "attachment-route" + segment = "shared" + share_with = ["*"] + } + + attachment_policies { + rule_number = 1 + condition_logic = "or" + + conditions { + type = "tag-value" + operator = "equals" + key = "segment" + value = "shared" + } + + action { + association_method = "constant" + segment = "shared" + } + } +} +` + +func testAccCoreNetworkConfig_basicWithOneTag(azs, tagKey1, tagValue1 string, ipv6Support bool) string { + return testAccVpcConfig_multipleSubnets + + testAccCoreNetworkConfig_multipleSubnets + fmt.Sprintf(` +resource "aws_networkmanager_vpc_attachment" "test" { + subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) + core_network_id = awscc_networkmanager_core_network.test.id + vpc_arn = aws_vpc.test.arn + + options { + ipv6_support = %[2]t + } + + tags = { + %[3]q = %[4]q + } +} + +resource "aws_networkmanager_attachment_acceptor" "test" { + attachment_id = aws_networkmanager_vpc_attachment.test.id +} +`, azs, ipv6Support, tagKey1, tagValue1) +} + +func testAccCoreNetworkConfig_basicWithTwoTag(azs, tagKey1, tagValue1, tagKey2, tagValue2 string, ipv6Support bool) string { + return testAccVpcConfig_multipleSubnets + + testAccCoreNetworkConfig_multipleSubnets + fmt.Sprintf(` +resource "aws_networkmanager_vpc_attachment" "test" { + subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) + core_network_id = awscc_networkmanager_core_network.test.id + vpc_arn = aws_vpc.test.arn + + options { + ipv6_support = %[2]t + } + + tags = { + %[3]q = %[4]q + %[5]q = %[6]q + } +} + +resource "aws_networkmanager_attachment_acceptor" "test" { + attachment_id = aws_networkmanager_vpc_attachment.test.id +} +`, azs, ipv6Support, tagKey1, tagValue1, tagKey2, tagValue2) +} diff --git a/website/docs/r/networkmanager_attachment_acceptor.html.markdown b/website/docs/r/networkmanager_attachment_acceptor.html.markdown new file mode 100644 index 00000000000..7d21af22b1d --- /dev/null +++ b/website/docs/r/networkmanager_attachment_acceptor.html.markdown @@ -0,0 +1,41 @@ +--- +subcategory: "NetworkManager" +layout: "aws" +page_title: "AWS: aws_networkmanager_attachment_acceptor" +description: |- + Terraform resource for managing an AWS NetworkManager VpcAttachment. +--- + +# Resource: aws_networkmanager_attachment_acceptor + +Terraform resource for managing an AWS NetworkManager Attachment Acceptor. + +## Example Usage + +### Basic Usage + +```terraform +resource "aws_networkmanager_attachment_acceptor" "test" { + attachment_id = aws_networkmanager_vpc_attachment.core_network.id +} +``` + +## Argument Reference + +The following arguments are required: + +* `attachment_id` - (Required) The ID of the attachment. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `attachment_policy_rule_number` - The policy rule number associated with the attachment. +* `attachment_type` - The type of attachment. +* `core_network_arn` - The ARN of a core network. +* `core_network_id` - The id of a core network. +* `edge_location` - The Region where the edge is located. +* `owner_account_id` - The ID of the attachment account owner. +* `resource_arn` - The attachment resource ARN. +* `segment_name` - The name of the segment attachment. +* `state` - The state of the attachment. diff --git a/website/docs/r/networkmanager_vpc_attachment.html.markdown b/website/docs/r/networkmanager_vpc_attachment.html.markdown new file mode 100644 index 00000000000..f4fe2443c3b --- /dev/null +++ b/website/docs/r/networkmanager_vpc_attachment.html.markdown @@ -0,0 +1,72 @@ +--- +subcategory: "NetworkManager" +layout: "aws" +page_title: "AWS: aws_networkmanager_vpc_attachment" +description: |- + Terraform resource for managing an AWS NetworkManager VpcAttachment. +--- + +# Resource: aws_networkmanager_vpc_attachment + +Terraform resource for managing an AWS NetworkManager VpcAttachment. + +## Example Usage + +### Basic Usage + +```terraform +resource "aws_networkmanager_vpc_attachment" "example" { + subnet_arns = [aws_subnet.example.arn] + core_network_id = awscc_networkmanager_core_network.example.id + vpc_arn = aws_vpc.example.arn + + options { + ipv6_support = false + } + + tags = { + "Name" : "my-vpc", + "segment": "example" + } +} +``` + +## Argument Reference + +The following arguments are required: + +* `core_network_id` - (Required) The ID of a core network for the VPC attachment. +* `subnet_arns` - (Required) The subnet ARN of the VPC attachment. +* `vpc_arn` - (Required) The ARN of the VPC. + +The following arguments are optional: + +* `options` - (Optional) Options for the VPC attachment. +* `tags` - (Optional) Key-value tags for the Global Network. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. + +### options + +* `ipv6_support` - (Required) Indicates whether IPv6 is supported. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `attachment_id` - The ID of the attachment. +* `attachment_policy_rule_number` - The policy rule number associated with the attachment. +* `attachment_type` - The type of attachment. +* `core_network_arn` - The ARN of a core network. +* `edge_location` - The Region where the edge is located. +* `owner_account_id` - The ID of the attachment account owner. +* `resource_arn` - The attachment resource ARN. +* `segment_name` - The name of the segment attachment. +* `state` - The state of the attachment. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). + +## Import + +NetworkManager VpcAttachment can be imported using the `attachment_id`, e.g., + +``` +$ terraform import aws_networkmanager_vpc_attachment.example attachment-0f8fa60d2238d1bd8 +``` From b067626f5117dcfcb9af6e48a26a89f4a4169fa5 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 11:16:15 -0400 Subject: [PATCH 02/30] separate test structures --- .../networkmanager/attachment_acceptor.go | 3 +- .../networkmanager/vpc_attachment_test.go | 97 ++++++++++++++----- 2 files changed, 73 insertions(+), 27 deletions(-) diff --git a/internal/service/networkmanager/attachment_acceptor.go b/internal/service/networkmanager/attachment_acceptor.go index 6b924a345cc..cf57963aba4 100644 --- a/internal/service/networkmanager/attachment_acceptor.go +++ b/internal/service/networkmanager/attachment_acceptor.go @@ -84,8 +84,6 @@ func ResourceAttachmentAcceptorCreate(ctx context.Context, d *schema.ResourceDat attachmentId := d.Get("attachment_id").(string) - // check status first and set id if already accepted - input := &networkmanager.AcceptAttachmentInput{ AttachmentId: aws.String(attachmentId), } @@ -100,6 +98,7 @@ func ResourceAttachmentAcceptorCreate(ctx context.Context, d *schema.ResourceDat if state == networkmanager.AttachmentStateAvailable { log.Printf("[WARN] Attachment (%s) already accepted, importing attributes into state without accepting.", d.Id()) + a.Attachment = output.Attachment } else { return diag.Errorf("error accepting Network Manager VPC Attachment: %s", err) } diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go index c60847a1c0f..32fc303b27e 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -6,12 +6,12 @@ import ( "testing" "github.com/aws/aws-sdk-go/service/networkmanager" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfnetworkmanager "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { @@ -31,41 +31,69 @@ func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { CheckDestroy: testAccCheckVpcAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccCoreNetworkConfig_basicWithOneTag("*", "segment", "shared", false), + Config: testAccCoreNetworkConfig_basic("*", false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), ), }, { - Config: testAccCoreNetworkConfig_basicWithOneTag("0", "segment", "shared", false), + Config: testAccCoreNetworkConfig_basic("0", false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), ), }, { - Config: testAccCoreNetworkConfig_basicWithOneTag("*", "segment", "shared", false), + Config: testAccCoreNetworkConfig_basic("*", false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkManagerVpcAttachment_tags(t *testing.T) { + resourceName := "aws_networkmanager_vpc_attachment.test" + testExternalProviders := map[string]resource.ExternalProvider{ + "awscc": { + Source: "hashicorp/awscc", + VersionConstraint: "0.29.0", + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ExternalProviders: testExternalProviders, + CheckDestroy: testAccCheckVpcAttachmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCoreNetworkConfig_oneTag("segment", "shared"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), ), }, { - Config: testAccCoreNetworkConfig_basicWithTwoTag("*", "segment", "shared", "Name", "test", false), + Config: testAccCoreNetworkConfig_twoTag("segment", "shared", "Name", "test"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), resource.TestCheckResourceAttr(resourceName, "tags.Name", "test"), ), }, { - Config: testAccCoreNetworkConfig_basicWithOneTag("*", "segment", "shared", false), + Config: testAccCoreNetworkConfig_oneTag("segment", "shared"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), ), @@ -89,7 +117,7 @@ func testAccCheckVpcAttachmentDestroy(s *terraform.State) error { _, err := tfnetworkmanager.FindVpcAttachmentByID(context.TODO(), conn, rs.Primary.ID) - if tfresource.NotFound(err) { + if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { continue } @@ -97,7 +125,7 @@ func testAccCheckVpcAttachmentDestroy(s *terraform.State) error { return err } - return fmt.Errorf("Network Manager Global Network %s still exists", rs.Primary.ID) + return fmt.Errorf("Network Manager Attachment ID %s still exists", rs.Primary.ID) } return nil @@ -123,7 +151,7 @@ resource "aws_subnet" "test" { } ` -const testAccCoreNetworkConfig_multipleSubnets = ` +const testAccNetworkManagerCoreNetworkConfig = ` resource "awscc_networkmanager_global_network" "test" {} resource "awscc_networkmanager_core_network" "test" { @@ -173,9 +201,9 @@ data "aws_networkmanager_core_network_policy_document" "test" { } ` -func testAccCoreNetworkConfig_basicWithOneTag(azs, tagKey1, tagValue1 string, ipv6Support bool) string { +func testAccCoreNetworkConfig_basic(azs string, ipv6Support bool) string { return testAccVpcConfig_multipleSubnets + - testAccCoreNetworkConfig_multipleSubnets + fmt.Sprintf(` + testAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) core_network_id = awscc_networkmanager_core_network.test.id @@ -184,38 +212,57 @@ resource "aws_networkmanager_vpc_attachment" "test" { options { ipv6_support = %[2]t } +} + +resource "aws_networkmanager_attachment_acceptor" "test" { + attachment_id = aws_networkmanager_vpc_attachment.test.id +} +`, azs, ipv6Support) +} + +func testAccCoreNetworkConfig_oneTag(tagKey1, tagValue1 string) string { + return testAccVpcConfig_multipleSubnets + + testAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` +resource "aws_networkmanager_vpc_attachment" "test" { + subnet_arns = [aws_subnet.test.0.arn] + core_network_id = awscc_networkmanager_core_network.test.id + vpc_arn = aws_vpc.test.arn + + options { + ipv6_support = false + } tags = { - %[3]q = %[4]q + %[1]q = %[2]q } } resource "aws_networkmanager_attachment_acceptor" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id } -`, azs, ipv6Support, tagKey1, tagValue1) +`, tagKey1, tagValue1) } -func testAccCoreNetworkConfig_basicWithTwoTag(azs, tagKey1, tagValue1, tagKey2, tagValue2 string, ipv6Support bool) string { +func testAccCoreNetworkConfig_twoTag(tagKey1, tagValue1, tagKey2, tagValue2 string) string { return testAccVpcConfig_multipleSubnets + - testAccCoreNetworkConfig_multipleSubnets + fmt.Sprintf(` + testAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) + subnet_arns = [aws_subnet.test.0.arn] core_network_id = awscc_networkmanager_core_network.test.id vpc_arn = aws_vpc.test.arn options { - ipv6_support = %[2]t + ipv6_support = false } tags = { + %[1]q = %[2]q %[3]q = %[4]q - %[5]q = %[6]q } } resource "aws_networkmanager_attachment_acceptor" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id } -`, azs, ipv6Support, tagKey1, tagValue1, tagKey2, tagValue2) +`, tagKey1, tagValue1, tagKey2, tagValue2) } From bfec4c7ff40dedda3667911d44f32e7d43d50f92 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 14:34:08 -0400 Subject: [PATCH 03/30] abstract attachment-acceptor to be flexible for other attachment types --- .../networkmanager/attachment_acceptor.go | 100 ++++++++++-------- .../service/networkmanager/vpc_attachment.go | 18 ++-- .../networkmanager/vpc_attachment_test.go | 12 ++- ...kmanager_attachment_acceptor.html.markdown | 5 +- 4 files changed, 76 insertions(+), 59 deletions(-) diff --git a/internal/service/networkmanager/attachment_acceptor.go b/internal/service/networkmanager/attachment_acceptor.go index cf57963aba4..b643fd4e803 100644 --- a/internal/service/networkmanager/attachment_acceptor.go +++ b/internal/service/networkmanager/attachment_acceptor.go @@ -10,10 +10,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) +// AttachmentAcceptor is not specific to AttachmentType. However, querying attachments for status updates is +// To faciliate querying and waiters on specific attachment types, attachment_type required + func ResourceAttachmentAcceptor() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: ResourceAttachmentAcceptorCreate, @@ -36,9 +39,15 @@ func ResourceAttachmentAcceptor() *schema.Resource { Computed: true, }, + // querying attachments requires knowing the type ahead of time + // therefore type is required in provider, though not on the API "attachment_type": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{networkmanager.AttachmentTypeVpc}, false), + // Implement Values() function for validation as mroe types are onboarded to provider + // networkmanager.AttachmentType_Values(), false), }, "core_network_arn": { @@ -83,42 +92,59 @@ func ResourceAttachmentAcceptorCreate(ctx context.Context, d *schema.ResourceDat conn := meta.(*conns.AWSClient).NetworkManagerConn attachmentId := d.Get("attachment_id").(string) + attachmentType := d.Get("attachment_type").(string) + attachment := &networkmanager.Attachment{} + accepted := false + var state string + + if attachmentType == networkmanager.AttachmentTypeVpc { + output, err := FindVpcAttachmentByID(ctx, conn, attachmentId) + + if err != nil { + return diag.Errorf("error finding Network Manager VPC Attachment: %s", err) + } - input := &networkmanager.AcceptAttachmentInput{ - AttachmentId: aws.String(attachmentId), + state = aws.StringValue(output.Attachment.State) + attachment = output.Attachment } - log.Printf("[DEBUG] Accepting Network Manager VPC Attachment: %s", input) - a, err := conn.AcceptAttachmentWithContext(ctx, input) + if state == networkmanager.AttachmentStateAvailable { + accepted = true + log.Printf("[WARN] Attachment (%s) already accepted, importing attributes into state without accepting.", attachmentId) + } - if err != nil { - output, err := FindVpcAttachmentByID(ctx, conn, attachmentId) + if !accepted { + input := &networkmanager.AcceptAttachmentInput{ + AttachmentId: aws.String(attachmentId), + } - state := aws.StringValue(output.Attachment.State) + log.Printf("[DEBUG] Accepting Network Manager Attachment: %s", input) + a, err := conn.AcceptAttachmentWithContext(ctx, input) - if state == networkmanager.AttachmentStateAvailable { - log.Printf("[WARN] Attachment (%s) already accepted, importing attributes into state without accepting.", d.Id()) - a.Attachment = output.Attachment - } else { - return diag.Errorf("error accepting Network Manager VPC Attachment: %s", err) + if err != nil { + return diag.Errorf("error accepting Network Manager Attachment: %s", err) } + + attachment = a.Attachment } d.SetId(attachmentId) - if _, err := waitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - d.SetId("") - return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) + + if attachmentType == networkmanager.AttachmentTypeVpc { + if _, err := waitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + d.SetId("") + return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) + } } - d.Set("core_network_id", a.Attachment.CoreNetworkId) - d.Set("state", a.Attachment.State) - d.Set("core_network_arn", a.Attachment.CoreNetworkArn) - d.Set("attachment_policy_rule_number", a.Attachment.AttachmentPolicyRuleNumber) - d.Set("attachment_type", a.Attachment.AttachmentType) - d.Set("edge_location", a.Attachment.EdgeLocation) - d.Set("owner_account_id", a.Attachment.OwnerAccountId) - d.Set("resource_arn", a.Attachment.ResourceArn) - d.Set("segment_name", a.Attachment.SegmentName) + d.Set("core_network_id", attachment.CoreNetworkId) + d.Set("state", attachment.State) + d.Set("core_network_arn", attachment.CoreNetworkArn) + d.Set("attachment_policy_rule_number", attachment.AttachmentPolicyRuleNumber) + d.Set("edge_location", attachment.EdgeLocation) + d.Set("owner_account_id", attachment.OwnerAccountId) + d.Set("resource_arn", attachment.ResourceArn) + d.Set("segment_name", attachment.SegmentName) return nil } @@ -129,28 +155,12 @@ func ResourceAttachmentAcceptorDelete(ctx context.Context, d *schema.ResourceDat return nil } -func statusAttachmentAcceptorState(ctx context.Context, conn *networkmanager.NetworkManager, id string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - output, err := FindVpcAttachmentByID(ctx, conn, id) - - if tfresource.NotFound(err) { - return nil, "", nil - } - - if err != nil { - return nil, "", err - } - - return output, aws.StringValue(output.Attachment.State), nil - } -} - -func waitAttachmentAcceptorCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { +func waitVpcAttachmentAcceptorCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { stateConf := &resource.StateChangeConf{ Pending: []string{networkmanager.AttachmentStatePendingAttachmentAcceptance, networkmanager.AttachmentStatePendingNetworkUpdate}, Target: []string{networkmanager.AttachmentStateAvailable}, Timeout: timeout, - Refresh: statusVpcAttachmentState(ctx, conn, id), + Refresh: StatusVpcAttachmentState(ctx, conn, id), } outputRaw, err := stateConf.WaitForStateContext(ctx) diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index aee313cc060..9721a930622 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -219,12 +219,11 @@ func resourceVpcAttachmentRead(ctx context.Context, d *schema.ResourceData, meta func resourceVpcAttachmentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn - // arn:aws:networkmanager::826255695022:attachment/attachment-0f8fa60d2238d1bd8 + if d.HasChange("tags_all") { o, n := d.GetChange("tags_all") acnt := meta.(*conns.AWSClient).AccountID arn := fmt.Sprintf("arn:aws:networkmanager::%s:attachment/%s", acnt, d.Id()) - // arn := d.Get("resource_arn").(string) if err := UpdateTags(conn, arn, o, n); err != nil { return diag.Errorf("error updating VPC Attachment (%s) tags: %s", d.Id(), err) @@ -236,10 +235,9 @@ func resourceVpcAttachmentUpdate(ctx context.Context, d *schema.ResourceData, me AttachmentId: aws.String(d.Id()), } - // TODO: uncomment once service bug is fixed - // if d.HasChange("options") { - // input.Options = expandVpcAttachmentOptions(d.Get("options").([]interface{})) - // } + if d.HasChange("options") { + input.Options = expandVpcAttachmentOptions(d.Get("options").([]interface{})) + } if d.HasChange("subnet_arns") { o, n := d.GetChange("subnet_arns") @@ -341,7 +339,7 @@ func FindVpcAttachmentByID(ctx context.Context, conn *networkmanager.NetworkMana return output.VpcAttachment, nil } -func statusVpcAttachmentState(ctx context.Context, conn *networkmanager.NetworkManager, id string) resource.StateRefreshFunc { +func StatusVpcAttachmentState(ctx context.Context, conn *networkmanager.NetworkManager, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { output, err := FindVpcAttachmentByID(ctx, conn, id) @@ -362,7 +360,7 @@ func waitVpcAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkM Pending: []string{networkmanager.AttachmentStateCreating, networkmanager.AttachmentStatePendingNetworkUpdate}, Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingAttachmentAcceptance}, Timeout: timeout, - Refresh: statusVpcAttachmentState(ctx, conn, id), + Refresh: StatusVpcAttachmentState(ctx, conn, id), } outputRaw, err := stateConf.WaitForStateContext(ctx) @@ -379,7 +377,7 @@ func waitVpcAttachmentDeleted(ctx context.Context, conn *networkmanager.NetworkM Pending: []string{networkmanager.AttachmentStateDeleting}, Target: []string{}, Timeout: timeout, - Refresh: statusVpcAttachmentState(ctx, conn, id), + Refresh: StatusVpcAttachmentState(ctx, conn, id), NotFoundChecks: 1, } @@ -397,7 +395,7 @@ func waitVpcAttachmentUpdated(ctx context.Context, conn *networkmanager.NetworkM Pending: []string{networkmanager.AttachmentStateUpdating}, Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingTagAcceptance}, Timeout: timeout, - Refresh: statusVpcAttachmentState(ctx, conn, id), + Refresh: StatusVpcAttachmentState(ctx, conn, id), } outputRaw, err := stateConf.WaitForStateContext(ctx) diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go index 32fc303b27e..d569c21485c 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -38,10 +38,10 @@ func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { ), }, { - Config: testAccCoreNetworkConfig_basic("0", false), + Config: testAccCoreNetworkConfig_basic("0", true), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), - resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), ), }, { @@ -51,6 +51,14 @@ func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), ), }, + // Cannot currently update ipv6 without also updating subnet arns + // { + // Config: testAccCoreNetworkConfig_basic("*", true), + // Check: resource.ComposeTestCheckFunc( + // resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + // resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), + // ), + // }, { ResourceName: resourceName, ImportState: true, diff --git a/website/docs/r/networkmanager_attachment_acceptor.html.markdown b/website/docs/r/networkmanager_attachment_acceptor.html.markdown index 7d21af22b1d..2730e85216a 100644 --- a/website/docs/r/networkmanager_attachment_acceptor.html.markdown +++ b/website/docs/r/networkmanager_attachment_acceptor.html.markdown @@ -16,7 +16,8 @@ Terraform resource for managing an AWS NetworkManager Attachment Acceptor. ```terraform resource "aws_networkmanager_attachment_acceptor" "test" { - attachment_id = aws_networkmanager_vpc_attachment.core_network.id + attachment_id = aws_networkmanager_vpc_attachment.vpc.id + attachment_type = aws_networkmanager_vpc_attachment.vpc.attachment_type } ``` @@ -25,13 +26,13 @@ resource "aws_networkmanager_attachment_acceptor" "test" { The following arguments are required: * `attachment_id` - (Required) The ID of the attachment. +* `attachment_type` - The type of attachment. Valid values can be found in the [AWS Documentation](https://docs.aws.amazon.com/networkmanager/latest/APIReference/API_ListAttachments.html#API_ListAttachments_RequestSyntax) ## Attributes Reference In addition to all arguments above, the following attributes are exported: * `attachment_policy_rule_number` - The policy rule number associated with the attachment. -* `attachment_type` - The type of attachment. * `core_network_arn` - The ARN of a core network. * `core_network_id` - The id of a core network. * `edge_location` - The Region where the edge is located. From 84232db27d61c50208511020a18130f00a6bdeb3 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 14:37:12 -0400 Subject: [PATCH 04/30] test file renamed to acceptor centric name --- .../{vpc_attachment_test.go => attachment_acceptor_test.go} | 2 ++ 1 file changed, 2 insertions(+) rename internal/service/networkmanager/{vpc_attachment_test.go => attachment_acceptor_test.go} (98%) diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/attachment_acceptor_test.go similarity index 98% rename from internal/service/networkmanager/vpc_attachment_test.go rename to internal/service/networkmanager/attachment_acceptor_test.go index d569c21485c..411840a12e2 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -14,6 +14,8 @@ import ( tfnetworkmanager "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" ) +// This test file serves as tests for aws_networkmanager_attachment_acceptor and the following attachment types +// aws_networkmanager_vpc_attachment func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ From 2d4a9b7b908d660b90dec02c931d08da81b0c4cf Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 14:52:42 -0400 Subject: [PATCH 05/30] cannot update ipv6 settings --- .../networkmanager/attachment_acceptor_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index 411840a12e2..4e0b5587581 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -40,10 +40,10 @@ func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { ), }, { - Config: testAccCoreNetworkConfig_basic("0", true), + Config: testAccCoreNetworkConfig_basic("0", false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), - resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), ), }, { @@ -53,7 +53,7 @@ func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), ), }, - // Cannot currently update ipv6 without also updating subnet arns + // Cannot currently update ipv6 // { // Config: testAccCoreNetworkConfig_basic("*", true), // Check: resource.ComposeTestCheckFunc( @@ -225,7 +225,8 @@ resource "aws_networkmanager_vpc_attachment" "test" { } resource "aws_networkmanager_attachment_acceptor" "test" { - attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } `, azs, ipv6Support) } @@ -248,7 +249,8 @@ resource "aws_networkmanager_vpc_attachment" "test" { } resource "aws_networkmanager_attachment_acceptor" "test" { - attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } `, tagKey1, tagValue1) } @@ -272,7 +274,8 @@ resource "aws_networkmanager_vpc_attachment" "test" { } resource "aws_networkmanager_attachment_acceptor" "test" { - attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } `, tagKey1, tagValue1, tagKey2, tagValue2) } From 99e36fe047de4f91ccd8a19a69dca24146b3d1a3 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 14:53:28 -0400 Subject: [PATCH 06/30] changelog new r/networkmanager_vpc_attachment --- .changelog/26227.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/26227.txt diff --git a/.changelog/26227.txt b/.changelog/26227.txt new file mode 100644 index 00000000000..c08900b7dd2 --- /dev/null +++ b/.changelog/26227.txt @@ -0,0 +1,7 @@ +```release-note:new-resource +aws_networkmanager_vpc_attachment +``` + +```release-note:new-resource +aws_networkmanager_attachment_acceptor +``` From ae29118d1356b85e32c323c3c6221012f61d56f9 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 15:02:16 -0400 Subject: [PATCH 07/30] terrafmt --- .../attachment_acceptor_test.go | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index 4e0b5587581..7cad9773381 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -170,44 +170,44 @@ resource "awscc_networkmanager_core_network" "test" { } data "aws_networkmanager_core_network_policy_document" "test" { - core_network_configuration { - vpn_ecmp_support = false - asn_ranges = ["64512-64555"] - edge_locations { - location = "us-east-1" - asn = 64512 - } - } + core_network_configuration { + vpn_ecmp_support = false + asn_ranges = ["64512-64555"] + edge_locations { + location = "us-east-1" + asn = 64512 + } + } - segments { - name = "shared" - description = "SegmentForSharedServices" - require_attachment_acceptance = true - } + segments { + name = "shared" + description = "SegmentForSharedServices" + require_attachment_acceptance = true + } - segment_actions { - action = "share" - mode = "attachment-route" - segment = "shared" - share_with = ["*"] - } + segment_actions { + action = "share" + mode = "attachment-route" + segment = "shared" + share_with = ["*"] + } - attachment_policies { - rule_number = 1 - condition_logic = "or" - - conditions { - type = "tag-value" - operator = "equals" - key = "segment" - value = "shared" - } - - action { - association_method = "constant" - segment = "shared" - } - } + attachment_policies { + rule_number = 1 + condition_logic = "or" + + conditions { + type = "tag-value" + operator = "equals" + key = "segment" + value = "shared" + } + + action { + association_method = "constant" + segment = "shared" + } + } } ` @@ -220,13 +220,13 @@ resource "aws_networkmanager_vpc_attachment" "test" { vpc_arn = aws_vpc.test.arn options { - ipv6_support = %[2]t + ipv6_support = %[2]t } } resource "aws_networkmanager_attachment_acceptor" "test" { - attachment_id = aws_networkmanager_vpc_attachment.test.id - attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } `, azs, ipv6Support) } @@ -240,7 +240,7 @@ resource "aws_networkmanager_vpc_attachment" "test" { vpc_arn = aws_vpc.test.arn options { - ipv6_support = false + ipv6_support = false } tags = { @@ -249,8 +249,8 @@ resource "aws_networkmanager_vpc_attachment" "test" { } resource "aws_networkmanager_attachment_acceptor" "test" { - attachment_id = aws_networkmanager_vpc_attachment.test.id - attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } `, tagKey1, tagValue1) } @@ -274,8 +274,8 @@ resource "aws_networkmanager_vpc_attachment" "test" { } resource "aws_networkmanager_attachment_acceptor" "test" { - attachment_id = aws_networkmanager_vpc_attachment.test.id - attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } `, tagKey1, tagValue1, tagKey2, tagValue2) } From b89ff3d5831ef1e91190875f7b48249212a21dbf Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 15:03:21 -0400 Subject: [PATCH 08/30] semgrep fix --- internal/service/networkmanager/attachment_acceptor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index 7cad9773381..1be33fb7e9b 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -125,7 +125,7 @@ func testAccCheckVpcAttachmentDestroy(s *terraform.State) error { continue } - _, err := tfnetworkmanager.FindVpcAttachmentByID(context.TODO(), conn, rs.Primary.ID) + _, err := tfnetworkmanager.FindVpcAttachmentByID(context.Background(), conn, rs.Primary.ID) if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { continue From 54817ebfaac12c070e6d567383d819528682fa4c Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 15:22:38 -0400 Subject: [PATCH 09/30] linting --- .../networkmanager/attachment_acceptor.go | 20 +------------------ .../attachment_acceptor_test.go | 20 +++++++++---------- .../service/networkmanager/vpc_attachment.go | 4 ++-- 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/internal/service/networkmanager/attachment_acceptor.go b/internal/service/networkmanager/attachment_acceptor.go index b643fd4e803..d14b5593ced 100644 --- a/internal/service/networkmanager/attachment_acceptor.go +++ b/internal/service/networkmanager/attachment_acceptor.go @@ -8,7 +8,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/networkmanager" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -131,7 +130,7 @@ func ResourceAttachmentAcceptorCreate(ctx context.Context, d *schema.ResourceDat d.SetId(attachmentId) if attachmentType == networkmanager.AttachmentTypeVpc { - if _, err := waitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := WaitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { d.SetId("") return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) } @@ -154,20 +153,3 @@ func ResourceAttachmentAcceptorDelete(ctx context.Context, d *schema.ResourceDat return nil } - -func waitVpcAttachmentAcceptorCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { - stateConf := &resource.StateChangeConf{ - Pending: []string{networkmanager.AttachmentStatePendingAttachmentAcceptance, networkmanager.AttachmentStatePendingNetworkUpdate}, - Target: []string{networkmanager.AttachmentStateAvailable}, - Timeout: timeout, - Refresh: StatusVpcAttachmentState(ctx, conn, id), - } - - outputRaw, err := stateConf.WaitForStateContext(ctx) - - if output, ok := outputRaw.(*networkmanager.VpcAttachment); ok { - return output, err - } - - return nil, err -} diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index 1be33fb7e9b..4a4ea18dde2 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -16,7 +16,7 @@ import ( // This test file serves as tests for aws_networkmanager_attachment_acceptor and the following attachment types // aws_networkmanager_vpc_attachment -func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { +func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentBasic(t *testing.T) { resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -70,7 +70,7 @@ func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { }) } -func TestAccNetworkManagerVpcAttachment_tags(t *testing.T) { +func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentTags(t *testing.T) { resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -141,7 +141,7 @@ func testAccCheckVpcAttachmentDestroy(s *terraform.State) error { return nil } -const testAccVpcConfig_multipleSubnets = ` +const TestAccVpcConfig_multipleSubnets = ` data "aws_availability_zones" "test" {} resource "aws_vpc" "test" { @@ -161,7 +161,7 @@ resource "aws_subnet" "test" { } ` -const testAccNetworkManagerCoreNetworkConfig = ` +const TestAccNetworkManagerCoreNetworkConfig = ` resource "awscc_networkmanager_global_network" "test" {} resource "awscc_networkmanager_core_network" "test" { @@ -212,8 +212,8 @@ data "aws_networkmanager_core_network_policy_document" "test" { ` func testAccCoreNetworkConfig_basic(azs string, ipv6Support bool) string { - return testAccVpcConfig_multipleSubnets + - testAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` + return TestAccVpcConfig_multipleSubnets + + TestAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) core_network_id = awscc_networkmanager_core_network.test.id @@ -232,8 +232,8 @@ resource "aws_networkmanager_attachment_acceptor" "test" { } func testAccCoreNetworkConfig_oneTag(tagKey1, tagValue1 string) string { - return testAccVpcConfig_multipleSubnets + - testAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` + return TestAccVpcConfig_multipleSubnets + + TestAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = [aws_subnet.test.0.arn] core_network_id = awscc_networkmanager_core_network.test.id @@ -256,8 +256,8 @@ resource "aws_networkmanager_attachment_acceptor" "test" { } func testAccCoreNetworkConfig_twoTag(tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return testAccVpcConfig_multipleSubnets + - testAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` + return TestAccVpcConfig_multipleSubnets + + TestAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = [aws_subnet.test.0.arn] core_network_id = awscc_networkmanager_core_network.test.id diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 9721a930622..84200317f61 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -152,7 +152,7 @@ func resourceVpcAttachmentCreate(ctx context.Context, d *schema.ResourceData, me d.SetId(aws.StringValue(output.VpcAttachment.Attachment.AttachmentId)) - if _, err := waitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := WaitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) } @@ -355,7 +355,7 @@ func StatusVpcAttachmentState(ctx context.Context, conn *networkmanager.NetworkM } } -func waitVpcAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { +func WaitVpcAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { stateConf := &resource.StateChangeConf{ Pending: []string{networkmanager.AttachmentStateCreating, networkmanager.AttachmentStatePendingNetworkUpdate}, Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingAttachmentAcceptance}, From 32a9e4b7324edd8c5619f939a420c9f124428c3b Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 15:44:16 -0400 Subject: [PATCH 10/30] linting --- internal/provider/provider.go | 2 +- .../networkmanager/attachment_acceptor.go | 8 +-- .../attachment_acceptor_test.go | 30 +++++----- .../service/networkmanager/vpc_attachment.go | 56 +++++++++---------- ...kmanager_attachment_acceptor.html.markdown | 6 +- ...etworkmanager_vpc_attachment.html.markdown | 17 ++---- 6 files changed, 53 insertions(+), 66 deletions(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 0f65d73adbe..b7aab64b2c1 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -1744,7 +1744,7 @@ func New(_ context.Context) (*schema.Provider, error) { "aws_networkmanager_site": networkmanager.ResourceSite(), "aws_networkmanager_transit_gateway_connect_peer_association": networkmanager.ResourceTransitGatewayConnectPeerAssociation(), "aws_networkmanager_transit_gateway_registration": networkmanager.ResourceTransitGatewayRegistration(), - "aws_networkmanager_vpc_attachment": networkmanager.ResourceVpcAttachment(), + "aws_networkmanager_vpc_attachment": networkmanager.ResourceVPCAttachment(), "aws_opensearch_domain": opensearch.ResourceDomain(), "aws_opensearch_domain_policy": opensearch.ResourceDomainPolicy(), diff --git a/internal/service/networkmanager/attachment_acceptor.go b/internal/service/networkmanager/attachment_acceptor.go index d14b5593ced..ec7613b3a03 100644 --- a/internal/service/networkmanager/attachment_acceptor.go +++ b/internal/service/networkmanager/attachment_acceptor.go @@ -14,7 +14,7 @@ import ( ) // AttachmentAcceptor is not specific to AttachmentType. However, querying attachments for status updates is -// To faciliate querying and waiters on specific attachment types, attachment_type required +// To facilitate querying and waiters on specific attachment types, attachment_type required func ResourceAttachmentAcceptor() *schema.Resource { return &schema.Resource{ @@ -45,7 +45,7 @@ func ResourceAttachmentAcceptor() *schema.Resource { Required: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{networkmanager.AttachmentTypeVpc}, false), - // Implement Values() function for validation as mroe types are onboarded to provider + // Implement Values() function for validation as more types are onboarded to provider // networkmanager.AttachmentType_Values(), false), }, @@ -97,7 +97,7 @@ func ResourceAttachmentAcceptorCreate(ctx context.Context, d *schema.ResourceDat var state string if attachmentType == networkmanager.AttachmentTypeVpc { - output, err := FindVpcAttachmentByID(ctx, conn, attachmentId) + output, err := FindVPCAttachmentByID(ctx, conn, attachmentId) if err != nil { return diag.Errorf("error finding Network Manager VPC Attachment: %s", err) @@ -130,7 +130,7 @@ func ResourceAttachmentAcceptorCreate(ctx context.Context, d *schema.ResourceDat d.SetId(attachmentId) if attachmentType == networkmanager.AttachmentTypeVpc { - if _, err := WaitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := WaitVPCAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { d.SetId("") return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) } diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index 4a4ea18dde2..39b8d28abf6 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -30,7 +30,7 @@ func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentBasic(t *testing.T) { ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, ExternalProviders: testExternalProviders, - CheckDestroy: testAccCheckVpcAttachmentDestroy, + CheckDestroy: testAccCheckVPCAttachmentDestroy, Steps: []resource.TestStep{ { Config: testAccCoreNetworkConfig_basic("*", false), @@ -84,7 +84,7 @@ func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentTags(t *testing.T) { ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, ExternalProviders: testExternalProviders, - CheckDestroy: testAccCheckVpcAttachmentDestroy, + CheckDestroy: testAccCheckVPCAttachmentDestroy, Steps: []resource.TestStep{ { Config: testAccCoreNetworkConfig_oneTag("segment", "shared"), @@ -117,7 +117,7 @@ func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentTags(t *testing.T) { }) } -func testAccCheckVpcAttachmentDestroy(s *terraform.State) error { +func testAccCheckVPCAttachmentDestroy(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkManagerConn for _, rs := range s.RootModule().Resources { @@ -125,7 +125,7 @@ func testAccCheckVpcAttachmentDestroy(s *terraform.State) error { continue } - _, err := tfnetworkmanager.FindVpcAttachmentByID(context.Background(), conn, rs.Primary.ID) + _, err := tfnetworkmanager.FindVPCAttachmentByID(context.Background(), conn, rs.Primary.ID) if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { continue @@ -141,7 +141,7 @@ func testAccCheckVpcAttachmentDestroy(s *terraform.State) error { return nil } -const TestAccVpcConfig_multipleSubnets = ` +const TestAccVPCConfig_multipleSubnets = ` data "aws_availability_zones" "test" {} resource "aws_vpc" "test" { @@ -157,11 +157,11 @@ resource "aws_subnet" "test" { vpc_id = aws_vpc.test.id cidr_block = element(var.subnets, count.index) - availability_zone = "${data.aws_availability_zones.test.names[count.index]}" + availability_zone = data.aws_availability_zones.test.names[count.index] } ` -const TestAccNetworkManagerCoreNetworkConfig = ` +const TestAccCoreNetworkConfig = ` resource "awscc_networkmanager_global_network" "test" {} resource "awscc_networkmanager_core_network" "test" { @@ -212,8 +212,8 @@ data "aws_networkmanager_core_network_policy_document" "test" { ` func testAccCoreNetworkConfig_basic(azs string, ipv6Support bool) string { - return TestAccVpcConfig_multipleSubnets + - TestAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` + return TestAccVPCConfig_multipleSubnets + + TestAccCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) core_network_id = awscc_networkmanager_core_network.test.id @@ -232,10 +232,10 @@ resource "aws_networkmanager_attachment_acceptor" "test" { } func testAccCoreNetworkConfig_oneTag(tagKey1, tagValue1 string) string { - return TestAccVpcConfig_multipleSubnets + - TestAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` + return TestAccVPCConfig_multipleSubnets + + TestAccCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = [aws_subnet.test.0.arn] + subnet_arns = [aws_subnet.test[0].arn] core_network_id = awscc_networkmanager_core_network.test.id vpc_arn = aws_vpc.test.arn @@ -256,10 +256,10 @@ resource "aws_networkmanager_attachment_acceptor" "test" { } func testAccCoreNetworkConfig_twoTag(tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return TestAccVpcConfig_multipleSubnets + - TestAccNetworkManagerCoreNetworkConfig + fmt.Sprintf(` + return TestAccVPCConfig_multipleSubnets + + TestAccCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = [aws_subnet.test.0.arn] + subnet_arns = [aws_subnet.test[0].arn] core_network_id = awscc_networkmanager_core_network.test.id vpc_arn = aws_vpc.test.arn diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 84200317f61..c93274f18f1 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -19,12 +19,12 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -func ResourceVpcAttachment() *schema.Resource { +func ResourceVPCAttachment() *schema.Resource { return &schema.Resource{ - CreateWithoutTimeout: resourceVpcAttachmentCreate, - ReadWithoutTimeout: resourceVpcAttachmentRead, - UpdateWithoutTimeout: resourceVpcAttachmentUpdate, - DeleteWithoutTimeout: resourceVpcAttachmentDelete, + CreateWithoutTimeout: resourceVPCAttachmentCreate, + ReadWithoutTimeout: resourceVPCAttachmentRead, + UpdateWithoutTimeout: resourceVPCAttachmentUpdate, + DeleteWithoutTimeout: resourceVPCAttachmentDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -121,7 +121,7 @@ func ResourceVpcAttachment() *schema.Resource { } } -func resourceVpcAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVPCAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) @@ -152,14 +152,14 @@ func resourceVpcAttachmentCreate(ctx context.Context, d *schema.ResourceData, me d.SetId(aws.StringValue(output.VpcAttachment.Attachment.AttachmentId)) - if _, err := WaitVpcAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := WaitVPCAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) } - return resourceVpcAttachmentRead(ctx, d, meta) + return resourceVPCAttachmentRead(ctx, d, meta) } -func resourceVpcAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -217,7 +217,7 @@ func resourceVpcAttachmentRead(ctx context.Context, d *schema.ResourceData, meta return nil } -func resourceVpcAttachmentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVPCAttachmentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn if d.HasChange("tags_all") { @@ -236,7 +236,7 @@ func resourceVpcAttachmentUpdate(ctx context.Context, d *schema.ResourceData, me } if d.HasChange("options") { - input.Options = expandVpcAttachmentOptions(d.Get("options").([]interface{})) + input.Options = expandVPCAttachmentOptions(d.Get("options").([]interface{})) } if d.HasChange("subnet_arns") { @@ -267,15 +267,15 @@ func resourceVpcAttachmentUpdate(ctx context.Context, d *schema.ResourceData, me return diag.Errorf("error updating vpc attachment (%s): %s", d.Id(), err) } - if _, err := waitVpcAttachmentUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + if _, err := waitVPCAttachmentUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) update: %s", d.Id(), err) } } - return resourceVpcAttachmentRead(ctx, d, meta) + return resourceVPCAttachmentRead(ctx, d, meta) } -func expandVpcAttachmentOptions(l []interface{}) *networkmanager.VpcOptions { +func expandVPCAttachmentOptions(l []interface{}) *networkmanager.VpcOptions { if len(l) == 0 || l[0] == nil { return nil } @@ -289,7 +289,7 @@ func expandVpcAttachmentOptions(l []interface{}) *networkmanager.VpcOptions { return opts } -func resourceVpcAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVPCAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn log.Printf("[DEBUG] Deleting Network Manager VPC Attachment: %s", d.Id()) @@ -312,7 +312,7 @@ func resourceVpcAttachmentDelete(ctx context.Context, d *schema.ResourceData, me return diag.Errorf("error deleting Network Manager VPC Attachment (%s): %s", d.Id(), err) } - if _, err := waitVpcAttachmentDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + if _, err := waitVPCAttachmentDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { return nil } @@ -322,11 +322,11 @@ func resourceVpcAttachmentDelete(ctx context.Context, d *schema.ResourceData, me return nil } -func VpcAttachmentIDNotFoundError(err error) bool { +func VPCAttachmentIDNotFoundError(err error) bool { return validationExceptionMessageContains(err, networkmanager.ValidationExceptionReasonFieldValidationFailed, "VPC Attachment not found") } -func FindVpcAttachmentByID(ctx context.Context, conn *networkmanager.NetworkManager, id string) (*networkmanager.VpcAttachment, error) { +func FindVPCAttachmentByID(ctx context.Context, conn *networkmanager.NetworkManager, id string) (*networkmanager.VpcAttachment, error) { output, err := conn.GetVpcAttachment(&networkmanager.GetVpcAttachmentInput{ AttachmentId: aws.String(id), @@ -339,9 +339,9 @@ func FindVpcAttachmentByID(ctx context.Context, conn *networkmanager.NetworkMana return output.VpcAttachment, nil } -func StatusVpcAttachmentState(ctx context.Context, conn *networkmanager.NetworkManager, id string) resource.StateRefreshFunc { +func StatusVPCAttachmentState(ctx context.Context, conn *networkmanager.NetworkManager, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindVpcAttachmentByID(ctx, conn, id) + output, err := FindVPCAttachmentByID(ctx, conn, id) if tfresource.NotFound(err) { return nil, "", nil @@ -355,12 +355,12 @@ func StatusVpcAttachmentState(ctx context.Context, conn *networkmanager.NetworkM } } -func WaitVpcAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { +func WaitVPCAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { stateConf := &resource.StateChangeConf{ Pending: []string{networkmanager.AttachmentStateCreating, networkmanager.AttachmentStatePendingNetworkUpdate}, Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingAttachmentAcceptance}, Timeout: timeout, - Refresh: StatusVpcAttachmentState(ctx, conn, id), + Refresh: StatusVPCAttachmentState(ctx, conn, id), } outputRaw, err := stateConf.WaitForStateContext(ctx) @@ -372,12 +372,12 @@ func WaitVpcAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkM return nil, err } -func waitVpcAttachmentDeleted(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { +func waitVPCAttachmentDeleted(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { stateConf := &resource.StateChangeConf{ Pending: []string{networkmanager.AttachmentStateDeleting}, Target: []string{}, Timeout: timeout, - Refresh: StatusVpcAttachmentState(ctx, conn, id), + Refresh: StatusVPCAttachmentState(ctx, conn, id), NotFoundChecks: 1, } @@ -390,12 +390,12 @@ func waitVpcAttachmentDeleted(ctx context.Context, conn *networkmanager.NetworkM return nil, err } -func waitVpcAttachmentUpdated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { +func waitVPCAttachmentUpdated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { stateConf := &resource.StateChangeConf{ Pending: []string{networkmanager.AttachmentStateUpdating}, Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingTagAcceptance}, Timeout: timeout, - Refresh: StatusVpcAttachmentState(ctx, conn, id), + Refresh: StatusVPCAttachmentState(ctx, conn, id), } outputRaw, err := stateConf.WaitForStateContext(ctx) @@ -406,7 +406,3 @@ func waitVpcAttachmentUpdated(ctx context.Context, conn *networkmanager.NetworkM return nil, err } - -const ( - VpcAttachmentValidationExceptionTimeout = 2 * time.Minute -) diff --git a/website/docs/r/networkmanager_attachment_acceptor.html.markdown b/website/docs/r/networkmanager_attachment_acceptor.html.markdown index 2730e85216a..74d6619f4d3 100644 --- a/website/docs/r/networkmanager_attachment_acceptor.html.markdown +++ b/website/docs/r/networkmanager_attachment_acceptor.html.markdown @@ -1,5 +1,5 @@ --- -subcategory: "NetworkManager" +subcategory: "Network Manager" layout: "aws" page_title: "AWS: aws_networkmanager_attachment_acceptor" description: |- @@ -16,8 +16,8 @@ Terraform resource for managing an AWS NetworkManager Attachment Acceptor. ```terraform resource "aws_networkmanager_attachment_acceptor" "test" { - attachment_id = aws_networkmanager_vpc_attachment.vpc.id - attachment_type = aws_networkmanager_vpc_attachment.vpc.attachment_type + attachment_id = aws_networkmanager_vpc_attachment.vpc.id + attachment_type = aws_networkmanager_vpc_attachment.vpc.attachment_type } ``` diff --git a/website/docs/r/networkmanager_vpc_attachment.html.markdown b/website/docs/r/networkmanager_vpc_attachment.html.markdown index f4fe2443c3b..c7c0aa61d0c 100644 --- a/website/docs/r/networkmanager_vpc_attachment.html.markdown +++ b/website/docs/r/networkmanager_vpc_attachment.html.markdown @@ -1,5 +1,5 @@ --- -subcategory: "NetworkManager" +subcategory: "Network Manager" layout: "aws" page_title: "AWS: aws_networkmanager_vpc_attachment" description: |- @@ -16,18 +16,9 @@ Terraform resource for managing an AWS NetworkManager VpcAttachment. ```terraform resource "aws_networkmanager_vpc_attachment" "example" { - subnet_arns = [aws_subnet.example.arn] - core_network_id = awscc_networkmanager_core_network.example.id - vpc_arn = aws_vpc.example.arn - - options { - ipv6_support = false - } - - tags = { - "Name" : "my-vpc", - "segment": "example" - } + subnet_arns = [aws_subnet.example.arn] + core_network_id = awscc_networkmanager_core_network.example.id + vpc_arn = aws_vpc.example.arn } ``` From f11c1961218cba604749bb358a806398198b550a Mon Sep 17 00:00:00 2001 From: drewmullen Date: Wed, 10 Aug 2022 22:41:01 -0400 Subject: [PATCH 11/30] linting --- internal/service/networkmanager/attachment_acceptor_test.go | 3 ++- internal/service/networkmanager/vpc_attachment.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index 39b8d28abf6..581060d9093 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -143,6 +143,7 @@ func testAccCheckVPCAttachmentDestroy(s *terraform.State) error { const TestAccVPCConfig_multipleSubnets = ` data "aws_availability_zones" "test" {} +data "aws_region" "test" {} resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -174,7 +175,7 @@ data "aws_networkmanager_core_network_policy_document" "test" { vpn_ecmp_support = false asn_ranges = ["64512-64555"] edge_locations { - location = "us-east-1" + location = data.aws_region.test.name asn = 64512 } } diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index c93274f18f1..025ddc883aa 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -223,7 +223,8 @@ func resourceVPCAttachmentUpdate(ctx context.Context, d *schema.ResourceData, me if d.HasChange("tags_all") { o, n := d.GetChange("tags_all") acnt := meta.(*conns.AWSClient).AccountID - arn := fmt.Sprintf("arn:aws:networkmanager::%s:attachment/%s", acnt, d.Id()) + part := meta.(*conns.AWSClient).Partition + arn := fmt.Sprintf("arn:%s:networkmanager::%s:attachment/%s", part, acnt, d.Id()) if err := UpdateTags(conn, arn, o, n); err != nil { return diag.Errorf("error updating VPC Attachment (%s) tags: %s", d.Id(), err) From aaa75814a695ab6a32037b5bc550b18d3e32c230 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Thu, 11 Aug 2022 08:07:13 -0400 Subject: [PATCH 12/30] rm unnecessary type cast --- internal/service/networkmanager/vpc_attachment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 025ddc883aa..7a3e4bfe644 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -284,7 +284,7 @@ func expandVPCAttachmentOptions(l []interface{}) *networkmanager.VpcOptions { m := l[0].(map[string]interface{}) opts := &networkmanager.VpcOptions{ - Ipv6Support: aws.Bool(bool(m["ipv6_support"].(bool))), + Ipv6Support: aws.Bool(m["ipv6_support"].(bool)), } return opts From 0c3cd95215833793bf1b361c278e79cb11a38bc4 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Thu, 11 Aug 2022 11:30:16 -0400 Subject: [PATCH 13/30] can only use ipv6 support if changing subnet_arns --- .../networkmanager/attachment_acceptor_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index 581060d9093..f39dc1aa849 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -40,10 +40,10 @@ func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentBasic(t *testing.T) { ), }, { - Config: testAccCoreNetworkConfig_basic("0", false), + Config: testAccCoreNetworkConfig_basic("0", true), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), - resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), ), }, { @@ -53,7 +53,7 @@ func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentBasic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), ), }, - // Cannot currently update ipv6 + // Cannot currently update ipv6 on its own, must also update subnet_arn // { // Config: testAccCoreNetworkConfig_basic("*", true), // Check: resource.ComposeTestCheckFunc( @@ -146,7 +146,12 @@ data "aws_availability_zones" "test" {} data "aws_region" "test" {} resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" + cidr_block = "10.0.0.0/16" + assign_generated_ipv6_cidr_block = true +} + +locals { + ipv6_cidrs = cidrsubnets(aws_vpc.test.ipv6_cidr_block, 8, 8) } variable "subnets" { @@ -159,6 +164,9 @@ resource "aws_subnet" "test" { vpc_id = aws_vpc.test.id cidr_block = element(var.subnets, count.index) availability_zone = data.aws_availability_zones.test.names[count.index] + + assign_ipv6_address_on_creation = true + ipv6_cidr_block = local.ipv6_cidrs[count.index] } ` From 4d5fe8b242db8634b0ece754282f86fcda375449 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Thu, 11 Aug 2022 12:18:44 -0400 Subject: [PATCH 14/30] rename resource "accepter" --- .changelog/26227.txt | 2 +- internal/provider/provider.go | 2 +- ...attachment_acceptor.go => attachment_accepter.go} | 12 ++++++------ .../networkmanager/attachment_acceptor_test.go | 12 ++++++------ ...networkmanager_attachment_accepter.html.markdown} | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) rename internal/service/networkmanager/{attachment_acceptor.go => attachment_accepter.go} (91%) rename website/docs/r/{networkmanager_attachment_acceptor.html.markdown => networkmanager_attachment_accepter.html.markdown} (87%) diff --git a/.changelog/26227.txt b/.changelog/26227.txt index c08900b7dd2..e44bdd9a08c 100644 --- a/.changelog/26227.txt +++ b/.changelog/26227.txt @@ -3,5 +3,5 @@ aws_networkmanager_vpc_attachment ``` ```release-note:new-resource -aws_networkmanager_attachment_acceptor +aws_networkmanager_attachment_accepter ``` diff --git a/internal/provider/provider.go b/internal/provider/provider.go index b7aab64b2c1..ed33db9c8fd 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -1734,7 +1734,7 @@ func New(_ context.Context) (*schema.Provider, error) { "aws_networkfirewall_resource_policy": networkfirewall.ResourceResourcePolicy(), "aws_networkfirewall_rule_group": networkfirewall.ResourceRuleGroup(), - "aws_networkmanager_attachment_acceptor": networkmanager.ResourceAttachmentAcceptor(), + "aws_networkmanager_attachment_accepter": networkmanager.ResourceAttachmentAccepter(), "aws_networkmanager_connection": networkmanager.ResourceConnection(), "aws_networkmanager_customer_gateway_association": networkmanager.ResourceCustomerGatewayAssociation(), "aws_networkmanager_device": networkmanager.ResourceDevice(), diff --git a/internal/service/networkmanager/attachment_acceptor.go b/internal/service/networkmanager/attachment_accepter.go similarity index 91% rename from internal/service/networkmanager/attachment_acceptor.go rename to internal/service/networkmanager/attachment_accepter.go index ec7613b3a03..fb981b50af1 100644 --- a/internal/service/networkmanager/attachment_acceptor.go +++ b/internal/service/networkmanager/attachment_accepter.go @@ -13,14 +13,14 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" ) -// AttachmentAcceptor is not specific to AttachmentType. However, querying attachments for status updates is +// AttachmentAccepter is not specific to AttachmentType. However, querying attachments for status updates is // To facilitate querying and waiters on specific attachment types, attachment_type required -func ResourceAttachmentAcceptor() *schema.Resource { +func ResourceAttachmentAccepter() *schema.Resource { return &schema.Resource{ - CreateWithoutTimeout: ResourceAttachmentAcceptorCreate, + CreateWithoutTimeout: ResourceAttachmentAccepterCreate, ReadWithoutTimeout: schema.NoopContext, - DeleteWithoutTimeout: ResourceAttachmentAcceptorDelete, + DeleteWithoutTimeout: ResourceAttachmentAccepterDelete, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), @@ -87,7 +87,7 @@ func ResourceAttachmentAcceptor() *schema.Resource { } } -func ResourceAttachmentAcceptorCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func ResourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn attachmentId := d.Get("attachment_id").(string) @@ -148,7 +148,7 @@ func ResourceAttachmentAcceptorCreate(ctx context.Context, d *schema.ResourceDat return nil } -func ResourceAttachmentAcceptorDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func ResourceAttachmentAccepterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[WARN] Attachment (%s) not deleted, removing from state.", d.Id()) return nil diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index f39dc1aa849..5fdbf589785 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -14,9 +14,9 @@ import ( tfnetworkmanager "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" ) -// This test file serves as tests for aws_networkmanager_attachment_acceptor and the following attachment types +// This test file serves as tests for aws_networkmanager_attachment_accepter and the following attachment types // aws_networkmanager_vpc_attachment -func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentBasic(t *testing.T) { +func TestAccNetworkManagerAttachmentAccepter_vpcAttachmentBasic(t *testing.T) { resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -70,7 +70,7 @@ func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentBasic(t *testing.T) { }) } -func TestAccNetworkManagerAttachmentAcceptor_vpcAttachmentTags(t *testing.T) { +func TestAccNetworkManagerAttachmentAccepter_vpcAttachmentTags(t *testing.T) { resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -233,7 +233,7 @@ resource "aws_networkmanager_vpc_attachment" "test" { } } -resource "aws_networkmanager_attachment_acceptor" "test" { +resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } @@ -257,7 +257,7 @@ resource "aws_networkmanager_vpc_attachment" "test" { } } -resource "aws_networkmanager_attachment_acceptor" "test" { +resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } @@ -282,7 +282,7 @@ resource "aws_networkmanager_vpc_attachment" "test" { } } -resource "aws_networkmanager_attachment_acceptor" "test" { +resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } diff --git a/website/docs/r/networkmanager_attachment_acceptor.html.markdown b/website/docs/r/networkmanager_attachment_accepter.html.markdown similarity index 87% rename from website/docs/r/networkmanager_attachment_acceptor.html.markdown rename to website/docs/r/networkmanager_attachment_accepter.html.markdown index 74d6619f4d3..e72a190c2c4 100644 --- a/website/docs/r/networkmanager_attachment_acceptor.html.markdown +++ b/website/docs/r/networkmanager_attachment_accepter.html.markdown @@ -1,21 +1,21 @@ --- subcategory: "Network Manager" layout: "aws" -page_title: "AWS: aws_networkmanager_attachment_acceptor" +page_title: "AWS: aws_networkmanager_attachment_accepter" description: |- Terraform resource for managing an AWS NetworkManager VpcAttachment. --- -# Resource: aws_networkmanager_attachment_acceptor +# Resource: aws_networkmanager_attachment_accepter -Terraform resource for managing an AWS NetworkManager Attachment Acceptor. +Terraform resource for managing an AWS NetworkManager Attachment Accepter. ## Example Usage ### Basic Usage ```terraform -resource "aws_networkmanager_attachment_acceptor" "test" { +resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.vpc.id attachment_type = aws_networkmanager_vpc_attachment.vpc.attachment_type } From ad34837d4a9dfbd4e0d69b4fb32bee872fff08b3 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Mon, 15 Aug 2022 10:36:16 -0400 Subject: [PATCH 15/30] separate tests across resources, provide basic test --- .../networkmanager/attachment_accepter.go | 20 +- .../attachment_acceptor_test.go | 256 +------------ .../service/networkmanager/vpc_attachment.go | 22 +- .../networkmanager/vpc_attachment_test.go | 335 ++++++++++++++++++ 4 files changed, 360 insertions(+), 273 deletions(-) create mode 100644 internal/service/networkmanager/vpc_attachment_test.go diff --git a/internal/service/networkmanager/attachment_accepter.go b/internal/service/networkmanager/attachment_accepter.go index fb981b50af1..e8fa8f50ca0 100644 --- a/internal/service/networkmanager/attachment_accepter.go +++ b/internal/service/networkmanager/attachment_accepter.go @@ -13,8 +13,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" ) -// AttachmentAccepter is not specific to AttachmentType. However, querying attachments for status updates is -// To facilitate querying and waiters on specific attachment types, attachment_type required +// AttachmentAccepter does not require AttachmentType. However, querying attachments for status updates requires knowing tyupe +// To facilitate querying and waiters on specific attachment types, attachment_type set to required func ResourceAttachmentAccepter() *schema.Resource { return &schema.Resource{ @@ -41,10 +41,12 @@ func ResourceAttachmentAccepter() *schema.Resource { // querying attachments requires knowing the type ahead of time // therefore type is required in provider, though not on the API "attachment_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{networkmanager.AttachmentTypeVpc}, false), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + networkmanager.AttachmentTypeVpc, + }, false), // Implement Values() function for validation as more types are onboarded to provider // networkmanager.AttachmentType_Values(), false), }, @@ -100,7 +102,7 @@ func ResourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceDat output, err := FindVPCAttachmentByID(ctx, conn, attachmentId) if err != nil { - return diag.Errorf("error finding Network Manager VPC Attachment: %s", err) + return diag.Errorf("Finding Network Manager VPC Attachment: %s", err) } state = aws.StringValue(output.Attachment.State) @@ -121,7 +123,7 @@ func ResourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceDat a, err := conn.AcceptAttachmentWithContext(ctx, input) if err != nil { - return diag.Errorf("error accepting Network Manager Attachment: %s", err) + return diag.Errorf("Accepting Network Manager Attachment: %s", err) } attachment = a.Attachment @@ -132,7 +134,7 @@ func ResourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceDat if attachmentType == networkmanager.AttachmentTypeVpc { if _, err := WaitVPCAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { d.SetId("") - return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) + return diag.Errorf("Waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) } } diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index 5fdbf589785..da59de7eb97 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -1,23 +1,15 @@ package networkmanager_test import ( - "context" - "fmt" "testing" "github.com/aws/aws-sdk-go/service/networkmanager" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/internal/conns" - tfnetworkmanager "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" ) -// This test file serves as tests for aws_networkmanager_attachment_accepter and the following attachment types -// aws_networkmanager_vpc_attachment func TestAccNetworkManagerAttachmentAccepter_vpcAttachmentBasic(t *testing.T) { - resourceName := "aws_networkmanager_vpc_attachment.test" + resourceName := "aws_networkmanager_attachment_accepter.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { Source: "hashicorp/awscc", @@ -33,34 +25,11 @@ func TestAccNetworkManagerAttachmentAccepter_vpcAttachmentBasic(t *testing.T) { CheckDestroy: testAccCheckVPCAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccCoreNetworkConfig_basic("*", false), + Config: testAccCoreNetworkConfig_basic(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), - resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + resource.TestCheckResourceAttr(resourceName, "attachment_type", "VPC"), ), }, - { - Config: testAccCoreNetworkConfig_basic("0", true), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), - resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), - ), - }, - { - Config: testAccCoreNetworkConfig_basic("*", false), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), - resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), - ), - }, - // Cannot currently update ipv6 on its own, must also update subnet_arn - // { - // Config: testAccCoreNetworkConfig_basic("*", true), - // Check: resource.ComposeTestCheckFunc( - // resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), - // resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), - // ), - // }, { ResourceName: resourceName, ImportState: true, @@ -69,222 +38,3 @@ func TestAccNetworkManagerAttachmentAccepter_vpcAttachmentBasic(t *testing.T) { }, }) } - -func TestAccNetworkManagerAttachmentAccepter_vpcAttachmentTags(t *testing.T) { - resourceName := "aws_networkmanager_vpc_attachment.test" - testExternalProviders := map[string]resource.ExternalProvider{ - "awscc": { - Source: "hashicorp/awscc", - VersionConstraint: "0.29.0", - }, - } - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ExternalProviders: testExternalProviders, - CheckDestroy: testAccCheckVPCAttachmentDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCoreNetworkConfig_oneTag("segment", "shared"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), - ), - }, - { - Config: testAccCoreNetworkConfig_twoTag("segment", "shared", "Name", "test"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), - resource.TestCheckResourceAttr(resourceName, "tags.Name", "test"), - ), - }, - { - Config: testAccCoreNetworkConfig_oneTag("segment", "shared"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccCheckVPCAttachmentDestroy(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkManagerConn - - for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_networkmanager_vpc_attachment" { - continue - } - - _, err := tfnetworkmanager.FindVPCAttachmentByID(context.Background(), conn, rs.Primary.ID) - - if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { - continue - } - - if err != nil { - return err - } - - return fmt.Errorf("Network Manager Attachment ID %s still exists", rs.Primary.ID) - } - - return nil -} - -const TestAccVPCConfig_multipleSubnets = ` -data "aws_availability_zones" "test" {} -data "aws_region" "test" {} - -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - assign_generated_ipv6_cidr_block = true -} - -locals { - ipv6_cidrs = cidrsubnets(aws_vpc.test.ipv6_cidr_block, 8, 8) -} - -variable "subnets" { - default = ["10.0.1.0/24", "10.0.2.0/24"] -} - -resource "aws_subnet" "test" { - count = length(var.subnets) - - vpc_id = aws_vpc.test.id - cidr_block = element(var.subnets, count.index) - availability_zone = data.aws_availability_zones.test.names[count.index] - - assign_ipv6_address_on_creation = true - ipv6_cidr_block = local.ipv6_cidrs[count.index] -} -` - -const TestAccCoreNetworkConfig = ` -resource "awscc_networkmanager_global_network" "test" {} - -resource "awscc_networkmanager_core_network" "test" { - global_network_id = awscc_networkmanager_global_network.test.id - policy_document = jsonencode(jsondecode(data.aws_networkmanager_core_network_policy_document.test.json)) -} - -data "aws_networkmanager_core_network_policy_document" "test" { - core_network_configuration { - vpn_ecmp_support = false - asn_ranges = ["64512-64555"] - edge_locations { - location = data.aws_region.test.name - asn = 64512 - } - } - - segments { - name = "shared" - description = "SegmentForSharedServices" - require_attachment_acceptance = true - } - - segment_actions { - action = "share" - mode = "attachment-route" - segment = "shared" - share_with = ["*"] - } - - attachment_policies { - rule_number = 1 - condition_logic = "or" - - conditions { - type = "tag-value" - operator = "equals" - key = "segment" - value = "shared" - } - - action { - association_method = "constant" - segment = "shared" - } - } -} -` - -func testAccCoreNetworkConfig_basic(azs string, ipv6Support bool) string { - return TestAccVPCConfig_multipleSubnets + - TestAccCoreNetworkConfig + fmt.Sprintf(` -resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) - core_network_id = awscc_networkmanager_core_network.test.id - vpc_arn = aws_vpc.test.arn - - options { - ipv6_support = %[2]t - } -} - -resource "aws_networkmanager_attachment_accepter" "test" { - attachment_id = aws_networkmanager_vpc_attachment.test.id - attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type -} -`, azs, ipv6Support) -} - -func testAccCoreNetworkConfig_oneTag(tagKey1, tagValue1 string) string { - return TestAccVPCConfig_multipleSubnets + - TestAccCoreNetworkConfig + fmt.Sprintf(` -resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = [aws_subnet.test[0].arn] - core_network_id = awscc_networkmanager_core_network.test.id - vpc_arn = aws_vpc.test.arn - - options { - ipv6_support = false - } - - tags = { - %[1]q = %[2]q - } -} - -resource "aws_networkmanager_attachment_accepter" "test" { - attachment_id = aws_networkmanager_vpc_attachment.test.id - attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type -} -`, tagKey1, tagValue1) -} - -func testAccCoreNetworkConfig_twoTag(tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return TestAccVPCConfig_multipleSubnets + - TestAccCoreNetworkConfig + fmt.Sprintf(` -resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = [aws_subnet.test[0].arn] - core_network_id = awscc_networkmanager_core_network.test.id - vpc_arn = aws_vpc.test.arn - - options { - ipv6_support = false - } - - tags = { - %[1]q = %[2]q - %[3]q = %[4]q - } -} - -resource "aws_networkmanager_attachment_accepter" "test" { - attachment_id = aws_networkmanager_vpc_attachment.test.id - attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type -} -`, tagKey1, tagValue1, tagKey2, tagValue2) -} diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 7a3e4bfe644..6f570b013d5 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -147,13 +147,13 @@ func resourceVPCAttachmentCreate(ctx context.Context, d *schema.ResourceData, me output, err := conn.CreateVpcAttachmentWithContext(ctx, input) if err != nil { - return diag.Errorf("error creating Network Manager VPC Attachment: %s", err) + return diag.Errorf("Creating Network Manager VPC Attachment: %s", err) } d.SetId(aws.StringValue(output.VpcAttachment.Attachment.AttachmentId)) if _, err := WaitVPCAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) + return diag.Errorf("Waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) } return resourceVPCAttachmentRead(ctx, d, meta) @@ -175,7 +175,7 @@ func resourceVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta } if err != nil { - return diag.Errorf("error reading Network Manager VPC Attachment (%s): %s", d.Id(), err) + return diag.Errorf("Reading Network Manager VPC Attachment (%s): %s", d.Id(), err) } a := vpcAttachment.VpcAttachment.Attachment @@ -207,11 +207,11 @@ func resourceVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta //lintignore:AWSR002 if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("error setting tags: %s", err) + return diag.Errorf("Setting tags: %s", err) } if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("error setting tags_all: %s", err) + return diag.Errorf("Setting tags_all: %s", err) } return nil @@ -227,7 +227,7 @@ func resourceVPCAttachmentUpdate(ctx context.Context, d *schema.ResourceData, me arn := fmt.Sprintf("arn:%s:networkmanager::%s:attachment/%s", part, acnt, d.Id()) if err := UpdateTags(conn, arn, o, n); err != nil { - return diag.Errorf("error updating VPC Attachment (%s) tags: %s", d.Id(), err) + return diag.Errorf("Updating VPC Attachment (%s) tags: %s", d.Id(), err) } } @@ -265,11 +265,11 @@ func resourceVPCAttachmentUpdate(ctx context.Context, d *schema.ResourceData, me _, err := conn.UpdateVpcAttachmentWithContext(ctx, input) if err != nil { - return diag.Errorf("error updating vpc attachment (%s): %s", d.Id(), err) + return diag.Errorf("Updating vpc attachment (%s): %s", d.Id(), err) } if _, err := waitVPCAttachmentUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) update: %s", d.Id(), err) + return diag.Errorf("Waiting for Network Manager VPC Attachment (%s) update: %s", d.Id(), err) } } @@ -298,7 +298,7 @@ func resourceVPCAttachmentDelete(ctx context.Context, d *schema.ResourceData, me state := d.Get("state").(string) if state == networkmanager.AttachmentStatePendingAttachmentAcceptance || state == networkmanager.AttachmentStatePendingTagAcceptance { - return diag.Errorf("error deleting Network Manager VPC Attachment (%s): Cannot delete attachment that is pending acceptance.", d.Id()) + return diag.Errorf("Deleting Network Manager VPC Attachment (%s): Cannot delete attachment that is pending acceptance.", d.Id()) } _, err := conn.DeleteAttachmentWithContext(ctx, &networkmanager.DeleteAttachmentInput{ @@ -310,14 +310,14 @@ func resourceVPCAttachmentDelete(ctx context.Context, d *schema.ResourceData, me } if err != nil { - return diag.Errorf("error deleting Network Manager VPC Attachment (%s): %s", d.Id(), err) + return diag.Errorf("Deleting Network Manager VPC Attachment (%s): %s", d.Id(), err) } if _, err := waitVPCAttachmentDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { return nil } - return diag.Errorf("error waiting for Network Manager VPC Attachment (%s) delete: %s", d.Id(), err) + return diag.Errorf("Waiting for Network Manager VPC Attachment (%s) delete: %s", d.Id(), err) } return nil diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go new file mode 100644 index 00000000000..76ae23c793c --- /dev/null +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -0,0 +1,335 @@ +package networkmanager_test + +import ( + "context" + "fmt" + "testing" + + "github.com/aws/aws-sdk-go/service/networkmanager" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + tfnetworkmanager "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" +) + +func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { + resourceName := "aws_networkmanager_vpc_attachment.test" + testExternalProviders := map[string]resource.ExternalProvider{ + "awscc": { + Source: "hashicorp/awscc", + VersionConstraint: "0.29.0", + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ExternalProviders: testExternalProviders, + CheckDestroy: testAccCheckVPCAttachmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCoreNetworkConfig_basic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkManagerVpcAttachment_updates(t *testing.T) { + resourceName := "aws_networkmanager_vpc_attachment.test" + testExternalProviders := map[string]resource.ExternalProvider{ + "awscc": { + Source: "hashicorp/awscc", + VersionConstraint: "0.29.0", + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ExternalProviders: testExternalProviders, + CheckDestroy: testAccCheckVPCAttachmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCoreNetworkConfig_updates("*", false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + ), + }, + { + Config: testAccCoreNetworkConfig_updates("0", true), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), + ), + }, + { + Config: testAccCoreNetworkConfig_updates("*", false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + ), + }, + // Cannot currently update ipv6 on its own, must also update subnet_arn + // { + // Config: testAccCoreNetworkConfig_basic("*", true), + // Check: resource.ComposeTestCheckFunc( + // resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + // resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), + // ), + // }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkManagerVpcAttachment_tags(t *testing.T) { + resourceName := "aws_networkmanager_vpc_attachment.test" + testExternalProviders := map[string]resource.ExternalProvider{ + "awscc": { + Source: "hashicorp/awscc", + VersionConstraint: "0.29.0", + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ExternalProviders: testExternalProviders, + CheckDestroy: testAccCheckVPCAttachmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCoreNetworkConfig_oneTag("segment", "shared"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + ), + }, + { + Config: testAccCoreNetworkConfig_twoTag("segment", "shared", "Name", "test"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "test"), + ), + }, + { + Config: testAccCoreNetworkConfig_oneTag("segment", "shared"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckVPCAttachmentDestroy(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkManagerConn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_networkmanager_vpc_attachment" { + continue + } + + _, err := tfnetworkmanager.FindVPCAttachmentByID(context.Background(), conn, rs.Primary.ID) + + if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { + continue + } + + if err != nil { + return err + } + + return fmt.Errorf("Network Manager Attachment ID %s still exists", rs.Primary.ID) + } + + return nil +} + +const TestAccVPCConfig_multipleSubnets = ` +data "aws_availability_zones" "test" {} +data "aws_region" "test" {} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + assign_generated_ipv6_cidr_block = true +} + +locals { + ipv6_cidrs = cidrsubnets(aws_vpc.test.ipv6_cidr_block, 8, 8) +} + +variable "subnets" { + default = ["10.0.1.0/24", "10.0.2.0/24"] +} + +resource "aws_subnet" "test" { + count = length(var.subnets) + + vpc_id = aws_vpc.test.id + cidr_block = element(var.subnets, count.index) + availability_zone = data.aws_availability_zones.test.names[count.index] + + assign_ipv6_address_on_creation = true + ipv6_cidr_block = local.ipv6_cidrs[count.index] +} +` + +const TestAccCoreNetworkConfig = ` +resource "awscc_networkmanager_global_network" "test" {} + +resource "awscc_networkmanager_core_network" "test" { + global_network_id = awscc_networkmanager_global_network.test.id + policy_document = jsonencode(jsondecode(data.aws_networkmanager_core_network_policy_document.test.json)) +} + +data "aws_networkmanager_core_network_policy_document" "test" { + core_network_configuration { + vpn_ecmp_support = false + asn_ranges = ["64512-64555"] + edge_locations { + location = data.aws_region.test.name + asn = 64512 + } + } + + segments { + name = "shared" + description = "SegmentForSharedServices" + require_attachment_acceptance = true + } + + segment_actions { + action = "share" + mode = "attachment-route" + segment = "shared" + share_with = ["*"] + } + + attachment_policies { + rule_number = 1 + condition_logic = "or" + + conditions { + type = "tag-value" + operator = "equals" + key = "segment" + value = "shared" + } + + action { + association_method = "constant" + segment = "shared" + } + } +} +` + +func testAccCoreNetworkConfig_basic() string { + return TestAccVPCConfig_multipleSubnets + + TestAccCoreNetworkConfig + ` +resource "aws_networkmanager_vpc_attachment" "test" { + subnet_arns = [aws_subnet.test.*.arn] + core_network_id = awscc_networkmanager_core_network.test.id + vpc_arn = aws_vpc.test.arn +} + +resource "aws_networkmanager_attachment_accepter" "test" { + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type +} +` +} + +func testAccCoreNetworkConfig_updates(azs string, ipv6Support bool) string { + return TestAccVPCConfig_multipleSubnets + + TestAccCoreNetworkConfig + fmt.Sprintf(` +resource "aws_networkmanager_vpc_attachment" "test" { + subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) + core_network_id = awscc_networkmanager_core_network.test.id + vpc_arn = aws_vpc.test.arn + + options { + ipv6_support = %[2]t + } +} + +resource "aws_networkmanager_attachment_accepter" "test" { + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type +} +`, azs, ipv6Support) +} + +func testAccCoreNetworkConfig_oneTag(tagKey1, tagValue1 string) string { + return TestAccVPCConfig_multipleSubnets + + TestAccCoreNetworkConfig + fmt.Sprintf(` +resource "aws_networkmanager_vpc_attachment" "test" { + subnet_arns = [aws_subnet.test[0].arn] + core_network_id = awscc_networkmanager_core_network.test.id + vpc_arn = aws_vpc.test.arn + + options { + ipv6_support = false + } + + tags = { + %[1]q = %[2]q + } +} + +resource "aws_networkmanager_attachment_accepter" "test" { + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type +} +`, tagKey1, tagValue1) +} + +func testAccCoreNetworkConfig_twoTag(tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return TestAccVPCConfig_multipleSubnets + + TestAccCoreNetworkConfig + fmt.Sprintf(` +resource "aws_networkmanager_vpc_attachment" "test" { + subnet_arns = [aws_subnet.test[0].arn] + core_network_id = awscc_networkmanager_core_network.test.id + vpc_arn = aws_vpc.test.arn + + options { + ipv6_support = false + } + + tags = { + %[1]q = %[2]q + %[3]q = %[4]q + } +} + +resource "aws_networkmanager_attachment_accepter" "test" { + attachment_id = aws_networkmanager_vpc_attachment.test.id + attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type +} +`, tagKey1, tagValue1, tagKey2, tagValue2) +} From 816cb7543b2d318b421bd2fa07f63b2e511c4218 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Mon, 15 Aug 2022 10:38:11 -0400 Subject: [PATCH 16/30] wip --- internal/service/networkmanager/vpc_attachment_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go index 76ae23c793c..927d31bb948 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -253,7 +253,7 @@ func testAccCoreNetworkConfig_basic() string { return TestAccVPCConfig_multipleSubnets + TestAccCoreNetworkConfig + ` resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = [aws_subnet.test.*.arn] + subnet_arns = aws_subnet.test.*.arn core_network_id = awscc_networkmanager_core_network.test.id vpc_arn = aws_vpc.test.arn } From 22435143d3b26b434897a4cc42bcb4eb2cb7cca1 Mon Sep 17 00:00:00 2001 From: drewmullen Date: Mon, 15 Aug 2022 11:01:27 -0400 Subject: [PATCH 17/30] configcompose --- .../networkmanager/vpc_attachment_test.go | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go index 927d31bb948..246e39d6373 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -14,7 +14,7 @@ import ( tfnetworkmanager "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" ) -func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { +func TestAccNetworkManagerVPCAttachment_basic(t *testing.T) { resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -45,7 +45,7 @@ func TestAccNetworkManagerVpcAttachment_basic(t *testing.T) { }) } -func TestAccNetworkManagerVpcAttachment_updates(t *testing.T) { +func TestAccNetworkManagerVPCAttachment_updates(t *testing.T) { resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -99,7 +99,7 @@ func TestAccNetworkManagerVpcAttachment_updates(t *testing.T) { }) } -func TestAccNetworkManagerVpcAttachment_tags(t *testing.T) { +func TestAccNetworkManagerVPCAttachment_tags(t *testing.T) { resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -250,7 +250,7 @@ data "aws_networkmanager_core_network_policy_document" "test" { ` func testAccCoreNetworkConfig_basic() string { - return TestAccVPCConfig_multipleSubnets + + return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets + TestAccCoreNetworkConfig + ` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = aws_subnet.test.*.arn @@ -262,11 +262,11 @@ resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } -` +`) } func testAccCoreNetworkConfig_updates(azs string, ipv6Support bool) string { - return TestAccVPCConfig_multipleSubnets + + return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets + TestAccCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) @@ -282,21 +282,17 @@ resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } -`, azs, ipv6Support) +`, azs, ipv6Support)) } func testAccCoreNetworkConfig_oneTag(tagKey1, tagValue1 string) string { - return TestAccVPCConfig_multipleSubnets + + return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets + TestAccCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = [aws_subnet.test[0].arn] core_network_id = awscc_networkmanager_core_network.test.id vpc_arn = aws_vpc.test.arn - options { - ipv6_support = false - } - tags = { %[1]q = %[2]q } @@ -306,21 +302,17 @@ resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } -`, tagKey1, tagValue1) +`, tagKey1, tagValue1)) } func testAccCoreNetworkConfig_twoTag(tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return TestAccVPCConfig_multipleSubnets + + return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets + TestAccCoreNetworkConfig + fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = [aws_subnet.test[0].arn] core_network_id = awscc_networkmanager_core_network.test.id vpc_arn = aws_vpc.test.arn - options { - ipv6_support = false - } - tags = { %[1]q = %[2]q %[3]q = %[4]q @@ -331,5 +323,5 @@ resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } -`, tagKey1, tagValue1, tagKey2, tagValue2) +`, tagKey1, tagValue1, tagKey2, tagValue2)) } From a07e413937808c457b6a8ba31877e093c6d3ab5a Mon Sep 17 00:00:00 2001 From: drewmullen Date: Mon, 15 Aug 2022 13:49:24 -0400 Subject: [PATCH 18/30] diff suppres optional block --- .../service/networkmanager/vpc_attachment.go | 1 + .../networkmanager/vpc_attachment_test.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 6f570b013d5..4a5975171b4 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -77,6 +77,7 @@ func ResourceVPCAttachment() *schema.Resource { }, }, }, + DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, }, "owner_account_id": { diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go index 246e39d6373..2efcc5bf5a2 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -250,8 +250,8 @@ data "aws_networkmanager_core_network_policy_document" "test" { ` func testAccCoreNetworkConfig_basic() string { - return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets + - TestAccCoreNetworkConfig + ` + return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, + TestAccCoreNetworkConfig, ` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = aws_subnet.test.*.arn core_network_id = awscc_networkmanager_core_network.test.id @@ -266,8 +266,8 @@ resource "aws_networkmanager_attachment_accepter" "test" { } func testAccCoreNetworkConfig_updates(azs string, ipv6Support bool) string { - return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets + - TestAccCoreNetworkConfig + fmt.Sprintf(` + return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, + TestAccCoreNetworkConfig, fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) core_network_id = awscc_networkmanager_core_network.test.id @@ -286,8 +286,8 @@ resource "aws_networkmanager_attachment_accepter" "test" { } func testAccCoreNetworkConfig_oneTag(tagKey1, tagValue1 string) string { - return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets + - TestAccCoreNetworkConfig + fmt.Sprintf(` + return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, + TestAccCoreNetworkConfig, fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = [aws_subnet.test[0].arn] core_network_id = awscc_networkmanager_core_network.test.id @@ -306,8 +306,8 @@ resource "aws_networkmanager_attachment_accepter" "test" { } func testAccCoreNetworkConfig_twoTag(tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets + - TestAccCoreNetworkConfig + fmt.Sprintf(` + return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, + TestAccCoreNetworkConfig, fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = [aws_subnet.test[0].arn] core_network_id = awscc_networkmanager_core_network.test.id From 220f15c2709b1b3287c34bc62fca2658b0404a6e Mon Sep 17 00:00:00 2001 From: drewmullen Date: Mon, 15 Aug 2022 13:59:48 -0400 Subject: [PATCH 19/30] accepter does not support import --- .../service/networkmanager/attachment_acceptor_test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go index da59de7eb97..a33797519bf 100644 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ b/internal/service/networkmanager/attachment_acceptor_test.go @@ -30,11 +30,8 @@ func TestAccNetworkManagerAttachmentAccepter_vpcAttachmentBasic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "attachment_type", "VPC"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + // does not support import }, }) } From 4a88eb23b1caa2224d90c68619e44eb955926e99 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 09:16:31 -0400 Subject: [PATCH 20/30] r/aws_networkmanager_vpc_attachment: Tweaks to resource Create. --- .../networkmanager/attachment_accepter.go | 2 +- .../service/networkmanager/vpc_attachment.go | 54 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/internal/service/networkmanager/attachment_accepter.go b/internal/service/networkmanager/attachment_accepter.go index e8fa8f50ca0..8e7cb348d4d 100644 --- a/internal/service/networkmanager/attachment_accepter.go +++ b/internal/service/networkmanager/attachment_accepter.go @@ -132,7 +132,7 @@ func ResourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceDat d.SetId(attachmentId) if attachmentType == networkmanager.AttachmentTypeVpc { - if _, err := WaitVPCAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := waitVPCAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { d.SetId("") return diag.Errorf("Waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) } diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 4a5975171b4..837aebb62a8 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -43,28 +43,23 @@ func ResourceVPCAttachment() *schema.Resource { Type: schema.TypeInt, Computed: true, }, - "attachment_type": { Type: schema.TypeString, Computed: true, }, - "core_network_arn": { Type: schema.TypeString, Computed: true, }, - "core_network_id": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "edge_location": { Type: schema.TypeString, Computed: true, }, - "options": { Type: schema.TypeList, Optional: true, @@ -79,27 +74,22 @@ func ResourceVPCAttachment() *schema.Resource { }, DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, }, - "owner_account_id": { Type: schema.TypeString, Computed: true, }, - "resource_arn": { Type: schema.TypeString, Computed: true, }, - "segment_name": { Type: schema.TypeString, Computed: true, }, - "state": { Type: schema.TypeString, Computed: true, }, - "subnet_arns": { Type: schema.TypeSet, Required: true, @@ -108,10 +98,8 @@ func ResourceVPCAttachment() *schema.Resource { ValidateFunc: verify.ValidARN, }, }, - "tags": tftags.TagsSchema(), "tags_all": tftags.TagsSchemaComputed(), - "vpc_arn": { Type: schema.TypeString, Required: true, @@ -127,17 +115,16 @@ func resourceVPCAttachmentCreate(ctx context.Context, d *schema.ResourceData, me defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) + coreNetworkID := d.Get("core_network_id").(string) + vpcARN := d.Get("vpc_arn").(string) input := &networkmanager.CreateVpcAttachmentInput{ - CoreNetworkId: aws.String(d.Get("core_network_id").(string)), - VpcArn: aws.String(d.Get("vpc_arn").(string)), + CoreNetworkId: aws.String(coreNetworkID), SubnetArns: flex.ExpandStringSet(d.Get("subnet_arns").(*schema.Set)), + VpcArn: aws.String(vpcARN), } - if v, ok := d.GetOk("options"); ok { - optsMap := v.([]interface{})[0].(map[string]interface{}) - input.Options = &networkmanager.VpcOptions{ - Ipv6Support: aws.Bool(optsMap["ipv6_support"].(bool)), - } + if v, ok := d.GetOk("options"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input.Options = expandVpcOptions(v.([]interface{})[0].(map[string]interface{})) } if len(tags) > 0 { @@ -148,13 +135,13 @@ func resourceVPCAttachmentCreate(ctx context.Context, d *schema.ResourceData, me output, err := conn.CreateVpcAttachmentWithContext(ctx, input) if err != nil { - return diag.Errorf("Creating Network Manager VPC Attachment: %s", err) + return diag.Errorf("creating Network Manager VPC (%s) Attachment (%s): %s", vpcARN, coreNetworkID, err) } d.SetId(aws.StringValue(output.VpcAttachment.Attachment.AttachmentId)) - if _, err := WaitVPCAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("Waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) + if _, err := waitVPCAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + return diag.Errorf("waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) } return resourceVPCAttachmentRead(ctx, d, meta) @@ -329,10 +316,11 @@ func VPCAttachmentIDNotFoundError(err error) bool { } func FindVPCAttachmentByID(ctx context.Context, conn *networkmanager.NetworkManager, id string) (*networkmanager.VpcAttachment, error) { - - output, err := conn.GetVpcAttachment(&networkmanager.GetVpcAttachmentInput{ + input := &networkmanager.GetVpcAttachmentInput{ AttachmentId: aws.String(id), - }) + } + + output, err := conn.GetVpcAttachmentWithContext(ctx, input) if err != nil { return nil, err @@ -357,7 +345,7 @@ func StatusVPCAttachmentState(ctx context.Context, conn *networkmanager.NetworkM } } -func WaitVPCAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { +func waitVPCAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { stateConf := &resource.StateChangeConf{ Pending: []string{networkmanager.AttachmentStateCreating, networkmanager.AttachmentStatePendingNetworkUpdate}, Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingAttachmentAcceptance}, @@ -408,3 +396,17 @@ func waitVPCAttachmentUpdated(ctx context.Context, conn *networkmanager.NetworkM return nil, err } + +func expandVpcOptions(tfMap map[string]interface{}) *networkmanager.VpcOptions { + if tfMap == nil { + return nil + } + + apiObject := &networkmanager.VpcOptions{} + + if v, ok := tfMap["ipv6_support"].(bool); ok { + apiObject.Ipv6Support = aws.Bool(v) + } + + return apiObject +} From 36503118f0c24e7f847d73715c57fb0d9784a792 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 09:26:06 -0400 Subject: [PATCH 21/30] r/aws_networkmanager_vpc_attachment: Tweaks to resource Read. --- .../service/networkmanager/vpc_attachment.go | 62 ++++++++++++------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 837aebb62a8..791bfb79ccd 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -152,45 +152,38 @@ func resourceVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig - vpcAttachment, err := conn.GetVpcAttachment(&networkmanager.GetVpcAttachmentInput{ - AttachmentId: aws.String(d.Id()), - }) + vpcAttachment, err := FindVPCAttachmentByID(ctx, conn, d.Id()) - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Network Manager VPC Attachment %s not found, removing from state", d.Id()) d.SetId("") return nil } if err != nil { - return diag.Errorf("Reading Network Manager VPC Attachment (%s): %s", d.Id(), err) + return diag.Errorf("reading Network Manager VPC Attachment (%s): %s", d.Id(), err) } - a := vpcAttachment.VpcAttachment.Attachment - subnetArns := vpcAttachment.VpcAttachment.SubnetArns - opts := vpcAttachment.VpcAttachment.Options - - d.Set("core_network_id", a.CoreNetworkId) - d.Set("state", a.State) + a := vpcAttachment.Attachment d.Set("core_network_arn", a.CoreNetworkArn) d.Set("attachment_policy_rule_number", a.AttachmentPolicyRuleNumber) d.Set("attachment_type", a.AttachmentType) + d.Set("core_network_id", a.CoreNetworkId) d.Set("edge_location", a.EdgeLocation) + if vpcAttachment.Options != nil { + if err := d.Set("options", []interface{}{flattenVpcOptions(vpcAttachment.Options)}); err != nil { + return diag.Errorf("setting options: %s", err) + } + } else { + d.Set("options", nil) + } d.Set("owner_account_id", a.OwnerAccountId) d.Set("resource_arn", a.ResourceArn) d.Set("segment_name", a.SegmentName) - - // VPC arn is not outputted, therefore use resource arn + d.Set("state", a.State) + d.Set("subnet_arns", aws.StringValueSlice(vpcAttachment.SubnetArns)) d.Set("vpc_arn", a.ResourceArn) - // options - d.Set("options", []interface{}{map[string]interface{}{ - "ipv6_support": aws.BoolValue(opts.Ipv6Support), - }}) - - // subnetArns - d.Set("subnet_arns", subnetArns) - tags := KeyValueTags(a.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) //lintignore:AWSR002 @@ -199,7 +192,7 @@ func resourceVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta } if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("Setting tags_all: %s", err) + return diag.Errorf("setting tags_all: %s", err) } return nil @@ -322,10 +315,21 @@ func FindVPCAttachmentByID(ctx context.Context, conn *networkmanager.NetworkMana output, err := conn.GetVpcAttachmentWithContext(ctx, input) + if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + if err != nil { return nil, err } + if output == nil || output.VpcAttachment == nil { + return nil, tfresource.NewEmptyResultError(input) + } + return output.VpcAttachment, nil } @@ -410,3 +414,17 @@ func expandVpcOptions(tfMap map[string]interface{}) *networkmanager.VpcOptions { return apiObject } + +func flattenVpcOptions(apiObject *networkmanager.VpcOptions) map[string]interface{} { + if apiObject == nil { + return nil + } + + tfMap := map[string]interface{}{} + + if v := apiObject.Ipv6Support; v != nil { + tfMap["ipv6_support"] = aws.BoolValue(v) + } + + return tfMap +} From bfb8bec686b69c5a833d6bcc19ccdfe3269f4910 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 09:34:48 -0400 Subject: [PATCH 22/30] r/aws_networkmanager_vpc_attachment: Add 'arn' attribute. --- .../service/networkmanager/vpc_attachment.go | 63 +++++++++---------- ...etworkmanager_vpc_attachment.html.markdown | 1 + 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 791bfb79ccd..063c62b3146 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -7,6 +7,7 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/networkmanager" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -39,6 +40,10 @@ func ResourceVPCAttachment() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeInt, + Computed: true, + }, "attachment_policy_rule_number": { Type: schema.TypeInt, Computed: true, @@ -165,9 +170,16 @@ func resourceVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta } a := vpcAttachment.Attachment - d.Set("core_network_arn", a.CoreNetworkArn) + arn := arn.ARN{ + Partition: meta.(*conns.AWSClient).Partition, + Service: "networkmanager", + AccountID: meta.(*conns.AWSClient).AccountID, + Resource: fmt.Sprintf("attachment/%s", d.Id()), + }.String() + d.Set("arn", arn) d.Set("attachment_policy_rule_number", a.AttachmentPolicyRuleNumber) d.Set("attachment_type", a.AttachmentType) + d.Set("core_network_arn", a.CoreNetworkArn) d.Set("core_network_id", a.CoreNetworkId) d.Set("edge_location", a.EdgeLocation) if vpcAttachment.Options != nil { @@ -201,24 +213,15 @@ func resourceVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta func resourceVPCAttachmentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - acnt := meta.(*conns.AWSClient).AccountID - part := meta.(*conns.AWSClient).Partition - arn := fmt.Sprintf("arn:%s:networkmanager::%s:attachment/%s", part, acnt, d.Id()) - - if err := UpdateTags(conn, arn, o, n); err != nil { - return diag.Errorf("Updating VPC Attachment (%s) tags: %s", d.Id(), err) - } - } - if d.HasChangesExcept("tags", "tags_all") { input := &networkmanager.UpdateVpcAttachmentInput{ AttachmentId: aws.String(d.Id()), } if d.HasChange("options") { - input.Options = expandVPCAttachmentOptions(d.Get("options").([]interface{})) + if v, ok := d.GetOk("options"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input.Options = expandVpcOptions(v.([]interface{})[0].(map[string]interface{})) + } } if d.HasChange("subnet_arns") { @@ -229,46 +232,38 @@ func resourceVPCAttachmentUpdate(ctx context.Context, d *schema.ResourceData, me if n == nil { n = new(schema.Set) } - os := o.(*schema.Set) ns := n.(*schema.Set) - subnetArnsUpdateAdd := ns.Difference(os) - subnetArnsUpdateRemove := os.Difference(ns) - if len(subnetArnsUpdateAdd.List()) > 0 { - input.AddSubnetArns = flex.ExpandStringSet(subnetArnsUpdateAdd) + if add := ns.Difference(os); len(add.List()) > 0 { + input.AddSubnetArns = flex.ExpandStringSet(add) } - if len(subnetArnsUpdateRemove.List()) > 0 { - input.RemoveSubnetArns = flex.ExpandStringSet(subnetArnsUpdateRemove) + if del := os.Difference(ns); len(del.List()) > 0 { + input.RemoveSubnetArns = flex.ExpandStringSet(del) } } + _, err := conn.UpdateVpcAttachmentWithContext(ctx, input) if err != nil { - return diag.Errorf("Updating vpc attachment (%s): %s", d.Id(), err) + return diag.Errorf("updating Network Manager VPC Attachment (%s): %s", d.Id(), err) } if _, err := waitVPCAttachmentUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return diag.Errorf("Waiting for Network Manager VPC Attachment (%s) update: %s", d.Id(), err) + return diag.Errorf("waiting for Network Manager VPC Attachment (%s) update: %s", d.Id(), err) } } - return resourceVPCAttachmentRead(ctx, d, meta) -} - -func expandVPCAttachmentOptions(l []interface{}) *networkmanager.VpcOptions { - if len(l) == 0 || l[0] == nil { - return nil - } - - m := l[0].(map[string]interface{}) + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") - opts := &networkmanager.VpcOptions{ - Ipv6Support: aws.Bool(m["ipv6_support"].(bool)), + if err := UpdateTags(conn, d.Get("arn").(string), o, n); err != nil { + return diag.Errorf("updating VPC Attachment (%s) tags: %s", d.Id(), err) + } } - return opts + return resourceVPCAttachmentRead(ctx, d, meta) } func resourceVPCAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { diff --git a/website/docs/r/networkmanager_vpc_attachment.html.markdown b/website/docs/r/networkmanager_vpc_attachment.html.markdown index c7c0aa61d0c..0e15219fd85 100644 --- a/website/docs/r/networkmanager_vpc_attachment.html.markdown +++ b/website/docs/r/networkmanager_vpc_attachment.html.markdown @@ -43,6 +43,7 @@ The following arguments are optional: In addition to all arguments above, the following attributes are exported: +* `arn` - The ARN of the attachment. * `attachment_id` - The ID of the attachment. * `attachment_policy_rule_number` - The policy rule number associated with the attachment. * `attachment_type` - The type of attachment. From a56122c626dacfdd0c0b908619a1914736c0c198 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 09:37:59 -0400 Subject: [PATCH 23/30] r/aws_networkmanager_vpc_attachment: Tweak resource Delete. --- .../service/networkmanager/vpc_attachment.go | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 063c62b3146..0c91c933fd9 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -269,14 +269,11 @@ func resourceVPCAttachmentUpdate(ctx context.Context, d *schema.ResourceData, me func resourceVPCAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn - log.Printf("[DEBUG] Deleting Network Manager VPC Attachment: %s", d.Id()) - - state := d.Get("state").(string) - - if state == networkmanager.AttachmentStatePendingAttachmentAcceptance || state == networkmanager.AttachmentStatePendingTagAcceptance { - return diag.Errorf("Deleting Network Manager VPC Attachment (%s): Cannot delete attachment that is pending acceptance.", d.Id()) + if state := d.Get("state").(string); state == networkmanager.AttachmentStatePendingAttachmentAcceptance || state == networkmanager.AttachmentStatePendingTagAcceptance { + return diag.Errorf("cannot delete Network Manager VPC Attachment (%s) in %s state", d.Id(), state) } + log.Printf("[DEBUG] Deleting Network Manager VPC Attachment: %s", d.Id()) _, err := conn.DeleteAttachmentWithContext(ctx, &networkmanager.DeleteAttachmentInput{ AttachmentId: aws.String(d.Id()), }) @@ -286,23 +283,16 @@ func resourceVPCAttachmentDelete(ctx context.Context, d *schema.ResourceData, me } if err != nil { - return diag.Errorf("Deleting Network Manager VPC Attachment (%s): %s", d.Id(), err) + return diag.Errorf("deleting Network Manager VPC Attachment (%s): %s", d.Id(), err) } if _, err := waitVPCAttachmentDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { - return nil - } - return diag.Errorf("Waiting for Network Manager VPC Attachment (%s) delete: %s", d.Id(), err) + return diag.Errorf("waiting for Network Manager VPC Attachment (%s) delete: %s", d.Id(), err) } return nil } -func VPCAttachmentIDNotFoundError(err error) bool { - return validationExceptionMessageContains(err, networkmanager.ValidationExceptionReasonFieldValidationFailed, "VPC Attachment not found") -} - func FindVPCAttachmentByID(ctx context.Context, conn *networkmanager.NetworkManager, id string) (*networkmanager.VpcAttachment, error) { input := &networkmanager.GetVpcAttachmentInput{ AttachmentId: aws.String(id), From 3eb90f1a106fda48810bf48af54b1e6d6f76fc9a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 10:48:02 -0400 Subject: [PATCH 24/30] r/aws_networkmanager_vpc_attachment: Add 'testAccCoreNetworkConfig_base'. Acceptance test output: % make testacc TESTARGS='-run=TestAccNetworkManagerVPCAttachment_basic' PKG=networkmanager ACCTEST_PARALLELISM=2 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/networkmanager/... -v -count 1 -parallel 2 -run=TestAccNetworkManagerVPCAttachment_basic -timeout 180m === RUN TestAccNetworkManagerVPCAttachment_basic === PAUSE TestAccNetworkManagerVPCAttachment_basic === CONT TestAccNetworkManagerVPCAttachment_basic --- PASS: TestAccNetworkManagerVPCAttachment_basic (814.61s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager 818.609s --- .../attachment_acceptor_test.go | 37 ----- .../service/networkmanager/vpc_attachment.go | 2 +- .../networkmanager/vpc_attachment_test.go | 127 ++++++++++++++++-- 3 files changed, 120 insertions(+), 46 deletions(-) delete mode 100644 internal/service/networkmanager/attachment_acceptor_test.go diff --git a/internal/service/networkmanager/attachment_acceptor_test.go b/internal/service/networkmanager/attachment_acceptor_test.go deleted file mode 100644 index a33797519bf..00000000000 --- a/internal/service/networkmanager/attachment_acceptor_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package networkmanager_test - -import ( - "testing" - - "github.com/aws/aws-sdk-go/service/networkmanager" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-provider-aws/internal/acctest" -) - -func TestAccNetworkManagerAttachmentAccepter_vpcAttachmentBasic(t *testing.T) { - resourceName := "aws_networkmanager_attachment_accepter.test" - testExternalProviders := map[string]resource.ExternalProvider{ - "awscc": { - Source: "hashicorp/awscc", - VersionConstraint: "0.29.0", - }, - } - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ExternalProviders: testExternalProviders, - CheckDestroy: testAccCheckVPCAttachmentDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCoreNetworkConfig_basic(), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "attachment_type", "VPC"), - ), - }, - - // does not support import - }, - }) -} diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 0c91c933fd9..6c34417f53f 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -41,7 +41,7 @@ func ResourceVPCAttachment() *schema.Resource { Schema: map[string]*schema.Schema{ "arn": { - Type: schema.TypeInt, + Type: schema.TypeString, Computed: true, }, "attachment_policy_rule_number": { diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go index 2efcc5bf5a2..4806b2da668 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -6,15 +6,17 @@ import ( "testing" "github.com/aws/aws-sdk-go/service/networkmanager" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfnetworkmanager "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func TestAccNetworkManagerVPCAttachment_basic(t *testing.T) { + var v networkmanager.VpcAttachment resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -22,6 +24,7 @@ func TestAccNetworkManagerVPCAttachment_basic(t *testing.T) { VersionConstraint: "0.29.0", }, } + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -31,8 +34,9 @@ func TestAccNetworkManagerVPCAttachment_basic(t *testing.T) { CheckDestroy: testAccCheckVPCAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccCoreNetworkConfig_basic(), + Config: testAccCoreNetworkConfig_basic(rName), Check: resource.ComposeTestCheckFunc( + testAccCheckVPCAttachmentExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), ), }, @@ -146,6 +150,31 @@ func TestAccNetworkManagerVPCAttachment_tags(t *testing.T) { }) } +func testAccCheckVPCAttachmentExists(n string, v *networkmanager.VpcAttachment) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Network Manager VPC Attachment ID is set") + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkManagerConn + + output, err := tfnetworkmanager.FindVPCAttachmentByID(context.Background(), conn, rs.Primary.ID) + + if err != nil { + return err + } + + *v = *output + + return nil + } +} + func testAccCheckVPCAttachmentDestroy(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkManagerConn @@ -156,7 +185,7 @@ func testAccCheckVPCAttachmentDestroy(s *terraform.State) error { _, err := tfnetworkmanager.FindVPCAttachmentByID(context.Background(), conn, rs.Primary.ID) - if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) { + if tfresource.NotFound(err) { continue } @@ -164,12 +193,95 @@ func testAccCheckVPCAttachmentDestroy(s *terraform.State) error { return err } - return fmt.Errorf("Network Manager Attachment ID %s still exists", rs.Primary.ID) + return fmt.Errorf("Network Manager VPC Attachment %s still exists", rs.Primary.ID) } return nil } +func testAccCoreNetworkConfig_base(rName string) string { + return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` +data "aws_region" "current" {} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + assign_generated_ipv6_cidr_block = true + + tags = { + Name = %[1]q + } +} + +resource "aws_subnet" "test" { + count = 2 + + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, count.index) + + ipv6_cidr_block = cidrsubnet(aws_vpc.test.ipv6_cidr_block, 8, count.index) + assign_ipv6_address_on_creation = true + + tags = { + Name = %[1]q + } +} + +resource "aws_networkmanager_global_network" "test" { + tags = { + Name = %[1]q + } +} + +resource "awscc_networkmanager_core_network" "test" { + global_network_id = aws_networkmanager_global_network.test.id + policy_document = jsonencode(jsondecode(data.aws_networkmanager_core_network_policy_document.test.json)) +} + +data "aws_networkmanager_core_network_policy_document" "test" { + core_network_configuration { + vpn_ecmp_support = false + asn_ranges = ["64512-64555"] + edge_locations { + location = data.aws_region.current.name + asn = 64512 + } + } + + segments { + name = "shared" + description = "SegmentForSharedServices" + require_attachment_acceptance = true + } + + segment_actions { + action = "share" + mode = "attachment-route" + segment = "shared" + share_with = ["*"] + } + + attachment_policies { + rule_number = 1 + condition_logic = "or" + + conditions { + type = "tag-value" + operator = "equals" + key = "segment" + value = "shared" + } + + action { + association_method = "constant" + segment = "shared" + } + } +} +`, rName)) +} + const TestAccVPCConfig_multipleSubnets = ` data "aws_availability_zones" "test" {} data "aws_region" "test" {} @@ -249,11 +361,10 @@ data "aws_networkmanager_core_network_policy_document" "test" { } ` -func testAccCoreNetworkConfig_basic() string { - return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, - TestAccCoreNetworkConfig, ` +func testAccCoreNetworkConfig_basic(rName string) string { + return acctest.ConfigCompose(testAccCoreNetworkConfig_base(rName), ` resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = aws_subnet.test.*.arn + subnet_arns = aws_subnet.test[*].arn core_network_id = awscc_networkmanager_core_network.test.id vpc_arn = aws_vpc.test.arn } From 87402a1f35f2f488acd8eb505f7bc0f04a46552c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 10:53:23 -0400 Subject: [PATCH 25/30] r/aws_networkmanager_vpc_attachment: Correct acceptance test configuration function names. --- .../networkmanager/vpc_attachment_test.go | 102 +++++++++++------- 1 file changed, 66 insertions(+), 36 deletions(-) diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go index 4806b2da668..16189f7f98d 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -34,7 +34,7 @@ func TestAccNetworkManagerVPCAttachment_basic(t *testing.T) { CheckDestroy: testAccCheckVPCAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccCoreNetworkConfig_basic(rName), + Config: testAccVPCAttachmentConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckVPCAttachmentExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), @@ -49,7 +49,8 @@ func TestAccNetworkManagerVPCAttachment_basic(t *testing.T) { }) } -func TestAccNetworkManagerVPCAttachment_updates(t *testing.T) { +func TestAccNetworkManagerVPCAttachment_disappears(t *testing.T) { + var v networkmanager.VpcAttachment resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -57,6 +58,7 @@ func TestAccNetworkManagerVPCAttachment_updates(t *testing.T) { VersionConstraint: "0.29.0", }, } + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -66,34 +68,55 @@ func TestAccNetworkManagerVPCAttachment_updates(t *testing.T) { CheckDestroy: testAccCheckVPCAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccCoreNetworkConfig_updates("*", false), + Config: testAccVPCAttachmentConfig_basic(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), - resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + testAccCheckVPCAttachmentExists(resourceName, &v), + acctest.CheckResourceDisappears(acctest.Provider, tfnetworkmanager.ResourceVPCAttachment(), resourceName), ), + ExpectNonEmptyPlan: true, }, + }, + }) +} + +func TestAccNetworkManagerVPCAttachment_tags(t *testing.T) { + resourceName := "aws_networkmanager_vpc_attachment.test" + testExternalProviders := map[string]resource.ExternalProvider{ + "awscc": { + Source: "hashicorp/awscc", + VersionConstraint: "0.29.0", + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ExternalProviders: testExternalProviders, + CheckDestroy: testAccCheckVPCAttachmentDestroy, + Steps: []resource.TestStep{ { - Config: testAccCoreNetworkConfig_updates("0", true), + Config: testAccVPCAttachmentConfig_tags1("segment", "shared"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), - resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), ), }, { - Config: testAccCoreNetworkConfig_updates("*", false), + Config: testAccVPCAttachmentConfig_tags2("segment", "shared", "Name", "test"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), - resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "test"), + ), + }, + { + Config: testAccVPCAttachmentConfig_tags1("segment", "shared"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), ), }, - // Cannot currently update ipv6 on its own, must also update subnet_arn - // { - // Config: testAccCoreNetworkConfig_basic("*", true), - // Check: resource.ComposeTestCheckFunc( - // resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), - // resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), - // ), - // }, { ResourceName: resourceName, ImportState: true, @@ -103,7 +126,7 @@ func TestAccNetworkManagerVPCAttachment_updates(t *testing.T) { }) } -func TestAccNetworkManagerVPCAttachment_tags(t *testing.T) { +func TestAccNetworkManagerVPCAttachment_update(t *testing.T) { resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -120,27 +143,34 @@ func TestAccNetworkManagerVPCAttachment_tags(t *testing.T) { CheckDestroy: testAccCheckVPCAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccCoreNetworkConfig_oneTag("segment", "shared"), + Config: testAccVPCAttachmentConfig_updates("*", false), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), ), }, { - Config: testAccCoreNetworkConfig_twoTag("segment", "shared", "Name", "test"), + Config: testAccVPCAttachmentConfig_updates("0", true), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), - resource.TestCheckResourceAttr(resourceName, "tags.Name", "test"), + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), ), }, { - Config: testAccCoreNetworkConfig_oneTag("segment", "shared"), + Config: testAccVPCAttachmentConfig_updates("*", false), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), + resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), ), }, + // Cannot currently update ipv6 on its own, must also update subnet_arn + // { + // Config: testAccCoreNetworkConfig_basic("*", true), + // Check: resource.ComposeTestCheckFunc( + // resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + // resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), + // ), + // }, { ResourceName: resourceName, ImportState: true, @@ -199,7 +229,7 @@ func testAccCheckVPCAttachmentDestroy(s *terraform.State) error { return nil } -func testAccCoreNetworkConfig_base(rName string) string { +func testAccVPCAttachmentConfig_base(rName string) string { return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` data "aws_region" "current" {} @@ -361,8 +391,8 @@ data "aws_networkmanager_core_network_policy_document" "test" { } ` -func testAccCoreNetworkConfig_basic(rName string) string { - return acctest.ConfigCompose(testAccCoreNetworkConfig_base(rName), ` +func testAccVPCAttachmentConfig_basic(rName string) string { + return acctest.ConfigCompose(testAccVPCAttachmentConfig_base(rName), ` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = aws_subnet.test[*].arn core_network_id = awscc_networkmanager_core_network.test.id @@ -376,7 +406,7 @@ resource "aws_networkmanager_attachment_accepter" "test" { `) } -func testAccCoreNetworkConfig_updates(azs string, ipv6Support bool) string { +func testAccVPCAttachmentConfig_updates(azs string, ipv6Support bool) string { return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, TestAccCoreNetworkConfig, fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { @@ -396,7 +426,7 @@ resource "aws_networkmanager_attachment_accepter" "test" { `, azs, ipv6Support)) } -func testAccCoreNetworkConfig_oneTag(tagKey1, tagValue1 string) string { +func testAccVPCAttachmentConfig_tags1(tagKey1, tagValue1 string) string { return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, TestAccCoreNetworkConfig, fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { @@ -416,7 +446,7 @@ resource "aws_networkmanager_attachment_accepter" "test" { `, tagKey1, tagValue1)) } -func testAccCoreNetworkConfig_twoTag(tagKey1, tagValue1, tagKey2, tagValue2 string) string { +func testAccVPCAttachmentConfig_tags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string { return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, TestAccCoreNetworkConfig, fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { From 71d42e27feb8b076e7eaedc7c7111e3615baf5e2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 12:39:17 -0400 Subject: [PATCH 26/30] r/aws_networkmanager_vpc_attachment: Tidy up acceptance tests. Acceptance test output: % make testacc TESTARGS='-run=TestAccNetworkManagerVPCAttachment_' PKG=networkmanager ACCTEST_PARALLELISM=2 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/networkmanager/... -v -count 1 -parallel 2 -run=TestAccNetworkManagerVPCAttachment_ -timeout 180m === RUN TestAccNetworkManagerVPCAttachment_basic === PAUSE TestAccNetworkManagerVPCAttachment_basic === RUN TestAccNetworkManagerVPCAttachment_disappears === PAUSE TestAccNetworkManagerVPCAttachment_disappears === RUN TestAccNetworkManagerVPCAttachment_tags === PAUSE TestAccNetworkManagerVPCAttachment_tags === RUN TestAccNetworkManagerVPCAttachment_update === PAUSE TestAccNetworkManagerVPCAttachment_update === CONT TestAccNetworkManagerVPCAttachment_basic === CONT TestAccNetworkManagerVPCAttachment_tags --- PASS: TestAccNetworkManagerVPCAttachment_basic (849.56s) === CONT TestAccNetworkManagerVPCAttachment_disappears --- PASS: TestAccNetworkManagerVPCAttachment_tags (1123.64s) === CONT TestAccNetworkManagerVPCAttachment_update --- PASS: TestAccNetworkManagerVPCAttachment_disappears (854.64s) --- PASS: TestAccNetworkManagerVPCAttachment_update (1284.73s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager 2412.205s --- .../networkmanager/vpc_attachment_test.go | 156 ++++++------------ 1 file changed, 51 insertions(+), 105 deletions(-) diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go index 16189f7f98d..36b978c720f 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -3,6 +3,7 @@ package networkmanager_test import ( "context" "fmt" + "regexp" "testing" "github.com/aws/aws-sdk-go/service/networkmanager" @@ -18,6 +19,7 @@ import ( func TestAccNetworkManagerVPCAttachment_basic(t *testing.T) { var v networkmanager.VpcAttachment resourceName := "aws_networkmanager_vpc_attachment.test" + vpcResourceName := "aws_vpc.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { Source: "hashicorp/awscc", @@ -35,9 +37,23 @@ func TestAccNetworkManagerVPCAttachment_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccVPCAttachmentConfig_basic(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckVPCAttachmentExists(resourceName, &v), + acctest.MatchResourceAttrGlobalARN(resourceName, "arn", "networkmanager", regexp.MustCompile(`attachment/.+`)), + resource.TestCheckResourceAttr(resourceName, "attachment_policy_rule_number", "0"), + resource.TestCheckResourceAttr(resourceName, "attachment_type", "VPC"), + resource.TestCheckResourceAttr(resourceName, "core_network_arn", ""), + resource.TestCheckResourceAttrSet(resourceName, "core_network_id"), + resource.TestCheckResourceAttr(resourceName, "edge_location", acctest.Region()), + resource.TestCheckResourceAttr(resourceName, "options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), + acctest.CheckResourceAttrAccountID(resourceName, "owner_account_id"), + resource.TestCheckResourceAttrPair(resourceName, "resource_arn", vpcResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "segment_name", ""), + resource.TestCheckResourceAttrSet(resourceName, "state"), resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + resource.TestCheckResourceAttrPair(resourceName, "vpc_arn", vpcResourceName, "arn"), ), }, { @@ -80,6 +96,7 @@ func TestAccNetworkManagerVPCAttachment_disappears(t *testing.T) { } func TestAccNetworkManagerVPCAttachment_tags(t *testing.T) { + var v networkmanager.VpcAttachment resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -87,6 +104,7 @@ func TestAccNetworkManagerVPCAttachment_tags(t *testing.T) { VersionConstraint: "0.29.0", }, } + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -96,23 +114,26 @@ func TestAccNetworkManagerVPCAttachment_tags(t *testing.T) { CheckDestroy: testAccCheckVPCAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccVPCAttachmentConfig_tags1("segment", "shared"), + Config: testAccVPCAttachmentConfig_tags1(rName, "segment", "shared"), Check: resource.ComposeTestCheckFunc( + testAccCheckVPCAttachmentExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), ), }, { - Config: testAccVPCAttachmentConfig_tags2("segment", "shared", "Name", "test"), + Config: testAccVPCAttachmentConfig_tags2(rName, "segment", "shared", "Name", "test"), Check: resource.ComposeTestCheckFunc( + testAccCheckVPCAttachmentExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), resource.TestCheckResourceAttr(resourceName, "tags.Name", "test"), ), }, { - Config: testAccVPCAttachmentConfig_tags1("segment", "shared"), + Config: testAccVPCAttachmentConfig_tags1(rName, "segment", "shared"), Check: resource.ComposeTestCheckFunc( + testAccCheckVPCAttachmentExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), resource.TestCheckResourceAttr(resourceName, "tags.segment", "shared"), ), @@ -127,6 +148,7 @@ func TestAccNetworkManagerVPCAttachment_tags(t *testing.T) { } func TestAccNetworkManagerVPCAttachment_update(t *testing.T) { + var v networkmanager.VpcAttachment resourceName := "aws_networkmanager_vpc_attachment.test" testExternalProviders := map[string]resource.ExternalProvider{ "awscc": { @@ -134,6 +156,7 @@ func TestAccNetworkManagerVPCAttachment_update(t *testing.T) { VersionConstraint: "0.29.0", }, } + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -143,21 +166,22 @@ func TestAccNetworkManagerVPCAttachment_update(t *testing.T) { CheckDestroy: testAccCheckVPCAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccVPCAttachmentConfig_updates("*", false), + Config: testAccVPCAttachmentConfig_updates(rName, 2, false), Check: resource.ComposeTestCheckFunc( + testAccCheckVPCAttachmentExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), ), }, { - Config: testAccVPCAttachmentConfig_updates("0", true), + Config: testAccVPCAttachmentConfig_updates(rName, 1, true), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "1"), resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), ), }, { - Config: testAccVPCAttachmentConfig_updates("*", false), + Config: testAccVPCAttachmentConfig_updates(rName, 2, false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "false"), @@ -165,7 +189,7 @@ func TestAccNetworkManagerVPCAttachment_update(t *testing.T) { }, // Cannot currently update ipv6 on its own, must also update subnet_arn // { - // Config: testAccCoreNetworkConfig_basic("*", true), + // Config: testAccVPCAttachmentConfig_updates(rName, 2, true), // Check: resource.ComposeTestCheckFunc( // resource.TestCheckResourceAttr(resourceName, "subnet_arns.#", "2"), // resource.TestCheckResourceAttr(resourceName, "options.0.ipv6_support", "true"), @@ -312,85 +336,6 @@ data "aws_networkmanager_core_network_policy_document" "test" { `, rName)) } -const TestAccVPCConfig_multipleSubnets = ` -data "aws_availability_zones" "test" {} -data "aws_region" "test" {} - -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - assign_generated_ipv6_cidr_block = true -} - -locals { - ipv6_cidrs = cidrsubnets(aws_vpc.test.ipv6_cidr_block, 8, 8) -} - -variable "subnets" { - default = ["10.0.1.0/24", "10.0.2.0/24"] -} - -resource "aws_subnet" "test" { - count = length(var.subnets) - - vpc_id = aws_vpc.test.id - cidr_block = element(var.subnets, count.index) - availability_zone = data.aws_availability_zones.test.names[count.index] - - assign_ipv6_address_on_creation = true - ipv6_cidr_block = local.ipv6_cidrs[count.index] -} -` - -const TestAccCoreNetworkConfig = ` -resource "awscc_networkmanager_global_network" "test" {} - -resource "awscc_networkmanager_core_network" "test" { - global_network_id = awscc_networkmanager_global_network.test.id - policy_document = jsonencode(jsondecode(data.aws_networkmanager_core_network_policy_document.test.json)) -} - -data "aws_networkmanager_core_network_policy_document" "test" { - core_network_configuration { - vpn_ecmp_support = false - asn_ranges = ["64512-64555"] - edge_locations { - location = data.aws_region.test.name - asn = 64512 - } - } - - segments { - name = "shared" - description = "SegmentForSharedServices" - require_attachment_acceptance = true - } - - segment_actions { - action = "share" - mode = "attachment-route" - segment = "shared" - share_with = ["*"] - } - - attachment_policies { - rule_number = 1 - condition_logic = "or" - - conditions { - type = "tag-value" - operator = "equals" - key = "segment" - value = "shared" - } - - action { - association_method = "constant" - segment = "shared" - } - } -} -` - func testAccVPCAttachmentConfig_basic(rName string) string { return acctest.ConfigCompose(testAccVPCAttachmentConfig_base(rName), ` resource "aws_networkmanager_vpc_attachment" "test" { @@ -406,16 +351,15 @@ resource "aws_networkmanager_attachment_accepter" "test" { `) } -func testAccVPCAttachmentConfig_updates(azs string, ipv6Support bool) string { - return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, - TestAccCoreNetworkConfig, fmt.Sprintf(` +func testAccVPCAttachmentConfig_tags1(rName, tagKey1, tagValue1 string) string { + return acctest.ConfigCompose(testAccVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = flatten([aws_subnet.test.%[1]s.arn]) + subnet_arns = [aws_subnet.test[0].arn] core_network_id = awscc_networkmanager_core_network.test.id vpc_arn = aws_vpc.test.arn - options { - ipv6_support = %[2]t + tags = { + %[1]q = %[2]q } } @@ -423,12 +367,11 @@ resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } -`, azs, ipv6Support)) +`, tagKey1, tagValue1)) } -func testAccVPCAttachmentConfig_tags1(tagKey1, tagValue1 string) string { - return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, - TestAccCoreNetworkConfig, fmt.Sprintf(` +func testAccVPCAttachmentConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return acctest.ConfigCompose(testAccVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { subnet_arns = [aws_subnet.test[0].arn] core_network_id = awscc_networkmanager_core_network.test.id @@ -436,6 +379,7 @@ resource "aws_networkmanager_vpc_attachment" "test" { tags = { %[1]q = %[2]q + %[3]q = %[4]q } } @@ -443,20 +387,22 @@ resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } -`, tagKey1, tagValue1)) +`, tagKey1, tagValue1, tagKey2, tagValue2)) } -func testAccVPCAttachmentConfig_tags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return acctest.ConfigCompose(TestAccVPCConfig_multipleSubnets, - TestAccCoreNetworkConfig, fmt.Sprintf(` +func testAccVPCAttachmentConfig_updates(rName string, nSubnets int, ipv6Support bool) string { + return acctest.ConfigCompose(testAccVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_networkmanager_vpc_attachment" "test" { - subnet_arns = [aws_subnet.test[0].arn] + subnet_arns = slice(aws_subnet.test[*].arn, 0, %[2]d) core_network_id = awscc_networkmanager_core_network.test.id vpc_arn = aws_vpc.test.arn + options { + ipv6_support = %[3]t + } + tags = { - %[1]q = %[2]q - %[3]q = %[4]q + Name = %[1]q } } @@ -464,5 +410,5 @@ resource "aws_networkmanager_attachment_accepter" "test" { attachment_id = aws_networkmanager_vpc_attachment.test.id attachment_type = aws_networkmanager_vpc_attachment.test.attachment_type } -`, tagKey1, tagValue1, tagKey2, tagValue2)) +`, rName, nSubnets, ipv6Support)) } From cb6765dbdef93752a037cd12eb4022a6b54726ea Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 14:45:19 -0400 Subject: [PATCH 27/30] r/aws_networkmanager_accepter: Implement resource Read. --- .../networkmanager/attachment_accepter.go | 94 ++++++++----------- .../service/networkmanager/vpc_attachment.go | 2 +- ...kmanager_attachment_accepter.html.markdown | 2 +- 3 files changed, 39 insertions(+), 59 deletions(-) diff --git a/internal/service/networkmanager/attachment_accepter.go b/internal/service/networkmanager/attachment_accepter.go index 8e7cb348d4d..aa463fe896f 100644 --- a/internal/service/networkmanager/attachment_accepter.go +++ b/internal/service/networkmanager/attachment_accepter.go @@ -2,7 +2,6 @@ package networkmanager import ( "context" - "log" "time" "github.com/aws/aws-sdk-go/aws" @@ -18,9 +17,9 @@ import ( func ResourceAttachmentAccepter() *schema.Resource { return &schema.Resource{ - CreateWithoutTimeout: ResourceAttachmentAccepterCreate, - ReadWithoutTimeout: schema.NoopContext, - DeleteWithoutTimeout: ResourceAttachmentAccepterDelete, + CreateWithoutTimeout: resourceAttachmentAccepterCreate, + ReadWithoutTimeout: resourceAttachmentAccepterRead, + DeleteWithoutTimeout: schema.NoopContext, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), @@ -32,12 +31,10 @@ func ResourceAttachmentAccepter() *schema.Resource { Required: true, ForceNew: true, }, - "attachment_policy_rule_number": { Type: schema.TypeInt, Computed: true, }, - // querying attachments requires knowing the type ahead of time // therefore type is required in provider, though not on the API "attachment_type": { @@ -50,37 +47,30 @@ func ResourceAttachmentAccepter() *schema.Resource { // Implement Values() function for validation as more types are onboarded to provider // networkmanager.AttachmentType_Values(), false), }, - "core_network_arn": { Type: schema.TypeString, Computed: true, }, - "core_network_id": { Type: schema.TypeString, Computed: true, }, - "edge_location": { Type: schema.TypeString, Computed: true, }, - "owner_account_id": { Type: schema.TypeString, Computed: true, }, - "resource_arn": { Type: schema.TypeString, Computed: true, }, - "segment_name": { Type: schema.TypeString, Computed: true, }, - "state": { Type: schema.TypeString, Computed: true, @@ -89,69 +79,59 @@ func ResourceAttachmentAccepter() *schema.Resource { } } -func ResourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn - attachmentId := d.Get("attachment_id").(string) - attachmentType := d.Get("attachment_type").(string) - attachment := &networkmanager.Attachment{} - accepted := false - var state string - - if attachmentType == networkmanager.AttachmentTypeVpc { - output, err := FindVPCAttachmentByID(ctx, conn, attachmentId) - - if err != nil { - return diag.Errorf("Finding Network Manager VPC Attachment: %s", err) - } - - state = aws.StringValue(output.Attachment.State) - attachment = output.Attachment + if attachmentType := d.Get("attachment_type").(string); attachmentType != networkmanager.AttachmentTypeVpc { + return diag.Errorf("unsupported Network Manager Attachment type: %s", attachmentType) } - if state == networkmanager.AttachmentStateAvailable { - accepted = true - log.Printf("[WARN] Attachment (%s) already accepted, importing attributes into state without accepting.", attachmentId) + attachmentID := d.Get("attachment_id").(string) + vpcAttachment, err := FindVPCAttachmentByID(ctx, conn, attachmentID) + + if err != nil { + return diag.Errorf("reading Network Manager VPC Attachment (%s): %s", attachmentID, err) } - if !accepted { + if state := aws.StringValue(vpcAttachment.Attachment.State); state == networkmanager.AttachmentStatePendingAttachmentAcceptance || state == networkmanager.AttachmentStatePendingTagAcceptance { input := &networkmanager.AcceptAttachmentInput{ - AttachmentId: aws.String(attachmentId), + AttachmentId: aws.String(attachmentID), } - log.Printf("[DEBUG] Accepting Network Manager Attachment: %s", input) - a, err := conn.AcceptAttachmentWithContext(ctx, input) + _, err := conn.AcceptAttachmentWithContext(ctx, input) if err != nil { - return diag.Errorf("Accepting Network Manager Attachment: %s", err) + return diag.Errorf("accepting Network Manager Attachment (%s): %s", attachmentID, err) } - attachment = a.Attachment - } - - d.SetId(attachmentId) - - if attachmentType == networkmanager.AttachmentTypeVpc { - if _, err := waitVPCAttachmentCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - d.SetId("") - return diag.Errorf("Waiting for Network Manager VPC Attachment (%s) create: %s", d.Id(), err) + if _, err := waitVPCAttachmentCreated(ctx, conn, attachmentID, d.Timeout(schema.TimeoutCreate)); err != nil { + return diag.Errorf("waiting for Network Manager VPC Attachment (%s) create: %s", attachmentID, err) } } - d.Set("core_network_id", attachment.CoreNetworkId) - d.Set("state", attachment.State) - d.Set("core_network_arn", attachment.CoreNetworkArn) - d.Set("attachment_policy_rule_number", attachment.AttachmentPolicyRuleNumber) - d.Set("edge_location", attachment.EdgeLocation) - d.Set("owner_account_id", attachment.OwnerAccountId) - d.Set("resource_arn", attachment.ResourceArn) - d.Set("segment_name", attachment.SegmentName) + d.SetId(attachmentID) - return nil + return resourceAttachmentAccepterRead(ctx, d, meta) } -func ResourceAttachmentAccepterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - log.Printf("[WARN] Attachment (%s) not deleted, removing from state.", d.Id()) +func resourceAttachmentAccepterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).NetworkManagerConn + + vpcAttachment, err := FindVPCAttachmentByID(ctx, conn, d.Id()) + + if err != nil { + return diag.Errorf("reading Network Manager VPC Attachment (%s): %s", d.Id(), err) + } + + a := vpcAttachment.Attachment + d.Set("attachment_policy_rule_number", a.AttachmentPolicyRuleNumber) + d.Set("core_network_arn", a.CoreNetworkArn) + d.Set("core_network_id", a.CoreNetworkId) + d.Set("edge_location", a.EdgeLocation) + d.Set("owner_account_id", a.OwnerAccountId) + d.Set("resource_arn", a.ResourceArn) + d.Set("segment_name", a.SegmentName) + d.Set("state", a.State) return nil } diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 6c34417f53f..66285cb6872 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -311,7 +311,7 @@ func FindVPCAttachmentByID(ctx context.Context, conn *networkmanager.NetworkMana return nil, err } - if output == nil || output.VpcAttachment == nil { + if output == nil || output.VpcAttachment == nil || output.VpcAttachment.Attachment == nil { return nil, tfresource.NewEmptyResultError(input) } diff --git a/website/docs/r/networkmanager_attachment_accepter.html.markdown b/website/docs/r/networkmanager_attachment_accepter.html.markdown index e72a190c2c4..ec77d9efd51 100644 --- a/website/docs/r/networkmanager_attachment_accepter.html.markdown +++ b/website/docs/r/networkmanager_attachment_accepter.html.markdown @@ -3,7 +3,7 @@ subcategory: "Network Manager" layout: "aws" page_title: "AWS: aws_networkmanager_attachment_accepter" description: |- - Terraform resource for managing an AWS NetworkManager VpcAttachment. + Terraform resource for managing an AWS NetworkManager Attachment Accepter. --- # Resource: aws_networkmanager_attachment_accepter From 76c307edbb98e6fb4e9474d496fdf2472b267c7f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 14:49:45 -0400 Subject: [PATCH 28/30] Fix terrafmt error. --- internal/service/networkmanager/vpc_attachment_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/networkmanager/vpc_attachment_test.go b/internal/service/networkmanager/vpc_attachment_test.go index 36b978c720f..5639f0d5b15 100644 --- a/internal/service/networkmanager/vpc_attachment_test.go +++ b/internal/service/networkmanager/vpc_attachment_test.go @@ -284,7 +284,7 @@ resource "aws_subnet" "test" { resource "aws_networkmanager_global_network" "test" { tags = { - Name = %[1]q + Name = %[1]q } } From c7f9205eb1901c395d90f19a4befc63d994059b9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 14:51:22 -0400 Subject: [PATCH 29/30] Fix semgrep 'ci.caps5-in-func-name'. --- internal/service/networkmanager/vpc_attachment.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index 66285cb6872..d78d80e1d41 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -386,7 +386,7 @@ func waitVPCAttachmentUpdated(ctx context.Context, conn *networkmanager.NetworkM return nil, err } -func expandVpcOptions(tfMap map[string]interface{}) *networkmanager.VpcOptions { +func expandVpcOptions(tfMap map[string]interface{}) *networkmanager.VpcOptions { // nosemgrep:ci.caps5-in-func-name if tfMap == nil { return nil } @@ -400,7 +400,7 @@ func expandVpcOptions(tfMap map[string]interface{}) *networkmanager.VpcOptions { return apiObject } -func flattenVpcOptions(apiObject *networkmanager.VpcOptions) map[string]interface{} { +func flattenVpcOptions(apiObject *networkmanager.VpcOptions) map[string]interface{} { // nosemgrep:ci.caps5-in-func-name if apiObject == nil { return nil } From 319f317b935dc97ec4617622c677851aab40cb3b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 16 Aug 2022 15:08:31 -0400 Subject: [PATCH 30/30] Fix golangci-lint 'unparam'. --- internal/service/networkmanager/vpc_attachment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index d78d80e1d41..7d286d033ff 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -334,7 +334,7 @@ func StatusVPCAttachmentState(ctx context.Context, conn *networkmanager.NetworkM } } -func waitVPCAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { +func waitVPCAttachmentCreated(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.VpcAttachment, error) { //nolint:unparam stateConf := &resource.StateChangeConf{ Pending: []string{networkmanager.AttachmentStateCreating, networkmanager.AttachmentStatePendingNetworkUpdate}, Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingAttachmentAcceptance},