Skip to content

Add client, permissions, monitoring and mfa configs to google_identity_platform_config #9609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions mmv1/products/identityplatform/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ examples:
test_vars_overrides:
# Set quota start time for the following day.
quota_start_time: 'time.Now().AddDate(0, 0, 1).Format(time.RFC3339)'
ignore_read_extra:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need ignore_read_extra for output-only values I think?

Copy link
Contributor Author

@gleichda gleichda Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above:
without the ingore read for the outputs the test fails: (This also feels a little bit flaky not happening every time but regularly)

=== NAME  TestAccIdentityPlatformConfig_identityPlatformConfigBasicExample
    vcr_utils.go:152: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.

        (map[string]string) (len=1) {
         (string) (len=27) "client.0.firebase_subdomain": (string) (len=28) "tf-test-my-projectswbrzvojnv"
        }


        (map[string]string) (len=1) {
         (string) (len=27) "client.0.firebase_subdomain": (string) ""
        }
        ```

- "client.0.api_key"
- "client.0.firebase_subdomain"
skip_vcr: true
- !ruby/object:Provider::Terraform::Examples
name: 'identity_platform_config_minimal'
Expand Down Expand Up @@ -254,3 +257,118 @@ properties:
description: |
Two letter unicode region codes to allow as defined by https://cldr.unicode.org/ The full list of these region codes is here: https://github.com/unicode-cldr/cldr-localenames-full/blob/master/main/en/territories.json
item_type: Api::Type::String
- !ruby/object:Api::Type::NestedObject
name: 'client'
description: |
Options related to how clients making requests on behalf of a project should be configured.
default_from_api: true
properties:
- !ruby/object:Api::Type::NestedObject
name: 'permissions'
custom_flatten: templates/terraform/custom_flatten/identity_platform_config_client_permissions.go.erb
description: |
Configuration related to restricting a user's ability to affect their account.
properties:
- !ruby/object:Api::Type::Boolean
name: 'disabledUserSignup'
description: |
When true, end users cannot sign up for a new account on the associated project through any of our API methods
- !ruby/object:Api::Type::Boolean
name: 'disabledUserDeletion'
description: |
When true, end users cannot delete their account on the associated project through any of our API methods
- !ruby/object:Api::Type::String
name: 'apiKey'
output: true
description: |
API key that can be used when making requests for this project.
sensitive: true
- !ruby/object:Api::Type::String
name: 'firebaseSubdomain'
output: true
description: |
Firebase subdomain.
- !ruby/object:Api::Type::NestedObject
name: 'mfa'
description: |
Options related to how clients making requests on behalf of a project should be configured.
default_from_api: true
properties:
- !ruby/object:Api::Type::Enum
name: 'state'
description: |
Whether MultiFactor Authentication has been enabled for this project.
default_from_api: true
values:
- :DISABLED
- :ENABLED
- :MANDATORY
- !ruby/object:Api::Type::Array
name: enabledProviders
description: |
A list of usable second factors for this project.
item_type: !ruby/object:Api::Type::Enum
name: 'undefined'
description: |
This field only has a name and description because of MM
limitations. It should not appear in downstreams.
values:
- :PHONE_SMS
- !ruby/object:Api::Type::Array
name: providerConfigs
description: |
A list of usable second factors for this project along with their configurations.
This field does not support phone based MFA, for that use the 'enabledProviders' field.
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::Enum
name: 'state'
default_from_api: true
description: |
Whether MultiFactor Authentication has been enabled for this project.
values:
- :DISABLED
- :ENABLED
- :MANDATORY
- !ruby/object:Api::Type::NestedObject
name: totpProviderConfig
description: |
TOTP MFA provider config for this project.
properties:
- !ruby/object:Api::Type::Integer
name: adjacentIntervals
description: |
The allowed number of adjacent intervals that will be used for verification to avoid clock skew.
- !ruby/object:Api::Type::NestedObject
name: 'multiTenant'
description: |
Configuration related to multi-tenant functionality.
properties:
- !ruby/object:Api::Type::Boolean
name: 'allowTenants'
description: |
Whether this project can have tenants or not.
- !ruby/object:Api::Type::String
name: 'defaultTenantLocation'
description: |
The default cloud parent org or folder that the tenant project should be created under.
The parent resource name should be in the format of "/", such as "folders/123" or "organizations/456".
If the value is not set, the tenant will be created under the same organization or folder as the agent project.
- !ruby/object:Api::Type::NestedObject
name: 'monitoring'
description: |
Configuration related to monitoring project activity.
default_from_api: true
properties:
- !ruby/object:Api::Type::NestedObject
name: 'requestLogging'
description: |
Configuration for logging requests made to this project to Stackdriver Logging
custom_flatten: templates/terraform/custom_flatten/identity_platform_config_logging.go.erb
send_empty_value: true
properties:
- !ruby/object:Api::Type::Boolean
name: enabled
description: |
Whether logging is enabled for this project or not.
send_empty_value: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}

original := v.(map[string]interface{})
transformed := make(map[string]interface{})

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

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

return []interface{}{transformed}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}

original := v.(map[string]interface{})
transformed := make(map[string]interface{})

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

return []interface{}{transformed}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,33 @@ resource "google_project_service" "identitytoolkit" {

resource "google_identity_platform_config" "default" {
project = google_project.default.project_id

client {
permissions {
disabled_user_deletion = false
disabled_user_signup = true
}
}

mfa {
enabled_providers = ["PHONE_SMS"]
provider_configs {
state = "ENABLED"
totp_provider_config {
adjacent_intervals = 3
}
}
state = "ENABLED"
}
monitoring {
request_logging {
enabled = true
}
}
multi_tenant {
allow_tenants = true
default_tenant_location = "organizations/<%= ctx[:test_env_vars]['org_id'] %>"
}

depends_on = [
google_project_service.identitytoolkit
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ func TestAccIdentityPlatformConfig_update(t *testing.T) {
Config: testAccIdentityPlatformConfig_basic(context),
},
{
ResourceName: "google_identity_platform_config.basic",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_identity_platform_config.basic",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"client", "mfa", "monitoring"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need ignore state verify here? If these are default_from_api it should just accept the server's value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed/or at least reduced to the outputs.
Without the outputs the test fail:

=== NAME  TestAccIdentityPlatformConfig_identityPlatformConfigBasicExample
    vcr_utils.go:152: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.

        (map[string]string) (len=1) {
         (string) (len=27) "client.0.firebase_subdomain": (string) (len=28) "tf-test-my-projectswbrzvojnv"
        }


        (map[string]string) (len=1) {
         (string) (len=27) "client.0.firebase_subdomain": (string) ""
        }

I'm not sure where this comes from but the actual expected is returned from the API therefor excluding this was my solution but happy to learn how to properly fix this

},
{
Config: testAccIdentityPlatformConfig_update(context),
},
{
ResourceName: "google_identity_platform_config.basic",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_identity_platform_config.basic",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"client", "mfa", "monitoring"},
},
},
})
Expand Down Expand Up @@ -90,6 +92,35 @@ resource "google_identity_platform_config" "basic" {
]
}
}

client {
permissions {
disabled_user_deletion = true
disabled_user_signup = true
}
}

mfa {
enabled_providers = ["PHONE_SMS"]
provider_configs {
state = "ENABLED"
totp_provider_config {
adjacent_intervals = 3
}
}
state = "ENABLED"
}

monitoring {
request_logging {
enabled = true
}
}

multi_tenant {
allow_tenants = true
default_tenant_location = "organizations/%{org_id}"
}
}
`, context)
}
Expand Down Expand Up @@ -138,6 +169,23 @@ resource "google_identity_platform_config" "basic" {
]
}
}

client {
permissions {
disabled_user_deletion = false
disabled_user_signup = false
}
}

mfa {
enabled_providers = ["PHONE_SMS"]
state = "DISABLED"
}
monitoring {
request_logging {
enabled = false
}
}
}
`, context)
}