diff --git a/aviatrix/resource_aviatrix_segmentation_network_domain_association.go b/aviatrix/resource_aviatrix_segmentation_network_domain_association.go index f1d7817c5..92f241f71 100644 --- a/aviatrix/resource_aviatrix_segmentation_network_domain_association.go +++ b/aviatrix/resource_aviatrix_segmentation_network_domain_association.go @@ -32,9 +32,12 @@ func resourceAviatrixSegmentationNetworkDomainAssociation() *schema.Resource { Description: "Attachment name. For spoke gateways, use spoke gateway name. For VLAN, use :.", }, "transit_gateway_name": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return true + }, Description: "Transit Gateway name.", }, }, @@ -76,7 +79,6 @@ func resourceAviatrixSegmentationNetworkDomainAssociationReadIfRequired(d *schem func resourceAviatrixSegmentationNetworkDomainAssociationRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*goaviatrix.Client) - transitGatewayName := d.Get("transit_gateway_name").(string) networkDomainName := d.Get("network_domain_name").(string) attachmentName := d.Get("attachment_name").(string) if networkDomainName == "" { @@ -89,7 +91,6 @@ func resourceAviatrixSegmentationNetworkDomainAssociationRead(d *schema.Resource } association := &goaviatrix.SegmentationSecurityDomainAssociation{ - TransitGatewayName: transitGatewayName, SecurityDomainName: networkDomainName, AttachmentName: attachmentName, } @@ -103,9 +104,10 @@ func resourceAviatrixSegmentationNetworkDomainAssociationRead(d *schema.Resource return fmt.Errorf("could not find segmentation_network_domain_association %s: %v", networkDomainName+"~"+attachmentName, err) } - d.Set("transit_gateway_name", association.TransitGatewayName) d.Set("network_domain_name", networkDomainName) d.Set("attachment_name", attachmentName) + d.Set("transit_gateway_name", association.TransitGatewayName) + d.SetId(networkDomainName + "~" + attachmentName) return nil diff --git a/aviatrix/resource_aviatrix_segmentation_network_domain_association_test.go b/aviatrix/resource_aviatrix_segmentation_network_domain_association_test.go index e71467577..62deb1d4c 100644 --- a/aviatrix/resource_aviatrix_segmentation_network_domain_association_test.go +++ b/aviatrix/resource_aviatrix_segmentation_network_domain_association_test.go @@ -5,8 +5,9 @@ import ( "os" "testing" - "github.com/AviatrixSystems/terraform-provider-aviatrix/v3/goaviatrix" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + + "github.com/AviatrixSystems/terraform-provider-aviatrix/v3/goaviatrix" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) @@ -17,16 +18,13 @@ func TestAccAviatrixSegmentationNetworkDomainAssociation_basic(t *testing.T) { } rName := acctest.RandString(5) - msg := ". Set SKIP_SEGMENTATION_NETWORK_DOMAIN_ASSOCIATION to yes to skip segmentation network domain association tests." resourceName := "aviatrix_segmentation_network_domain_association.test_segmentation_network_domain_association" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) - preGatewayCheck(t, msg) - preGateway2Check(t, msg) }, - Providers: testAccProviders, + Providers: testAccProvidersVersionValidation, CheckDestroy: testAccCheckSegmentationNetworkDomainAssociationDestroy, Steps: []resource.TestStep{ { @@ -55,27 +53,14 @@ resource "aviatrix_account" "test_acc_aws" { aws_secret_key = "%s" } -resource "aviatrix_transit_gateway" "test_transit_gateway" { - cloud_type = 1 - account_name = aviatrix_account.test_acc_aws.account_name - gw_name = "transit-aws-%[1]s" - vpc_id = "%[5]s" - vpc_reg = "%[6]s" - gw_size = "t2.micro" - subnet = "%[7]s" - enable_segmentation = true - connected_transit = true -} - resource "aviatrix_spoke_gateway" "test_spoke_gateway" { - cloud_type = 1 - account_name = aviatrix_account.test_acc_aws.account_name - gw_name = "spoke-aws-%[1]s" - vpc_id = "%[8]s" - vpc_reg = "%[9]s" - gw_size = "t2.micro" - subnet = "%[10]s" - transit_gw = aviatrix_transit_gateway.test_transit_gateway.gw_name + cloud_type = 1 + account_name = aviatrix_account.test_acc_aws.account_name + gw_name = "spoke-aws-%[1]s" + vpc_id = "%[5]s" + vpc_reg = "%[6]s" + gw_size = "t2.micro" + subnet = "%[7]s" } resource "aviatrix_segmentation_network_domain" "test_segmentation_network_domain" { @@ -83,13 +68,12 @@ resource "aviatrix_segmentation_network_domain" "test_segmentation_network_domai } resource "aviatrix_segmentation_network_domain_association" "test_segmentation_network_domain_association" { - transit_gateway_name = aviatrix_transit_gateway.test_transit_gateway.gw_name - network_domain_name = aviatrix_segmentation_network_domain.test_segmentation_network_domain.domain_name - attachment_name = aviatrix_spoke_gateway.test_spoke_gateway.gw_name + network_domain_name = aviatrix_segmentation_network_domain.test_segmentation_network_domain.domain_name + attachment_name = aviatrix_spoke_gateway.test_spoke_gateway.gw_name +} } `, rName, os.Getenv("AWS_ACCOUNT_NUMBER"), os.Getenv("AWS_ACCESS_KEY"), os.Getenv("AWS_SECRET_KEY"), - os.Getenv("AWS_VPC_ID"), os.Getenv("AWS_REGION"), os.Getenv("AWS_SUBNET"), - os.Getenv("AWS_VPC_ID2"), os.Getenv("AWS_REGION2"), os.Getenv("AWS_SUBNET2")) + os.Getenv("AWS_VPC_ID"), os.Getenv("AWS_REGION"), os.Getenv("AWS_SUBNET")) } func testAccCheckSegmentationNetworkDomainAssociationExists(n string) resource.TestCheckFunc { @@ -102,10 +86,9 @@ func testAccCheckSegmentationNetworkDomainAssociationExists(n string) resource.T return fmt.Errorf("no segmentation_network_domain_association ID is set") } - client := testAccProvider.Meta().(*goaviatrix.Client) + client := testAccProviderVersionValidation.Meta().(*goaviatrix.Client) association := &goaviatrix.SegmentationSecurityDomainAssociation{ - TransitGatewayName: rs.Primary.Attributes["transit_gateway_name"], SecurityDomainName: rs.Primary.Attributes["network_domain_name"], AttachmentName: rs.Primary.Attributes["attachment_name"], } @@ -115,7 +98,7 @@ func testAccCheckSegmentationNetworkDomainAssociationExists(n string) resource.T return err } - id := association.TransitGatewayName + "~" + association.SecurityDomainName + "~" + association.AttachmentName + id := association.SecurityDomainName + "~" + association.AttachmentName if id != rs.Primary.ID { return fmt.Errorf("segmentation_network_domain_association not found") } @@ -125,14 +108,13 @@ func testAccCheckSegmentationNetworkDomainAssociationExists(n string) resource.T } func testAccCheckSegmentationNetworkDomainAssociationDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*goaviatrix.Client) + client := testAccProviderVersionValidation.Meta().(*goaviatrix.Client) for _, rs := range s.RootModule().Resources { if rs.Type != "aviatrix_segmentation_network_domain_association" { continue } association := &goaviatrix.SegmentationSecurityDomainAssociation{ - TransitGatewayName: rs.Primary.Attributes["transit_gateway_name"], SecurityDomainName: rs.Primary.Attributes["network_domain_name"], AttachmentName: rs.Primary.Attributes["attachment_name"], } diff --git a/docs/resources/aviatrix_segmentation_network_domain_association.md b/docs/resources/aviatrix_segmentation_network_domain_association.md index de0255086..33200abb4 100644 --- a/docs/resources/aviatrix_segmentation_network_domain_association.md +++ b/docs/resources/aviatrix_segmentation_network_domain_association.md @@ -31,6 +31,8 @@ The following arguments are supported: ### Optional +-> **NOTE:** `transit_gateway_name` is an optional and computed attribute now, and it will only be a computed attribute in the V3.2.0 release. + * `transit_gateway_name` - (Optional) Name of the Transit Gateway. ## Import