Skip to content

Commit

Permalink
fix: Correctly handle GCP updates of mongodbatlas_network_peering (#…
Browse files Browse the repository at this point in the history
…2306)

* correctly handle GCP updates of network peering

* changelog

* fix changelog

* remove unnecessary comment

* Update .changelog/2306.txt

Co-authored-by: kanchana-mongodb <[email protected]>

---------

Co-authored-by: kanchana-mongodb <[email protected]>
  • Loading branch information
oarbusi and kanchana-mongodb authored May 28, 2024
1 parent 065af27 commit f81f690
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/2306.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/mongodbatlas_network_peering: Correctly handles GCP updates of mongodbatlas_network_peering
```
10 changes: 3 additions & 7 deletions internal/service/networkpeering/resource_network_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ func Resource() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"network_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"atlas_gcp_project_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -410,13 +412,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.
ContainerId: conversion.GetEncodedID(d.Get("container_id").(string), "container_id"),
}

// Updating any of the attributes for Azure Network Peering forces a recreation of the network peering.
// Need to check if GCP and AWS have the same behavior
switch peer.GetProviderName() {
case "GCP":
peer.SetGcpProjectId(d.Get("gcp_project_id").(string))
peer.SetNetworkName(d.Get("network_name").(string))
default: // AWS by default
if peer.GetProviderName() == "AWS" {
region, _ := conversion.ValRegion(d.Get("accepter_region_name"), "network_peering")
peer.SetAccepterRegionName(region)
peer.SetAwsAccountId(d.Get("aws_account_id").(string))
Expand Down
46 changes: 46 additions & 0 deletions internal/service/networkpeering/resource_network_peering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,52 @@ func TestAccNetworkRSNetworkPeering_basicGCP(t *testing.T) {
})
}

func TestAccNetworkRSNetworkPeering_updateBasicGCP(t *testing.T) {
acc.SkipTestForCI(t) // needs GCP configuration

var (
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
providerName = "GCP"
gcpProjectID = os.Getenv("GCP_PROJECT_ID")
networkName = acc.RandomName()
updatedNetworkName = acc.RandomName()
)

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.PreCheck(t); acc.PreCheckPeeringEnvGCP(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyNetworkPeering,
Steps: []resource.TestStep{
{
Config: configGCP(projectID, providerName, gcpProjectID, networkName),
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "container_id"),
resource.TestCheckResourceAttrSet(resourceName, "network_name"),

resource.TestCheckResourceAttr(resourceName, "provider_name", providerName),
resource.TestCheckResourceAttr(resourceName, "gcp_project_id", gcpProjectID),
resource.TestCheckResourceAttr(resourceName, "network_name", networkName),
),
},
{
Config: configGCP(projectID, providerName, gcpProjectID, updatedNetworkName),
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "container_id"),
resource.TestCheckResourceAttrSet(resourceName, "network_name"),

resource.TestCheckResourceAttr(resourceName, "provider_name", providerName),
resource.TestCheckResourceAttr(resourceName, "gcp_project_id", gcpProjectID),
resource.TestCheckResourceAttr(resourceName, "network_name", updatedNetworkName),
),
},
},
})
}

func TestAccNetworkRSNetworkPeering_AWSDifferentRegionName(t *testing.T) {
var (
vpcID = os.Getenv("AWS_VPC_ID")
Expand Down

0 comments on commit f81f690

Please sign in to comment.