Skip to content

Commit 1534796

Browse files
osconfig: fix permadiff where patch_config.yum.minimal doesn't send false for empty values (#15046) (#24247)
[upstream:cc70cc8f8613b9382904844bf56032345f83cece] Signed-off-by: Modular Magician <[email protected]>
1 parent 7f85b37 commit 1534796

File tree

3 files changed

+130
-1
lines changed

3 files changed

+130
-1
lines changed

.changelog/15046.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```release-note:bug
2+
osconfig: fix permadiff where `patch_config.yum.minimal` doesn't send `false` for empty values
3+
```
4+
5+
Implemented a specific test to reproduce the permadiff, but I'm fine removing it if it is too much overhead.
6+
7+
**Acceptance tests:**
8+
9+
```
10+
❮ make testacc TEST=./google/services/osconfig TESTARGS='-run=TestAccOSConfigPatchDeployment_'
11+
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google/services/osconfig -v -run=TestAccOSConfigPatchDeployment_ -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google/version.ProviderVersion=acc"
12+
=== RUN TestAccOSConfigPatchDeployment_osConfigPatchDeploymentBasicExample
13+
=== PAUSE TestAccOSConfigPatchDeployment_osConfigPatchDeploymentBasicExample
14+
=== RUN TestAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyExample
15+
=== PAUSE TestAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyExample
16+
=== RUN TestAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyMidnightExample
17+
=== PAUSE TestAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyMidnightExample
18+
=== RUN TestAccOSConfigPatchDeployment_osConfigPatchDeploymentInstanceExample
19+
=== PAUSE TestAccOSConfigPatchDeployment_osConfigPatchDeploymentInstanceExample
20+
=== RUN TestAccOSConfigPatchDeployment_osConfigPatchDeploymentFullExample
21+
=== PAUSE TestAccOSConfigPatchDeployment_osConfigPatchDeploymentFullExample
22+
=== RUN TestAccOSConfigPatchDeployment_osConfigPatchDeployment_yum_basic
23+
=== PAUSE TestAccOSConfigPatchDeployment_osConfigPatchDeployment_yum_basic
24+
=== CONT TestAccOSConfigPatchDeployment_osConfigPatchDeploymentBasicExample
25+
=== CONT TestAccOSConfigPatchDeployment_osConfigPatchDeploymentFullExample
26+
=== CONT TestAccOSConfigPatchDeployment_osConfigPatchDeployment_yum_basic
27+
=== CONT TestAccOSConfigPatchDeployment_osConfigPatchDeploymentInstanceExample
28+
=== CONT TestAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyMidnightExample
29+
=== CONT TestAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyExample
30+
--- PASS: TestAccOSConfigPatchDeployment_osConfigPatchDeploymentBasicExample (5.41s)
31+
--- PASS: TestAccOSConfigPatchDeployment_osConfigPatchDeployment_yum_basic (5.41s)
32+
--- PASS: TestAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyMidnightExample (5.43s)
33+
--- PASS: TestAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyExample (5.43s)
34+
--- PASS: TestAccOSConfigPatchDeployment_osConfigPatchDeploymentFullExample (5.76s)
35+
--- PASS: TestAccOSConfigPatchDeployment_osConfigPatchDeploymentInstanceExample (128.94s)
36+
PASS
37+
ok github.com/hashicorp/terraform-provider-google/google/services/osconfig 129.689s
38+
39+
```
40+
41+
Had to update the decoder as welll, because even if you provide `false` in the POST for the `patchConfig.yum.minimal`, the GET returns an empty object:
42+
43+
```
44+
"patchConfig": {
45+
"yum": {}
46+
},
47+
```

google/services/osconfig/resource_os_config_patch_deployment.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ func expandOSConfigPatchDeploymentPatchConfigYum(v interface{}, d tpgresource.Te
23582358
transformedMinimal, err := expandOSConfigPatchDeploymentPatchConfigYumMinimal(original["minimal"], d, config)
23592359
if err != nil {
23602360
return nil, err
2361-
} else if val := reflect.ValueOf(transformedMinimal); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2361+
} else {
23622362
transformed["minimal"] = transformedMinimal
23632363
}
23642364

@@ -3382,6 +3382,14 @@ func resourceOSConfigPatchDeploymentDecoder(d *schema.ResourceData, meta interfa
33823382
patchConfig["goo"].(map[string]interface{})["enabled"] = true
33833383
res["patchConfig"] = patchConfig
33843384
}
3385+
3386+
if patchConfig["yum"] != nil {
3387+
patchConfigYum := patchConfig["yum"].(map[string]interface{})
3388+
if _, ok := patchConfigYum["minimal"]; !ok {
3389+
patchConfigYum["minimal"] = false
3390+
}
3391+
patchConfig["yum"] = patchConfigYum
3392+
}
33853393
}
33863394

33873395
return res, nil
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
// ----------------------------------------------------------------------------
4+
//
5+
// *** AUTO GENERATED CODE *** Type: Handwritten ***
6+
//
7+
// ----------------------------------------------------------------------------
8+
//
9+
// This code is generated by Magic Modules using the following:
10+
//
11+
// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/osconfig/resource_os_config_patch_deployment_test.go
12+
//
13+
// DO NOT EDIT this file directly. Any changes made to this file will be
14+
// overwritten during the next generation cycle.
15+
//
16+
// ----------------------------------------------------------------------------
17+
package osconfig_test
18+
19+
import (
20+
"testing"
21+
22+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
23+
"github.com/hashicorp/terraform-provider-google/google/acctest"
24+
)
25+
26+
func TestAccOSConfigPatchDeployment_osConfigPatchDeployment_yum_basic(t *testing.T) {
27+
t.Parallel()
28+
29+
context := map[string]interface{}{
30+
"random_suffix": acctest.RandString(t, 10),
31+
}
32+
33+
acctest.VcrTest(t, resource.TestCase{
34+
PreCheck: func() { acctest.AccTestPreCheck(t) },
35+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
36+
CheckDestroy: testAccCheckOSConfigPatchDeploymentDestroyProducer(t),
37+
Steps: []resource.TestStep{
38+
{
39+
Config: testAccOSConfigPatchDeployment_osConfigPatchDeployment_yum_basic(context),
40+
Check: resource.ComposeTestCheckFunc(
41+
resource.TestCheckResourceAttr("google_os_config_patch_deployment.patch", "patch_config.0.yum.0.minimal", "false"),
42+
),
43+
},
44+
{
45+
ResourceName: "google_os_config_patch_deployment.patch",
46+
ImportState: true,
47+
ImportStateVerify: true,
48+
ImportStateVerifyIgnore: []string{"patch_deployment_id"},
49+
},
50+
},
51+
})
52+
}
53+
54+
func testAccOSConfigPatchDeployment_osConfigPatchDeployment_yum_basic(context map[string]interface{}) string {
55+
return acctest.Nprintf(`
56+
resource "google_os_config_patch_deployment" "patch" {
57+
patch_deployment_id = "tf-test-patch-deploy%{random_suffix}"
58+
59+
instance_filter {
60+
all = true
61+
}
62+
63+
patch_config {
64+
yum {
65+
minimal = false
66+
}
67+
}
68+
69+
one_time_schedule {
70+
execute_time = "2999-10-10T10:10:10.045123456Z"
71+
}
72+
}
73+
`, context)
74+
}

0 commit comments

Comments
 (0)