Skip to content
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

Support for Identity Platform #5199

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type Config struct {
FilestoreBasePath string
FirestoreBasePath string
IapBasePath string
IdentityPlatformBasePath string
KMSBasePath string
LoggingBasePath string
MLEngineBasePath string
Expand Down Expand Up @@ -220,6 +221,7 @@ var DNSDefaultBasePath = "https://www.googleapis.com/dns/v1/"
var FilestoreDefaultBasePath = "https://file.googleapis.com/v1/"
var FirestoreDefaultBasePath = "https://firestore.googleapis.com/v1/"
var IapDefaultBasePath = "https://iap.googleapis.com/v1/"
var IdentityPlatformDefaultBasePath = "https://identitytoolkit.googleapis.com/v2/"
var KMSDefaultBasePath = "https://cloudkms.googleapis.com/v1/"
var LoggingDefaultBasePath = "https://logging.googleapis.com/v2/"
var MLEngineDefaultBasePath = "https://ml.googleapis.com/v1/"
Expand Down Expand Up @@ -694,6 +696,7 @@ func ConfigureBasePaths(c *Config) {
c.FilestoreBasePath = FilestoreDefaultBasePath
c.FirestoreBasePath = FirestoreDefaultBasePath
c.IapBasePath = IapDefaultBasePath
c.IdentityPlatformBasePath = IdentityPlatformDefaultBasePath
c.KMSBasePath = KMSDefaultBasePath
c.LoggingBasePath = LoggingDefaultBasePath
c.MLEngineBasePath = MLEngineDefaultBasePath
Expand Down
286 changes: 151 additions & 135 deletions google/provider.go

Large diffs are not rendered by default.

286 changes: 286 additions & 0 deletions google/resource_identity_platform_default_supported_idp_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package google

import (
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func resourceIdentityPlatformDefaultSupportedIdpConfig() *schema.Resource {
return &schema.Resource{
Create: resourceIdentityPlatformDefaultSupportedIdpConfigCreate,
Read: resourceIdentityPlatformDefaultSupportedIdpConfigRead,
Update: resourceIdentityPlatformDefaultSupportedIdpConfigUpdate,
Delete: resourceIdentityPlatformDefaultSupportedIdpConfigDelete,

Importer: &schema.ResourceImporter{
State: resourceIdentityPlatformDefaultSupportedIdpConfigImport,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(4 * time.Minute),
Update: schema.DefaultTimeout(4 * time.Minute),
Delete: schema.DefaultTimeout(4 * time.Minute),
},

Schema: map[string]*schema.Schema{
"client_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `OAuth client ID`,
},
"client_secret": {
Type: schema.TypeString,
Required: true,
Description: `OAuth client secret`,
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Description: `If this IDP allows the user to sign in`,
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: `The name of the DefaultSupportedIdpConfig resource`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
}
}

func resourceIdentityPlatformDefaultSupportedIdpConfigCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

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(clientIdProp)) && (ok || !reflect.DeepEqual(v, clientIdProp)) {
obj["clientId"] = clientIdProp
}
clientSecretProp, err := expandIdentityPlatformDefaultSupportedIdpConfigClientSecret(d.Get("client_secret"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("client_secret"); !isEmptyValue(reflect.ValueOf(clientSecretProp)) && (ok || !reflect.DeepEqual(v, clientSecretProp)) {
obj["clientSecret"] = clientSecretProp
}
enabledProp, err := expandIdentityPlatformDefaultSupportedIdpConfigEnabled(d.Get("enabled"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enabled"); !isEmptyValue(reflect.ValueOf(enabledProp)) && (ok || !reflect.DeepEqual(v, enabledProp)) {
obj["enabled"] = enabledProp
}

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

log.Printf("[DEBUG] Creating new DefaultSupportedIdpConfig: %#v", obj)
project, err := getProject(d, config)
if err != nil {
return err
}
res, err := sendRequestWithTimeout(config, "POST", project, url, obj, d.Timeout(schema.TimeoutCreate))
if err != nil {
return fmt.Errorf("Error creating DefaultSupportedIdpConfig: %s", err)
}

// Store the ID now
id, err := replaceVars(d, config, "projects/{{project}}/defaultSupportedIdpConfigs/{{client_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

log.Printf("[DEBUG] Finished creating DefaultSupportedIdpConfig %q: %#v", d.Id(), res)

return resourceIdentityPlatformDefaultSupportedIdpConfigRead(d, meta)
}

func resourceIdentityPlatformDefaultSupportedIdpConfigRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

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

project, err := getProject(d, config)
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, nil)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("IdentityPlatformDefaultSupportedIdpConfig %q", d.Id()))
}

if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading DefaultSupportedIdpConfig: %s", err)
}

if err := d.Set("name", flattenIdentityPlatformDefaultSupportedIdpConfigName(res["name"], d)); err != nil {
return fmt.Errorf("Error reading DefaultSupportedIdpConfig: %s", err)
}
if err := d.Set("client_id", flattenIdentityPlatformDefaultSupportedIdpConfigClientId(res["clientId"], d)); err != nil {
return fmt.Errorf("Error reading DefaultSupportedIdpConfig: %s", err)
}
if err := d.Set("client_secret", flattenIdentityPlatformDefaultSupportedIdpConfigClientSecret(res["clientSecret"], d)); err != nil {
return fmt.Errorf("Error reading DefaultSupportedIdpConfig: %s", err)
}
if err := d.Set("enabled", flattenIdentityPlatformDefaultSupportedIdpConfigEnabled(res["enabled"], d)); err != nil {
return fmt.Errorf("Error reading DefaultSupportedIdpConfig: %s", err)
}

return nil
}

func resourceIdentityPlatformDefaultSupportedIdpConfigUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

project, err := getProject(d, config)
if err != nil {
return err
}

obj := make(map[string]interface{})
clientSecretProp, err := expandIdentityPlatformDefaultSupportedIdpConfigClientSecret(d.Get("client_secret"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("client_secret"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, clientSecretProp)) {
obj["clientSecret"] = clientSecretProp
}
enabledProp, err := expandIdentityPlatformDefaultSupportedIdpConfigEnabled(d.Get("enabled"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enabled"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enabledProp)) {
obj["enabled"] = enabledProp
}

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

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

if d.HasChange("client_secret") {
updateMask = append(updateMask, "clientSecret")
}

if d.HasChange("enabled") {
updateMask = append(updateMask, "enabled")
}
// updateMask is a URL parameter but not present in the schema, so replaceVars
// won't set it
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))

if err != nil {
return fmt.Errorf("Error updating DefaultSupportedIdpConfig %q: %s", d.Id(), err)
}

return resourceIdentityPlatformDefaultSupportedIdpConfigRead(d, meta)
}

