Skip to content

Commit f81f690

Browse files
fix: Correctly handle GCP updates of mongodbatlas_network_peering (#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]>
1 parent 065af27 commit f81f690

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

.changelog/2306.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/mongodbatlas_network_peering: Correctly handles GCP updates of mongodbatlas_network_peering
3+
```

internal/service/networkpeering/resource_network_peering.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ func Resource() *schema.Resource {
135135
Type: schema.TypeString,
136136
Optional: true,
137137
Computed: true,
138+
ForceNew: true,
138139
},
139140
"network_name": {
140141
Type: schema.TypeString,
141142
Optional: true,
142143
Computed: true,
144+
ForceNew: true,
143145
},
144146
"atlas_gcp_project_id": {
145147
Type: schema.TypeString,
@@ -410,13 +412,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.
410412
ContainerId: conversion.GetEncodedID(d.Get("container_id").(string), "container_id"),
411413
}
412414

413-
// Updating any of the attributes for Azure Network Peering forces a recreation of the network peering.
414-
// Need to check if GCP and AWS have the same behavior
415-
switch peer.GetProviderName() {
416-
case "GCP":
417-
peer.SetGcpProjectId(d.Get("gcp_project_id").(string))
418-
peer.SetNetworkName(d.Get("network_name").(string))
419-
default: // AWS by default
415+
if peer.GetProviderName() == "AWS" {
420416
region, _ := conversion.ValRegion(d.Get("accepter_region_name"), "network_peering")
421417
peer.SetAccepterRegionName(region)
422418
peer.SetAwsAccountId(d.Get("aws_account_id").(string))

internal/service/networkpeering/resource_network_peering_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,52 @@ func TestAccNetworkRSNetworkPeering_basicGCP(t *testing.T) {
142142
})
143143
}
144144

145+
func TestAccNetworkRSNetworkPeering_updateBasicGCP(t *testing.T) {
146+
acc.SkipTestForCI(t) // needs GCP configuration
147+
148+
var (
149+
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
150+
providerName = "GCP"
151+
gcpProjectID = os.Getenv("GCP_PROJECT_ID")
152+
networkName = acc.RandomName()
153+
updatedNetworkName = acc.RandomName()
154+
)
155+
156+
resource.Test(t, resource.TestCase{
157+
PreCheck: func() { acc.PreCheck(t); acc.PreCheckPeeringEnvGCP(t) },
158+
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
159+
CheckDestroy: acc.CheckDestroyNetworkPeering,
160+
Steps: []resource.TestStep{
161+
{
162+
Config: configGCP(projectID, providerName, gcpProjectID, networkName),
163+
Check: resource.ComposeTestCheckFunc(
164+
checkExists(resourceName),
165+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
166+
resource.TestCheckResourceAttrSet(resourceName, "container_id"),
167+
resource.TestCheckResourceAttrSet(resourceName, "network_name"),
168+
169+
resource.TestCheckResourceAttr(resourceName, "provider_name", providerName),
170+
resource.TestCheckResourceAttr(resourceName, "gcp_project_id", gcpProjectID),
171+
resource.TestCheckResourceAttr(resourceName, "network_name", networkName),
172+
),
173+
},
174+
{
175+
Config: configGCP(projectID, providerName, gcpProjectID, updatedNetworkName),
176+
Check: resource.ComposeTestCheckFunc(
177+
checkExists(resourceName),
178+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
179+
resource.TestCheckResourceAttrSet(resourceName, "container_id"),
180+
resource.TestCheckResourceAttrSet(resourceName, "network_name"),
181+
182+
resource.TestCheckResourceAttr(resourceName, "provider_name", providerName),
183+
resource.TestCheckResourceAttr(resourceName, "gcp_project_id", gcpProjectID),
184+
resource.TestCheckResourceAttr(resourceName, "network_name", updatedNetworkName),
185+
),
186+
},
187+
},
188+
})
189+
}
190+
145191
func TestAccNetworkRSNetworkPeering_AWSDifferentRegionName(t *testing.T) {
146192
var (
147193
vpcID = os.Getenv("AWS_VPC_ID")

0 commit comments

Comments
 (0)