diff --git a/go.mod b/go.mod index 4f8e868a8..f116f390e 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,11 @@ module github.com/vmware/terraform-provider-nsxt go 1.19 replace ( - github.com/vmware/vsphere-automation-sdk-go/lib => github.com/annakhm/vsphere-automation-sdk-go/lib v0.0.0-20240829205651-501d8b74a2f2 - github.com/vmware/vsphere-automation-sdk-go/runtime => github.com/annakhm/vsphere-automation-sdk-go/runtime v0.0.0-20240829205651-501d8b74a2f2 - github.com/vmware/vsphere-automation-sdk-go/services/nsxt => github.com/annakhm/vsphere-automation-sdk-go/services/nsxt v0.0.0-20240829205651-501d8b74a2f2 - github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm => github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-gm v0.0.0-20240829205651-501d8b74a2f2 - github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp => github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20240829205651-501d8b74a2f2 + github.com/vmware/vsphere-automation-sdk-go/lib => github.com/annakhm/vsphere-automation-sdk-go/lib v0.0.0-20241110024359-e42c5fcc5482 + github.com/vmware/vsphere-automation-sdk-go/runtime => github.com/annakhm/vsphere-automation-sdk-go/runtime v0.0.0-20241110024359-e42c5fcc5482 + github.com/vmware/vsphere-automation-sdk-go/services/nsxt => github.com/annakhm/vsphere-automation-sdk-go/services/nsxt v0.0.0-20241110024359-e42c5fcc5482 + github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm => github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-gm v0.0.0-20241110024359-e42c5fcc5482 + github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp => github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20241110024359-e42c5fcc5482 ) require ( diff --git a/go.sum b/go.sum index 9ca9a17af..ebe3f9d77 100644 --- a/go.sum +++ b/go.sum @@ -6,16 +6,16 @@ github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjA github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= -github.com/annakhm/vsphere-automation-sdk-go/lib v0.0.0-20240829205651-501d8b74a2f2 h1:g/LOjqOLwM3/zkMDqxcWiPo9f4cD2TARKpNodisecDw= -github.com/annakhm/vsphere-automation-sdk-go/lib v0.0.0-20240829205651-501d8b74a2f2/go.mod h1:ADkX8BkdnvT1Kc9ZfqHaV4qzaaD+9L8Ok2+pxK4xoD8= -github.com/annakhm/vsphere-automation-sdk-go/runtime v0.0.0-20240829205651-501d8b74a2f2 h1:jZasoSshbh7jFHHNXDhJ06SNSu7DRWu72IlwGpp/eV4= -github.com/annakhm/vsphere-automation-sdk-go/runtime v0.0.0-20240829205651-501d8b74a2f2/go.mod h1:DzLetYAmw1+vj7bqElRWEpuy40WYE/woL3alsymYa/c= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt v0.0.0-20240829205651-501d8b74a2f2 h1:PWqW/+aaPewj39/nmvER8ZGF4OwS7AFVCd4tg7FZgH0= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt v0.0.0-20240829205651-501d8b74a2f2/go.mod h1:upLH9b9zpG86P0wwO4+gREf0lBXr8gYcs7P1FRZ9n30= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-gm v0.0.0-20240829205651-501d8b74a2f2 h1:06nwNUgwFfRBf6tytT9UHPYmmPKYPEyo4KmatvfPZLE= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-gm v0.0.0-20240829205651-501d8b74a2f2/go.mod h1:gcEvyczWPFMZX2gkBiBVpOwvUGSNXSpxU19Sx9aiouY= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20240829205651-501d8b74a2f2 h1:mlyh0vvF9Zwb6ZvGNfdP3KfFJ/J1ioAciz6CTkY2g4k= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20240829205651-501d8b74a2f2/go.mod h1:ugk9I4YM62SSAox57l5NAVBCRIkPQ1RNLb3URxyTADc= +github.com/annakhm/vsphere-automation-sdk-go/lib v0.0.0-20241110024359-e42c5fcc5482 h1:aSqiTMwQQso+tTULhSf/26iAkhTHVfdi9P1Q/X+HpxQ= +github.com/annakhm/vsphere-automation-sdk-go/lib v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:ADkX8BkdnvT1Kc9ZfqHaV4qzaaD+9L8Ok2+pxK4xoD8= +github.com/annakhm/vsphere-automation-sdk-go/runtime v0.0.0-20241110024359-e42c5fcc5482 h1:wWKGPhmqvvpxO0G4mlNtZ27ThzPCuOG/kPXgbu0CR8s= +github.com/annakhm/vsphere-automation-sdk-go/runtime v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:DzLetYAmw1+vj7bqElRWEpuy40WYE/woL3alsymYa/c= +github.com/annakhm/vsphere-automation-sdk-go/services/nsxt v0.0.0-20241110024359-e42c5fcc5482 h1:qDHIIezjQTDqgv9YlFee9R3vBWDlbFJGUZRxvomtkgk= +github.com/annakhm/vsphere-automation-sdk-go/services/nsxt v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:NSjO9WqelbsTEDb3pVxpYYz4zjgX0XPp43dKNT4Y+9k= +github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-gm v0.0.0-20241110024359-e42c5fcc5482 h1:QkLzAnPXPDxqICfRfo8QMVjim0mY1nYfM+ie0r/pyLQ= +github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-gm v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:gcEvyczWPFMZX2gkBiBVpOwvUGSNXSpxU19Sx9aiouY= +github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20241110024359-e42c5fcc5482 h1:/+pwbYwlKBuZAwJVtZhSQorwtDmIGbo/EqRnFkgE7dk= +github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:ugk9I4YM62SSAox57l5NAVBCRIkPQ1RNLb3URxyTADc= github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= diff --git a/nsxt/policy_utils.go b/nsxt/policy_utils.go index 6ad9ffe13..7fd2e5ef4 100644 --- a/nsxt/policy_utils.go +++ b/nsxt/policy_utils.go @@ -320,7 +320,7 @@ func parseStandardPolicyPath(path string) ([]string, error) { infraPath = false } } - if len(segments) <= idx { + if len(segments) < idx { return nil, fmt.Errorf("unexpected policy path %s", path) } if infraPath { diff --git a/nsxt/policy_utils_test.go b/nsxt/policy_utils_test.go index fe3877165..bb84aa77d 100644 --- a/nsxt/policy_utils_test.go +++ b/nsxt/policy_utils_test.go @@ -65,6 +65,7 @@ func TestIsPolicyPath(t *testing.T) { "/global-infra/tier-1s/mygw1", "/orgs/infra/tier-1s/mygw1", "/orgs/myorg/projects/myproj/domains/d", + "/orgs/myorg/projects/myproj/vpcs/nicevpc", } for _, test := range testData { diff --git a/nsxt/provider.go b/nsxt/provider.go index 98c3aa5b6..8c3a16484 100644 --- a/nsxt/provider.go +++ b/nsxt/provider.go @@ -519,6 +519,7 @@ func Provider() *schema.Provider { "nsxt_policy_gateway_connection": resourceNsxtPolicyGatewayConnection(), "nsxt_policy_distributed_vlan_connection": resourceNsxtPolicyDistributedVlanConnection(), "nsxt_vpc": resourceNsxtVpc(), + "nsxt_vpc_attachment": resourceNsxtVpcAttachment(), "nsxt_vpc_nat_rule": resourceNsxtPolicyVpcNatRule(), "nsxt_policy_transit_gateway_attachment": resourceNsxtPolicyTransitGatewayAttachment(), "nsxt_vpc_external_address": resourceNsxtVpcExternalAddress(), diff --git a/nsxt/resource_nsxt_vpc.go b/nsxt/resource_nsxt_vpc.go index 6cb6c2e38..fb9703902 100644 --- a/nsxt/resource_nsxt_vpc.go +++ b/nsxt/resource_nsxt_vpc.go @@ -114,19 +114,6 @@ var vpcSchema = map[string]*metadata.ExtendedSchema{ OmitIfEmpty: true, }, }, - "vpc_connectivity_profile": { - Schema: schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validatePolicyPath(), - Optional: true, - Computed: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "string", - SdkFieldName: "VpcConnectivityProfile", - OmitIfEmpty: true, - }, - }, } // VPC resource needs dedicated importer since its path is VPC path, diff --git a/nsxt/resource_nsxt_vpc_attachment.go b/nsxt/resource_nsxt_vpc_attachment.go new file mode 100644 index 000000000..6f373418f --- /dev/null +++ b/nsxt/resource_nsxt_vpc_attachment.go @@ -0,0 +1,206 @@ +/* Copyright © 2024 Broadcom, Inc. All Rights Reserved. + SPDX-License-Identifier: MPL-2.0 */ + +package nsxt + +import ( + "fmt" + "log" + "reflect" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" + clientLayer "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs" + + utl "github.com/vmware/terraform-provider-nsxt/api/utl" + "github.com/vmware/terraform-provider-nsxt/nsxt/metadata" +) + +var vpcAttachmentSchema = map[string]*metadata.ExtendedSchema{ + "nsx_id": metadata.GetExtendedSchema(getNsxIDSchema()), + "path": metadata.GetExtendedSchema(getPathSchema()), + "display_name": metadata.GetExtendedSchema(getDisplayNameSchema()), + "description": metadata.GetExtendedSchema(getDescriptionSchema()), + "revision": metadata.GetExtendedSchema(getRevisionSchema()), + "tag": metadata.GetExtendedSchema(getTagsSchema()), + "parent_path": metadata.GetExtendedSchema(getPolicyPathSchema(true, true, "Policy path of the parent")), + "vpc_connectivity_profile": { + Schema: schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validatePolicyPath(), + Required: true, + }, + Metadata: metadata.Metadata{ + SchemaType: "string", + SdkFieldName: "VpcConnectivityProfile", + }, + }, +} + +func resourceNsxtVpcAttachment() *schema.Resource { + return &schema.Resource{ + Create: resourceNsxtVpcAttachmentCreate, + Read: resourceNsxtVpcAttachmentRead, + Update: resourceNsxtVpcAttachmentUpdate, + Delete: resourceNsxtVpcAttachmentDelete, + Importer: &schema.ResourceImporter{ + State: nsxtParentPathResourceImporter, + }, + Schema: metadata.GetSchemaFromExtendedSchema(vpcAttachmentSchema), + } +} + +func resourceNsxtVpcAttachmentExists(sessionContext utl.SessionContext, parentPath string, id string, connector client.Connector) (bool, error) { + var err error + parents, pathErr := parseStandardPolicyPathVerifySize(parentPath, 3) + if pathErr != nil { + return false, pathErr + } + client := clientLayer.NewAttachmentsClient(connector) + _, err = client.Get(parents[0], parents[1], parents[2], id) + if err == nil { + return true, nil + } + + if isNotFoundError(err) { + return false, nil + } + + return false, logAPIError("error retrieving resource", err) +} + +func resourceNsxtVpcAttachmentCreate(d *schema.ResourceData, m interface{}) error { + connector := getPolicyConnector(m) + + id, err := getOrGenerateIDWithParent(d, m, resourceNsxtVpcAttachmentExists) + if err != nil { + return err + } + + parentPath := d.Get("parent_path").(string) + parents, pathErr := parseStandardPolicyPathVerifySize(parentPath, 3) + if pathErr != nil { + return pathErr + } + displayName := d.Get("display_name").(string) + description := d.Get("description").(string) + tags := getPolicyTagsFromSchema(d) + + obj := model.VpcAttachment{ + DisplayName: &displayName, + Description: &description, + Tags: tags, + } + + elem := reflect.ValueOf(&obj).Elem() + if err := metadata.SchemaToStruct(elem, d, vpcAttachmentSchema, "", nil); err != nil { + return err + } + + log.Printf("[INFO] Creating VpcAttachment with ID %s", id) + + client := clientLayer.NewAttachmentsClient(connector) + err = client.Patch(parents[0], parents[1], parents[2], id, obj) + if err != nil { + return handleCreateError("VpcAttachment", id, err) + } + d.SetId(id) + d.Set("nsx_id", id) + + return resourceNsxtVpcAttachmentRead(d, m) +} + +func resourceNsxtVpcAttachmentRead(d *schema.ResourceData, m interface{}) error { + connector := getPolicyConnector(m) + + id := d.Id() + if id == "" { + return fmt.Errorf("error obtaining VpcAttachment ID") + } + + client := clientLayer.NewAttachmentsClient(connector) + parentPath := d.Get("parent_path").(string) + parents, pathErr := parseStandardPolicyPathVerifySize(parentPath, 3) + if pathErr != nil { + return pathErr + } + obj, err := client.Get(parents[0], parents[1], parents[2], id) + if err != nil { + return handleReadError(d, "VpcAttachment", id, err) + } + + setPolicyTagsInSchema(d, obj.Tags) + d.Set("nsx_id", id) + d.Set("display_name", obj.DisplayName) + d.Set("description", obj.Description) + d.Set("revision", obj.Revision) + d.Set("path", obj.Path) + + elem := reflect.ValueOf(&obj).Elem() + return metadata.StructToSchema(elem, d, vpcAttachmentSchema, "", nil) +} + +func resourceNsxtVpcAttachmentUpdate(d *schema.ResourceData, m interface{}) error { + + connector := getPolicyConnector(m) + + id := d.Id() + if id == "" { + return fmt.Errorf("error obtaining VpcAttachment ID") + } + + parentPath := d.Get("parent_path").(string) + parents, pathErr := parseStandardPolicyPathVerifySize(parentPath, 3) + if pathErr != nil { + return pathErr + } + description := d.Get("description").(string) + displayName := d.Get("display_name").(string) + tags := getPolicyTagsFromSchema(d) + + revision := int64(d.Get("revision").(int)) + + obj := model.VpcAttachment{ + DisplayName: &displayName, + Description: &description, + Tags: tags, + Revision: &revision, + } + + elem := reflect.ValueOf(&obj).Elem() + if err := metadata.SchemaToStruct(elem, d, vpcAttachmentSchema, "", nil); err != nil { + return err + } + client := clientLayer.NewAttachmentsClient(connector) + _, err := client.Update(parents[0], parents[1], parents[2], id, obj) + if err != nil { + return handleUpdateError("VpcAttachment", id, err) + } + + return resourceNsxtVpcAttachmentRead(d, m) +} + +func resourceNsxtVpcAttachmentDelete(d *schema.ResourceData, m interface{}) error { + id := d.Id() + if id == "" { + return fmt.Errorf("error obtaining VpcAttachment ID") + } + + connector := getPolicyConnector(m) + parentPath := d.Get("parent_path").(string) + + parents, pathErr := parseStandardPolicyPathVerifySize(parentPath, 3) + if pathErr != nil { + return pathErr + } + + client := clientLayer.NewAttachmentsClient(connector) + err := client.Delete(parents[0], parents[1], parents[2], id) + + if err != nil { + return handleDeleteError("VpcAttachment", id, err) + } + + return nil +} diff --git a/nsxt/resource_nsxt_vpc_service_profile.go b/nsxt/resource_nsxt_vpc_service_profile.go index 813442145..29b64d47f 100644 --- a/nsxt/resource_nsxt_vpc_service_profile.go +++ b/nsxt/resource_nsxt_vpc_service_profile.go @@ -24,14 +24,6 @@ var vpcServiceProfileModeValues = []string{ model.VpcProfileDhcpConfig_MODE_DEACTIVATED, } -var vpcServiceProfileLogLevelValues = []string{ - model.PolicyVpcDnsForwarder_LOG_LEVEL_DEBUG, - model.PolicyVpcDnsForwarder_LOG_LEVEL_INFO, - model.PolicyVpcDnsForwarder_LOG_LEVEL_ERROR, - model.PolicyVpcDnsForwarder_LOG_LEVEL_WARNING, - model.PolicyVpcDnsForwarder_LOG_LEVEL_FATAL, -} - var vpcServiceProfileSchema = map[string]*metadata.ExtendedSchema{ "nsx_id": metadata.GetExtendedSchema(getNsxIDSchema()), "path": metadata.GetExtendedSchema(getPathSchema()), diff --git a/nsxt/resource_nsxt_vpc_test.go b/nsxt/resource_nsxt_vpc_test.go index c135b1d50..b954bd515 100644 --- a/nsxt/resource_nsxt_vpc_test.go +++ b/nsxt/resource_nsxt_vpc_test.go @@ -34,6 +34,7 @@ var accTestVpcUpdateAttributes = map[string]string{ func TestAccResourceNsxtVpc_basic(t *testing.T) { testResourceName := "nsxt_vpc.test" + attachmentResourceName := "nsxt_vpc_attachment.test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccOnlyVPC(t) }, @@ -55,11 +56,12 @@ func TestAccResourceNsxtVpc_basic(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "load_balancer_vpc_endpoint.#", "1"), resource.TestCheckResourceAttr(testResourceName, "load_balancer_vpc_endpoint.0.enabled", accTestVpcCreateAttributes["enabled"]), resource.TestCheckResourceAttrSet(testResourceName, "vpc_service_profile"), - resource.TestCheckResourceAttrSet(testResourceName, "vpc_connectivity_profile"), resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), resource.TestCheckResourceAttrSet(testResourceName, "path"), resource.TestCheckResourceAttrSet(testResourceName, "revision"), resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + resource.TestCheckResourceAttrSet(attachmentResourceName, "parent_path"), + resource.TestCheckResourceAttrSet(attachmentResourceName, "vpc_connectivity_profile"), ), }, { @@ -74,11 +76,12 @@ func TestAccResourceNsxtVpc_basic(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "load_balancer_vpc_endpoint.#", "1"), resource.TestCheckResourceAttr(testResourceName, "load_balancer_vpc_endpoint.0.enabled", accTestVpcUpdateAttributes["enabled"]), resource.TestCheckResourceAttrSet(testResourceName, "vpc_service_profile"), - resource.TestCheckResourceAttrSet(testResourceName, "vpc_connectivity_profile"), resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), resource.TestCheckResourceAttrSet(testResourceName, "path"), resource.TestCheckResourceAttrSet(testResourceName, "revision"), resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + resource.TestCheckResourceAttrSet(attachmentResourceName, "parent_path"), + resource.TestCheckResourceAttrSet(attachmentResourceName, "vpc_connectivity_profile"), ), }, { @@ -86,7 +89,6 @@ func TestAccResourceNsxtVpc_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccNsxtVpcExists(accTestVpcCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttrSet(testResourceName, "vpc_service_profile"), - resource.TestCheckResourceAttrSet(testResourceName, "vpc_connectivity_profile"), resource.TestCheckResourceAttr(testResourceName, "short_id", accTestVpcUpdateAttributes["short_id"]), resource.TestCheckResourceAttr(testResourceName, "load_balancer_vpc_endpoint.#", "0"), resource.TestCheckResourceAttr(testResourceName, "description", ""), @@ -101,7 +103,6 @@ func TestAccResourceNsxtVpc_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccNsxtVpcExists(accTestVpcCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttrSet(testResourceName, "vpc_service_profile"), - resource.TestCheckResourceAttrSet(testResourceName, "vpc_connectivity_profile"), resource.TestCheckResourceAttr(testResourceName, "load_balancer_vpc_endpoint.#", "0"), resource.TestCheckResourceAttr(testResourceName, "description", ""), resource.TestCheckResourceAttr(testResourceName, "short_id", accTestVpcUpdateAttributes["short_id"]), @@ -226,8 +227,7 @@ resource "nsxt_vpc" "test" { private_ips = ["%s"] short_id = "%s" - vpc_service_profile = nsxt_vpc_service_profile.test.path - vpc_connectivity_profile = nsxt_vpc_connectivity_profile.test.path + vpc_service_profile = nsxt_vpc_service_profile.test.path load_balancer_vpc_endpoint { enabled = %s @@ -237,7 +237,14 @@ resource "nsxt_vpc" "test" { scope = "scope1" tag = "tag1" } -}`, testAccNsxtProjectContext(), attrMap["display_name"], attrMap["description"], attrMap["private_ips"], attrMap["short_id"], attrMap["enabled"]) +} + +resource "nsxt_vpc_attachment" "test" { + display_name = "%s" + parent_path = nsxt_vpc.test.path + vpc_connectivity_profile = nsxt_vpc_connectivity_profile.test.path +} +`, testAccNsxtProjectContext(), attrMap["display_name"], attrMap["description"], attrMap["private_ips"], attrMap["short_id"], attrMap["enabled"], attrMap["display_name"]) } func testAccNsxtVpcMinimalistic() string { @@ -249,7 +256,6 @@ resource "nsxt_vpc" "test" { short_id = "%s" # TODO - remove when default profiles are supported vpc_service_profile = nsxt_vpc_service_profile.test.path - vpc_connectivity_profile = nsxt_vpc_connectivity_profile.test.path }`, testAccNsxtProjectContext(), accTestVpcUpdateAttributes["display_name"], accTestVpcUpdateAttributes["short_id"]) } @@ -262,6 +268,5 @@ resource "nsxt_vpc" "test" { display_name = "%s" # TODO - remove when default profiles are supported vpc_service_profile = nsxt_vpc_service_profile.test.path - vpc_connectivity_profile = nsxt_vpc_connectivity_profile.test.path }`, testAccNsxtProjectContext(), accTestVpcUpdateAttributes["short_id"], accTestVpcUpdateAttributes["display_name"]) } diff --git a/website/docs/r/vpc.html.markdown b/website/docs/r/vpc.html.markdown index 415b20aaa..2dbf6ca83 100644 --- a/website/docs/r/vpc.html.markdown +++ b/website/docs/r/vpc.html.markdown @@ -41,7 +41,6 @@ The following arguments are supported: * `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource. * `private_ips` - (Optional) IP CIDRs to manage private IPv4 subnets. * `vpc_service_profile` - (Optional) The path of the configuration profile of the VPC services. -* `vpc_connectivity_profile` - (Optional) The path of the configuration profile for the VPC transit gateway attachment. * `load_balancer_vpc_endpoint` - (Optional) Configuration for Load Balancer Endpoint * `enabled` - (Optional) Flag to indicate whether support for load balancing is needed. Setting this flag to `true` causes allocation of private IPs from the private block associated with this VPC for the use of the load balancer. * `ip_address_type` - (Optional) This defines the IP address type that will be allocated for subnets. diff --git a/website/docs/r/vpc_attachment.html.markdown b/website/docs/r/vpc_attachment.html.markdown new file mode 100644 index 000000000..d34c7ac24 --- /dev/null +++ b/website/docs/r/vpc_attachment.html.markdown @@ -0,0 +1,68 @@ +--- +subcategory: "VPC" +layout: "nsxt" +page_title: "NSXT: nsxt_vpc_attachment" +description: A resource to configure VPC attachment. +--- + +# nsxt_vpc_attachment + +This resource provides a method for the management of VPC Attachment. + +This resource is applicable to NSX Policy Manager. + +## Example Usage + +```hcl +data "nsxt_vpc" "test" { + context { + project_id = data.nsxt_policy_project.dev.id + } + display_name = "test" +} + +data "nsxt_vpc_connectivity_profile" "test" { + context { + project_id = data.nsxt_policy_project.dev.id + } + display_name = "test" +} + +resource "nsxt_vpc_attachment" "test" { + display_name = "test" + description = "terraform provisioned vpc attachment" + parent_path = data.nsxt_vpc.test.path + vpc_connectivity_profile = data.nsxt_vpc_connectivity_profile.test.path +} +``` + +## Argument Reference + +The following arguments are supported: + +* `display_name` - (Required) Display name of the resource. +* `description` - (Optional) Description of the resource. +* `tag` - (Optional) A list of scope + tag pairs to associate with this resource. +* `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource. +* `parent_path` - (Required) Policy path of parent VPC object. +* `vpc_connectivity_profile` - (Required) Path of VPC connectivity profile to attach to the VPC. + +## Attributes Reference + +In addition to arguments listed above, the following attributes are exported: + +* `id` - ID of the resource. +* `revision` - Indicates current revision number of the object as seen by NSX-T API server. This attribute can be useful for debugging. +* `path` - The NSX path of the policy resource. + +## Importing + +An existing object can be [imported][docs-import] into this resource, via the following command: + +[docs-import]: https://www.terraform.io/cli/import + +``` +terraform import nsxt_vpc_attachment.test PATH +``` + +The above command imports VPC Attachment named `test` with the policy path `PATH`.