func resourceIdentityPlatformDefaultSupportedIdpConfigDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

project, err := getProject(d, config)
if err != nil {
return err
}

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

var obj map[string]interface{}
log.Printf("[DEBUG] Deleting DefaultSupportedIdpConfig %q", d.Id())

res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete))
if err != nil {
return handleNotFoundError(err, d, "DefaultSupportedIdpConfig")
}

log.Printf("[DEBUG] Finished deleting DefaultSupportedIdpConfig %q: %#v", d.Id(), res)
return nil
}

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>[^/]+)",
}, d, config); err != nil {
return nil, err
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "projects/{{project}}/defaultSupportedIdpConfigs/{{client_id}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return []*schema.ResourceData{d}, nil
}

func flattenIdentityPlatformDefaultSupportedIdpConfigName(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenIdentityPlatformDefaultSupportedIdpConfigClientId(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenIdentityPlatformDefaultSupportedIdpConfigClientSecret(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenIdentityPlatformDefaultSupportedIdpConfigEnabled(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func expandIdentityPlatformDefaultSupportedIdpConfigClientId(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandIdentityPlatformDefaultSupportedIdpConfigClientSecret(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandIdentityPlatformDefaultSupportedIdpConfigEnabled(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package google

import (
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

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

context := map[string]interface{}{
"random_suffix": acctest.RandString(10),
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIdentityPlatformDefaultSupportedIdpConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccIdentityPlatformDefaultSupportedIdpConfig_defaultSupportedIdpConfigBasic(context),
},
{
ResourceName: "google_identity_platform_default_supported_idp_config.idp_config",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccIdentityPlatformDefaultSupportedIdpConfig_defaultSupportedIdpConfigUpdate(context),
},
{
ResourceName: "google_identity_platform_default_supported_idp_config.idp_config",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckIdentityPlatformDefaultSupportedIdpConfigDestroy(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_identity_platform_default_supported_idp_config" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

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

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

_, err = sendRequest(config, "GET", "", url, nil)
if err == nil {
return fmt.Errorf("IdentityPlatformDefaultSupportedIdpConfig still exists at %s", url)
}
}

return nil
}

func testAccIdentityPlatformDefaultSupportedIdpConfig_defaultSupportedIdpConfigBasic(context map[string]interface{}) string {
return Nprintf(`
resource "google_identity_platform_default_supported_idp_config" "idp_config" {
enabled = true
client_id = "playgames.google.com"
client_secret = "secret"
}
`, context)
}

func testAccIdentityPlatformDefaultSupportedIdpConfig_defaultSupportedIdpConfigUpdate(context map[string]interface{}) string {
return Nprintf(`
resource "google_identity_platform_default_supported_idp_config" "idp_config" {
enabled = false
client_id = "playgames.google.com"
client_secret = "anothersecret"
}
`, context)
}
Loading