Skip to content

Commit

Permalink
Merge pull request #5398 from modular-magician/codegen-pr-2969
Browse files Browse the repository at this point in the history
Fix identity platform default_supported_idp_config. Needs separate id…
  • Loading branch information
slevenick authored Jan 14, 2020
2 parents 8ee9fef + 95e6fc8 commit 09520ea
Showing 9 changed files with 142 additions and 37 deletions.
55 changes: 45 additions & 10 deletions google/resource_identity_platform_default_supported_idp_config.go
Original file line number Diff line number Diff line change
@@ -45,14 +45,39 @@ func resourceIdentityPlatformDefaultSupportedIdpConfig() *schema.Resource {
"client_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `OAuth client ID`,
},
"client_secret": {
Type: schema.TypeString,
Required: true,
Description: `OAuth client secret`,
},
"idp_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `ID of the IDP. Possible values include:
* 'apple.com'
* 'facebook.com'
* 'gc.apple.com'
* 'github.com'
* 'google.com'
* 'linkedin.com'
* 'microsoft.com'
* 'playgames.google.com'
* 'twitter.com'
* 'yahoo.com'`,
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
@@ -96,7 +121,7 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigCreate(d *schema.ResourceD
obj["enabled"] = enabledProp
}

url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/defaultSupportedIdpConfigs?idpId={{client_id}}")
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/defaultSupportedIdpConfigs?idpId={{idp_id}}")
if err != nil {
return err
}
@@ -112,7 +137,7 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigCreate(d *schema.ResourceD
}

// Store the ID now
id, err := replaceVars(d, config, "projects/{{project}}/defaultSupportedIdpConfigs/{{client_id}}")
id, err := replaceVars(d, config, "projects/{{project}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
@@ -126,7 +151,7 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigCreate(d *schema.ResourceD
func resourceIdentityPlatformDefaultSupportedIdpConfigRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/defaultSupportedIdpConfigs/{{client_id}}")
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return err
}
@@ -169,6 +194,12 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigUpdate(d *schema.ResourceD
}

obj := make(map[string]interface{})
clientIdProp, err := expandIdentityPlatformDefaultSupportedIdpConfigClientId(d.Get("client_id"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("client_id"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, clientIdProp)) {
obj["clientId"] = clientIdProp
}
clientSecretProp, err := expandIdentityPlatformDefaultSupportedIdpConfigClientSecret(d.Get("client_secret"), d, config)
if err != nil {
return err
@@ -182,14 +213,18 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigUpdate(d *schema.ResourceD
obj["enabled"] = enabledProp
}

url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/defaultSupportedIdpConfigs/{{client_id}}")
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return err
}

log.Printf("[DEBUG] Updating DefaultSupportedIdpConfig %q: %#v", d.Id(), obj)
updateMask := []string{}

if d.HasChange("client_id") {
updateMask = append(updateMask, "clientId")
}

if d.HasChange("client_secret") {
updateMask = append(updateMask, "clientSecret")
}
@@ -220,7 +255,7 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigDelete(d *schema.ResourceD
return err
}

url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/defaultSupportedIdpConfigs/{{client_id}}")
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return err
}
@@ -240,15 +275,15 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigDelete(d *schema.ResourceD
func resourceIdentityPlatformDefaultSupportedIdpConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
if err := parseImportId([]string{
"projects/(?P<project>[^/]+)/defaultSupportedIdpConfigs/(?P<client_id>[^/]+)",
"(?P<project>[^/]+)/(?P<client_id>[^/]+)",
"(?P<client_id>[^/]+)",
"projects/(?P<project>[^/]+)/defaultSupportedIdpConfigs/(?P<idp_id>[^/]+)",
"(?P<project>[^/]+)/(?P<idp_id>[^/]+)",
"(?P<idp_id>[^/]+)",
}, d, config); err != nil {
return nil, err
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "projects/{{project}}/defaultSupportedIdpConfigs/{{client_id}}")
id, err := replaceVars(d, config, "projects/{{project}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ func testSweepIdentityPlatformDefaultSupportedIdpConfig(region string) error {
continue
}

deleteTemplate := "https://identitytoolkit.googleapis.com/v2/projects/{{project}}/defaultSupportedIdpConfigs/{{client_id}}"
deleteTemplate := "https://identitytoolkit.googleapis.com/v2/projects/{{project}}/defaultSupportedIdpConfigs/{{idp_id}}"
deleteUrl, err := replaceVars(d, config, deleteTemplate)
if err != nil {
log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err)
Original file line number Diff line number Diff line change
@@ -71,7 +71,8 @@ func testAccIdentityPlatformDefaultSupportedIdpConfig_defaultSupportedIdpConfigB
return Nprintf(`
resource "google_identity_platform_default_supported_idp_config" "idp_config" {
enabled = true
client_id = "playgames.google.com"
idp_id = "playgames.google.com"
client_id = "client-id"
client_secret = "secret"
}
`, context)
@@ -81,7 +82,8 @@ func testAccIdentityPlatformDefaultSupportedIdpConfig_defaultSupportedIdpConfigU
return Nprintf(`
resource "google_identity_platform_default_supported_idp_config" "idp_config" {
enabled = false
client_id = "playgames.google.com"
idp_id = "playgames.google.com"
client_id = "client-id"
client_secret = "anothersecret"
}
`, context)
Original file line number Diff line number Diff line change
@@ -45,14 +45,39 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfig() *schema.Resource
"client_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `OAuth client ID`,
},
"client_secret": {
Type: schema.TypeString,
Required: true,
Description: `OAuth client secret`,
},
"idp_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `ID of the IDP. Possible values include:
* 'apple.com'
* 'facebook.com'
* 'gc.apple.com'
* 'github.com'
* 'google.com'
* 'linkedin.com'
* 'microsoft.com'
* 'playgames.google.com'
* 'twitter.com'
* 'yahoo.com'`,
},
"tenant": {
Type: schema.TypeString,
Required: true,
@@ -102,7 +127,7 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigCreate(d *schema.Res
obj["enabled"] = enabledProp
}

url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs?idpId={{client_id}}")
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs?idpId={{idp_id}}")
if err != nil {
return err
}
@@ -118,7 +143,7 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigCreate(d *schema.Res
}

// Store the ID now
id, err := replaceVars(d, config, "projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{client_id}}")
id, err := replaceVars(d, config, "projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
@@ -132,7 +157,7 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigCreate(d *schema.Res
func resourceIdentityPlatformTenantDefaultSupportedIdpConfigRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{client_id}}")
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return err
}
@@ -175,6 +200,12 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigUpdate(d *schema.Res
}

obj := make(map[string]interface{})
clientIdProp, err := expandIdentityPlatformTenantDefaultSupportedIdpConfigClientId(d.Get("client_id"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("client_id"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, clientIdProp)) {
obj["clientId"] = clientIdProp
}
clientSecretProp, err := expandIdentityPlatformTenantDefaultSupportedIdpConfigClientSecret(d.Get("client_secret"), d, config)
if err != nil {
return err
@@ -188,14 +219,18 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigUpdate(d *schema.Res
obj["enabled"] = enabledProp
}

url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{client_id}}")
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return err
}

log.Printf("[DEBUG] Updating TenantDefaultSupportedIdpConfig %q: %#v", d.Id(), obj)
updateMask := []string{}

if d.HasChange("client_id") {
updateMask = append(updateMask, "clientId")
}

if d.HasChange("client_secret") {
updateMask = append(updateMask, "clientSecret")
}
@@ -226,7 +261,7 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigDelete(d *schema.Res
return err
}

url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{client_id}}")
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return err
}
@@ -246,15 +281,15 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigDelete(d *schema.Res
func resourceIdentityPlatformTenantDefaultSupportedIdpConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
if err := parseImportId([]string{
"projects/(?P<project>[^/]+)/tenants/(?P<tenant>[^/]+)/defaultSupportedIdpConfigs/(?P<client_id>[^/]+)",
"(?P<project>[^/]+)/(?P<tenant>[^/]+)/(?P<client_id>[^/]+)",
"(?P<tenant>[^/]+)/(?P<client_id>[^/]+)",
"projects/(?P<project>[^/]+)/tenants/(?P<tenant>[^/]+)/defaultSupportedIdpConfigs/(?P<idp_id>[^/]+)",
"(?P<project>[^/]+)/(?P<tenant>[^/]+)/(?P<idp_id>[^/]+)",
"(?P<tenant>[^/]+)/(?P<idp_id>[^/]+)",
}, d, config); err != nil {
return nil, err
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{client_id}}")
id, err := replaceVars(d, config, "projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ func TestAccIdentityPlatformTenantDefaultSupportedIdpConfig_identityPlatformTena
ResourceName: "google_identity_platform_tenant_default_supported_idp_config.idp_config",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"tenant"},
ImportStateVerifyIgnore: []string{"idp_id", "tenant"},
},
},
})
@@ -58,7 +58,8 @@ resource "google_identity_platform_tenant" "tenant" {
resource "google_identity_platform_tenant_default_supported_idp_config" "idp_config" {
enabled = true
tenant = google_identity_platform_tenant.tenant.name
client_id = "playgames.google.com"
idp_id = "playgames.google.com"
client_id = "my-client-id"
client_secret = "secret"
}
`, context)
@@ -75,7 +76,7 @@ func testAccCheckIdentityPlatformTenantDefaultSupportedIdpConfigDestroy(s *terra

config := testAccProvider.Meta().(*Config)

url, err := replaceVarsForTest(config, rs, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{client_id}}")
url, err := replaceVarsForTest(config, rs, "{{IdentityPlatformBasePath}}projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{idp_id}}")
if err != nil {
return err
}
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ func testSweepIdentityPlatformTenantDefaultSupportedIdpConfig(region string) err
continue
}

