Skip to content

Commit 45a5d3c

Browse files
Send empty log_config value (#5154) (#3581)
Signed-off-by: Modular Magician <[email protected]>
1 parent d37c846 commit 45a5d3c

File tree

4 files changed

+99
-4
lines changed

4 files changed

+99
-4
lines changed

.changelog/5154.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: fixed an issue in `google_compute_router_nat` where removing `log_config` resulted in a perma-diff
3+
```

google-beta/resource_compute_router_nat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
395395
logConfigProp, err := expandNestedComputeRouterNatLogConfig(d.Get("log_config"), d, config)
396396
if err != nil {
397397
return err
398-
} else if v, ok := d.GetOkExists("log_config"); !isEmptyValue(reflect.ValueOf(logConfigProp)) && (ok || !reflect.DeepEqual(v, logConfigProp)) {
398+
} else if v, ok := d.GetOkExists("log_config"); ok || !reflect.DeepEqual(v, logConfigProp) {
399399
obj["logConfig"] = logConfigProp
400400
}
401401
enableEndpointIndependentMappingProp, err := expandNestedComputeRouterNatEnableEndpointIndependentMapping(d.Get("enable_endpoint_independent_mapping"), d, config)
@@ -631,7 +631,7 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er
631631
logConfigProp, err := expandNestedComputeRouterNatLogConfig(d.Get("log_config"), d, config)
632632
if err != nil {
633633
return err
634-
} else if v, ok := d.GetOkExists("log_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, logConfigProp)) {
634+
} else if v, ok := d.GetOkExists("log_config"); ok || !reflect.DeepEqual(v, logConfigProp) {
635635
obj["logConfig"] = logConfigProp
636636
}
637637
enableEndpointIndependentMappingProp, err := expandNestedComputeRouterNatEnableEndpointIndependentMapping(d.Get("enable_endpoint_independent_mapping"), d, config)

google-beta/resource_compute_router_nat_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,37 @@ func TestAccComputeRouterNat_update(t *testing.T) {
114114
})
115115
}
116116

117+
func TestAccComputeRouterNat_removeLogConfig(t *testing.T) {
118+
t.Parallel()
119+
120+
testId := randString(t, 10)
121+
routerName := fmt.Sprintf("tf-test-router-nat-%s", testId)
122+
123+
vcrTest(t, resource.TestCase{
124+
PreCheck: func() { testAccPreCheck(t) },
125+
Providers: testAccProviders,
126+
CheckDestroy: testAccCheckComputeRouterNatDestroyProducer(t),
127+
Steps: []resource.TestStep{
128+
{
129+
Config: testAccComputeRouterNatLogConfig(routerName),
130+
},
131+
{
132+
ResourceName: "google_compute_router_nat.foobar",
133+
ImportState: true,
134+
ImportStateVerify: true,
135+
},
136+
{
137+
Config: testAccComputeRouterNatLogConfigRemoved(routerName),
138+
},
139+
{
140+
ResourceName: "google_compute_router_nat.foobar",
141+
ImportState: true,
142+
ImportStateVerify: true,
143+
},
144+
},
145+
})
146+
}
147+
117148
func TestAccComputeRouterNat_withManualIpAndSubnetConfiguration(t *testing.T) {
118149
t.Parallel()
119150

@@ -781,3 +812,65 @@ resource "google_compute_router" "foobar" {
781812
}
782813
`, routerName, routerName, routerName)
783814
}
815+
816+
func testAccComputeRouterNatLogConfig(routerName string) string {
817+
return fmt.Sprintf(`
818+
resource "google_compute_network" "foobar" {
819+
name = "%s-net"
820+
}
821+
822+
resource "google_compute_subnetwork" "foobar" {
823+
name = "%s-subnet"
824+
network = google_compute_network.foobar.self_link
825+
ip_cidr_range = "10.0.0.0/16"
826+
region = "us-central1"
827+
}
828+
829+
resource "google_compute_router" "foobar" {
830+
name = "%s"
831+
region = google_compute_subnetwork.foobar.region
832+
network = google_compute_network.foobar.self_link
833+
}
834+
835+
resource "google_compute_router_nat" "foobar" {
836+
name = "%s"
837+
router = google_compute_router.foobar.name
838+
region = google_compute_router.foobar.region
839+
nat_ip_allocate_option = "AUTO_ONLY"
840+
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
841+
log_config {
842+
enable = false
843+
filter = "ALL"
844+
}
845+
}
846+
`, routerName, routerName, routerName, routerName)
847+
}
848+
849+
func testAccComputeRouterNatLogConfigRemoved(routerName string) string {
850+
return fmt.Sprintf(`
851+
resource "google_compute_network" "foobar" {
852+
name = "%s-net"
853+
}
854+
855+
resource "google_compute_subnetwork" "foobar" {
856+
name = "%s-subnet"
857+
network = google_compute_network.foobar.self_link
858+
ip_cidr_range = "10.0.0.0/16"
859+
region = "us-central1"
860+
}
861+
862+
resource "google_compute_router" "foobar" {
863+
name = "%s"
864+
region = google_compute_subnetwork.foobar.region
865+
network = google_compute_network.foobar.self_link
866+
}
867+
868+
resource "google_compute_router_nat" "foobar" {
869+
name = "%s"
870+
router = google_compute_router.foobar.name
871+
region = google_compute_router.foobar.region
872+
nat_ip_allocate_option = "AUTO_ONLY"
873+
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
874+
}
875+
`, routerName, routerName, routerName, routerName)
876+
}

google-beta/resource_dataproc_cluster_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import (
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1515

16-
"google.golang.org/api/googleapi"
17-
1816
dataproc "google.golang.org/api/dataproc/v1beta2"
17+
"google.golang.org/api/googleapi"
1918
)
2019

2120
func TestDataprocExtractInitTimeout(t *testing.T) {

0 commit comments

Comments
 (0)