Skip to content

Commit

Permalink
AVX-46698: make transit_gateway_name optional and computed in segment…
Browse files Browse the repository at this point in the history
…ation_network_domain_association and ignore diff (#1880)
  • Loading branch information
shuoliugit authored Oct 10, 2023
1 parent 9493f16 commit e49f3ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ func resourceAviatrixSegmentationNetworkDomainAssociation() *schema.Resource {
Description: "Attachment name. For spoke gateways, use spoke gateway name. For VLAN, use <site-id>:<vlan-id>.",
},
"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.",
},
},
Expand Down Expand Up @@ -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 == "" {
Expand All @@ -89,7 +91,6 @@ func resourceAviatrixSegmentationNetworkDomainAssociationRead(d *schema.Resource
}

association := &goaviatrix.SegmentationSecurityDomainAssociation{
TransitGatewayName: transitGatewayName,
SecurityDomainName: networkDomainName,
AttachmentName: attachmentName,
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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{
{
Expand Down Expand Up @@ -55,41 +53,27 @@ 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" {
domain_name = "domain-name-%[1]s"
}
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 {
Expand All @@ -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"],
}
Expand All @@ -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")
}
Expand All @@ -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"],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e49f3ec

Please sign in to comment.