Skip to content

Commit

Permalink
Fix plan for google_identity_platform_config always showing a change …
Browse files Browse the repository at this point in the history
…for phone_number.enabled=false and email.enabled=false (#12255) (#8663)

[upstream:c3885741c9b1c21ba3ccd0c4128818891791952f]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Nov 8, 2024
1 parent 4f84ceb commit cce6847
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .changelog/12255.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note: bug
identityplatform: Fixed perma-diff in `google_identity_platform_config`
```
Original file line number Diff line number Diff line change
Expand Up @@ -840,49 +840,47 @@ func flattenIdentityPlatformConfigSignIn(v interface{}, d *schema.ResourceData,
return []interface{}{transformed}
}
func flattenIdentityPlatformConfigSignInEmail(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
transformed := make(map[string]interface{})

if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
transformed["enabled"] = false
} else {
original := v.(map[string]interface{})

if original["enabled"] == nil {
transformed["enabled"] = false
} else {
transformed["enabled"] = original["enabled"]
}

if original["passwordRequired"] != nil {
transformed["password_required"] = original["passwordRequired"]
}
}
transformed := make(map[string]interface{})
transformed["enabled"] =
flattenIdentityPlatformConfigSignInEmailEnabled(original["enabled"], d, config)
transformed["password_required"] =
flattenIdentityPlatformConfigSignInEmailPasswordRequired(original["passwordRequired"], d, config)
return []interface{}{transformed}
}
func flattenIdentityPlatformConfigSignInEmailEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenIdentityPlatformConfigSignInEmailPasswordRequired(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
return []interface{}{transformed}
}

func flattenIdentityPlatformConfigSignInPhoneNumber(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
transformed := make(map[string]interface{})

if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
transformed["enabled"] = false
} else {
original := v.(map[string]interface{})

if original["enabled"] == nil {
transformed["enabled"] = false
} else {
transformed["enabled"] = original["enabled"]
}

if original["testPhoneNumbers"] != nil {
transformed["test_phone_numbers"] = original["testPhoneNumbers"]
}
}
transformed := make(map[string]interface{})
transformed["enabled"] =
flattenIdentityPlatformConfigSignInPhoneNumberEnabled(original["enabled"], d, config)
transformed["test_phone_numbers"] =
flattenIdentityPlatformConfigSignInPhoneNumberTestPhoneNumbers(original["testPhoneNumbers"], d, config)
return []interface{}{transformed}
}
func flattenIdentityPlatformConfigSignInPhoneNumberEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenIdentityPlatformConfigSignInPhoneNumberTestPhoneNumbers(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
return []interface{}{transformed}
}

func flattenIdentityPlatformConfigSignInAnonymous(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,66 @@ resource "google_identity_platform_config" "default" {
}
`, context)
}

func TestAccIdentityPlatformConfig_identityPlatformConfigWithFalseValuesExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"billing_acct": envvar.GetTestBillingAccountFromEnv(t),
"org_id": envvar.GetTestOrgFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccIdentityPlatformConfig_identityPlatformConfigWithFalseValuesExample(context),
},
{
ResourceName: "google_identity_platform_config.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"client.0.api_key", "client.0.firebase_subdomain"},
},
},
})
}

func testAccIdentityPlatformConfig_identityPlatformConfigWithFalseValuesExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_project" "default" {
project_id = "tf-test-my-project-2%{random_suffix}"
name = "tf-test-my-project-2%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_acct}"
deletion_policy = "DELETE"
labels = {
firebase = "enabled"
}
}
resource "google_project_service" "identitytoolkit" {
project = google_project.default.project_id
service = "identitytoolkit.googleapis.com"
}
resource "google_identity_platform_config" "default" {
project = google_project.default.project_id
autodelete_anonymous_users = false
sign_in {
anonymous {
enabled = false
}
email {
enabled = false
}
phone_number {
enabled = false
}
}
}
`, context)
}

0 comments on commit cce6847

Please sign in to comment.