Skip to content

Commit b3dd7eb

Browse files
Subserialanoopkverma-google
authored andcommitted
google_artifact_registry_repository: Fix perma-diff in maven_config (GoogleCloudPlatform#12190)
1 parent 0b22c51 commit b3dd7eb

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

mmv1/products/artifactregistry/Repository.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ properties:
300300
Provides additional configuration details for repositories of the maven
301301
format type.
302302
allow_empty_object: true
303+
diff_suppress_func: 'emptyMavenConfigDiffSuppress'
303304
properties:
304305
# Maven properties.
305306
- name: 'allowSnapshotOverwrites'

mmv1/templates/terraform/constants/artifact_registry_repository.go.tmpl

+19
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,22 @@ func mapHashID(v any) int {
9595
obj := v.(map[string]any)
9696
return schema.HashString(obj["id"])
9797
}
98+
99+
func isDefaultEnum(val any) bool {
100+
s, ok := val.(string)
101+
if !ok {
102+
return false
103+
}
104+
return s == "" || strings.HasSuffix(s, "_UNSPECIFIED")
105+
}
106+
107+
// emptyMavenConfigDiffSuppress generates a config from defaults if it or any
108+
// properties are unset. Missing, empty and default configs are all equivalent.
109+
func emptyMavenConfigDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
110+
oSnap, nSnap := d.GetChange("maven_config.0.allow_snapshot_overwrites")
111+
if oSnap.(bool) != nSnap.(bool) {
112+
return false
113+
}
114+
oPolicy, nPolicy := d.GetChange("maven_config.0.version_policy")
115+
return isDefaultEnum(oPolicy) && isDefaultEnum(nPolicy)
116+
}

mmv1/third_party/terraform/services/artifactregistry/resource_artifact_registry_repository_test.go.tmpl

+69
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,38 @@ func TestAccArtifactRegistryRepository_createMvnRelease(t *testing.T) {
8484
})
8585
}
8686

87+
func TestAccArtifactRegistryRepository_updateEmptyMvn(t *testing.T) {
88+
t.Parallel()
89+
90+
repositoryID := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
91+
92+
acctest.VcrTest(t, resource.TestCase{
93+
PreCheck: func() { acctest.AccTestPreCheck(t) },
94+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
95+
CheckDestroy: testAccCheckArtifactRegistryRepositoryDestroyProducer(t),
96+
Steps: []resource.TestStep{
97+
{
98+
Config: testAccArtifactRegistryRepository_createMvnEmpty1(repositoryID),
99+
},
100+
{
101+
ResourceName: "google_artifact_registry_repository.test",
102+
ImportState: true,
103+
ImportStateVerify: true,
104+
},
105+
{
106+
Config: testAccArtifactRegistryRepository_createMvnEmpty2(repositoryID),
107+
PlanOnly: true,
108+
ExpectNonEmptyPlan: false,
109+
},
110+
{
111+
Config: testAccArtifactRegistryRepository_createMvnEmpty3(repositoryID),
112+
PlanOnly: true,
113+
ExpectNonEmptyPlan: false,
114+
},
115+
},
116+
})
117+
}
118+
87119
func TestAccArtifactRegistryRepository_kfp(t *testing.T) {
88120
t.Parallel()
89121

@@ -152,6 +184,43 @@ resource "google_artifact_registry_repository" "test" {
152184
`, repositoryID, versionPolicy)
153185
}
154186

187+
func testAccArtifactRegistryRepository_createMvnEmpty1(repositoryID string) string {
188+
return fmt.Sprintf(`
189+
resource "google_artifact_registry_repository" "test" {
190+
repository_id = "%s"
191+
location = "us-central1"
192+
description = "maven repository with empty maven_config"
193+
format = "MAVEN"
194+
}
195+
`, repositoryID)
196+
}
197+
198+
func testAccArtifactRegistryRepository_createMvnEmpty2(repositoryID string) string {
199+
return fmt.Sprintf(`
200+
resource "google_artifact_registry_repository" "test" {
201+
repository_id = "%s"
202+
location = "us-central1"
203+
description = "maven repository with empty maven_config"
204+
format = "MAVEN"
205+
maven_config { }
206+
}
207+
`, repositoryID)
208+
}
209+
210+
func testAccArtifactRegistryRepository_createMvnEmpty3(repositoryID string) string {
211+
return fmt.Sprintf(`
212+
resource "google_artifact_registry_repository" "test" {
213+
repository_id = "%s"
214+
location = "us-central1"
215+
description = "maven repository with empty maven_config"
216+
format = "MAVEN"
217+
maven_config {
218+
allow_snapshot_overwrites = false
219+
}
220+
}
221+
`, repositoryID)
222+
}
223+
155224
func testAccArtifactRegistryRepository_kfp(repositoryID string) string {
156225
return fmt.Sprintf(`
157226
resource "google_artifact_registry_repository" "test" {

0 commit comments

Comments
 (0)