Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

New Resources: r/aws_networkmanager_vpc_attachment & r/aws_networkmanager_attachment_acceptor #26227

Merged
merged 31 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
94987ef
initial commit for vpc_attachment and attachment_acceptor
drewmullen Aug 10, 2022
b067626
separate test structures
drewmullen Aug 10, 2022
bfec4c7
abstract attachment-acceptor to be flexible for other attachment types
drewmullen Aug 10, 2022
84232db
test file renamed to acceptor centric name
drewmullen Aug 10, 2022
2d4a9b7
cannot update ipv6 settings
drewmullen Aug 10, 2022
99e36fe
changelog new r/networkmanager_vpc_attachment
drewmullen Aug 10, 2022
ae29118
terrafmt
drewmullen Aug 10, 2022
b89ff3d
semgrep fix
drewmullen Aug 10, 2022
54817eb
linting
drewmullen Aug 10, 2022
32a9e4b
linting
drewmullen Aug 10, 2022
f11c196
linting
drewmullen Aug 11, 2022
aaa7581
rm unnecessary type cast
drewmullen Aug 11, 2022
0c3cd95
can only use ipv6 support if changing subnet_arns
drewmullen Aug 11, 2022
4d5fe8b
rename resource "accepter"
drewmullen Aug 11, 2022
ad34837
separate tests across resources, provide basic test
drewmullen Aug 15, 2022
816cb75
wip
drewmullen Aug 15, 2022
2243514
configcompose
drewmullen Aug 15, 2022
a07e413
diff suppres optional block
drewmullen Aug 15, 2022
220f15c
accepter does not support import
drewmullen Aug 15, 2022
eaa2b1c
Merge branch 'main' into HEAD
ewbankkit Aug 16, 2022
4a88eb2
r/aws_networkmanager_vpc_attachment: Tweaks to resource Create.
ewbankkit Aug 16, 2022
3650311
r/aws_networkmanager_vpc_attachment: Tweaks to resource Read.
ewbankkit Aug 16, 2022
bfb8bec
r/aws_networkmanager_vpc_attachment: Add 'arn' attribute.
ewbankkit Aug 16, 2022
a56122c
r/aws_networkmanager_vpc_attachment: Tweak resource Delete.
ewbankkit Aug 16, 2022
3eb90f1
r/aws_networkmanager_vpc_attachment: Add 'testAccCoreNetworkConfig_ba…
ewbankkit Aug 16, 2022
87402a1
r/aws_networkmanager_vpc_attachment: Correct acceptance test configur…
ewbankkit Aug 16, 2022
71d42e2
r/aws_networkmanager_vpc_attachment: Tidy up acceptance tests.
ewbankkit Aug 16, 2022
cb6765d
r/aws_networkmanager_accepter: Implement resource Read.
ewbankkit Aug 16, 2022
76c307e
Fix terrafmt error.
ewbankkit Aug 16, 2022
c7f9205
Fix semgrep 'ci.caps5-in-func-name'.
ewbankkit Aug 16, 2022
319f317
Fix golangci-lint 'unparam'.
ewbankkit Aug 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/26227.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
aws_networkmanager_vpc_attachment
```

```release-note:new-resource
aws_networkmanager_attachment_accepter
```
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_accepter": networkmanager.ResourceAttachmentAccepter(),
"aws_networkmanager_connection": networkmanager.ResourceConnection(),
"aws_networkmanager_customer_gateway_association": networkmanager.ResourceCustomerGatewayAssociation(),
"aws_networkmanager_device": networkmanager.ResourceDevice(),
Expand All @@ -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(),
Expand Down
157 changes: 157 additions & 0 deletions internal/service/networkmanager/attachment_accepter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
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/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
)

// 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{
CreateWithoutTimeout: ResourceAttachmentAccepterCreate,
ReadWithoutTimeout: schema.NoopContext,
DeleteWithoutTimeout: ResourceAttachmentAccepterDelete,

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,
},

// 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),
// 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,
},
},
}
}

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 state == networkmanager.AttachmentStateAvailable {
accepted = true
log.Printf("[WARN] Attachment (%s) already accepted, importing attributes into state without accepting.", attachmentId)
}

if !accepted {
input := &networkmanager.AcceptAttachmentInput{
AttachmentId: aws.String(attachmentId),
}

log.Printf("[DEBUG] Accepting Network Manager Attachment: %s", input)
a, err := conn.AcceptAttachmentWithContext(ctx, input)

if err != nil {
return diag.Errorf("Accepting Network Manager Attachment: %s", 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)
}
}

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
}

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
}
40 changes: 40 additions & 0 deletions internal/service/networkmanager/attachment_acceptor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Loading