deleteTemplate := "https://identitytoolkit.googleapis.com/v2/projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{client_id}}"
deleteTemplate := "https://identitytoolkit.googleapis.com/v2/projects/{{project}}/tenants/{{tenant}}/defaultSupportedIdpConfigs/{{idp_id}}"
deleteUrl, err := replaceVars(d, config, deleteTemplate)
if err != nil {
log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err)
Original file line number Diff line number Diff line change
@@ -50,7 +50,8 @@ resource "google_identity_platform_tenant" "tenant" {
resource "google_identity_platform_tenant_default_supported_idp_config" "idp_config" {
enabled = true
tenant = google_identity_platform_tenant.tenant.name
client_id = "playgames.google.com"
idp_id = "playgames.google.com"
client_id = "client-id"
client_secret = "secret"
}
`, context)
@@ -65,7 +66,8 @@ resource "google_identity_platform_tenant" "tenant" {
resource "google_identity_platform_tenant_default_supported_idp_config" "idp_config" {
enabled = false
tenant = google_identity_platform_tenant.tenant.name
client_id = "playgames.google.com"
idp_id = "playgames.google.com"
client_id = "client-id2"
client_secret = "differentsecret"
}
`, context)
Original file line number Diff line number Diff line change
@@ -36,7 +36,8 @@ the marketplace prior to using this resource.
```hcl
resource "google_identity_platform_default_supported_idp_config" "idp_config" {
enabled = true
client_id = "playgames.google.com"
idp_id = "playgames.google.com"
client_id = "client-id"
client_secret = "secret"
}
```
@@ -46,6 +47,20 @@ resource "google_identity_platform_default_supported_idp_config" "idp_config" {
The following arguments are supported:


* `idp_id` -
(Required)
ID of the IDP. Possible values include:
* `apple.com`
* `facebook.com`
* `gc.apple.com`
* `github.com`
* `google.com`
* `linkedin.com`
* `microsoft.com`
* `playgames.google.com`
* `twitter.com`
* `yahoo.com`

* `client_id` -
(Required)
OAuth client ID
@@ -89,9 +104,9 @@ This resource provides the following
DefaultSupportedIdpConfig can be imported using any of these accepted formats:

```
$ terraform import google_identity_platform_default_supported_idp_config.default projects/{{project}}/defaultSupportedIdpConfigs/{{client_id}}
$ terraform import google_identity_platform_default_supported_idp_config.default {{project}}/{{client_id}}
$ terraform import google_identity_platform_default_supported_idp_config.default {{client_id}}
$ terraform import google_identity_platform_default_supported_idp_config.default projects/{{project}}/defaultSupportedIdpConfigs/{{idp_id}}
$ terraform import google_identity_platform_default_supported_idp_config.default {{project}}/{{idp_id}}
$ terraform import google_identity_platform_default_supported_idp_config.default {{idp_id}}
```

-> If you're importing a resource with beta features, make sure to include `-provider=google-beta`
Loading

0 comments on commit 09520ea

Please sign in to comment.