Skip to content

Commit 773a09f

Browse files
Add new Config entity to Identitytoolkit (#6587) (#4729)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent f2ff8f7 commit 773a09f

File tree

5 files changed

+445
-2
lines changed

5 files changed

+445
-2
lines changed

.changelog/6587.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_identity_platform_config`
3+
```

google-beta/provider.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,9 +954,9 @@ func Provider() *schema.Provider {
954954
return provider
955955
}
956956

957-
// Generated resources: 262
957+
// Generated resources: 263
958958
// Generated IAM resources: 171
959-
// Total generated resources: 433
959+
// Total generated resources: 434
960960
func ResourceMap() map[string]*schema.Resource {
961961
resourceMap, _ := ResourceMapWithErrors()
962962
return resourceMap
@@ -1282,6 +1282,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
12821282
"google_iap_tunnel_iam_policy": ResourceIamPolicy(IapTunnelIamSchema, IapTunnelIamUpdaterProducer, IapTunnelIdParseFunc),
12831283
"google_iap_brand": resourceIapBrand(),
12841284
"google_iap_client": resourceIapClient(),
1285+
"google_identity_platform_config": resourceIdentityPlatformConfig(),
12851286
"google_identity_platform_default_supported_idp_config": resourceIdentityPlatformDefaultSupportedIdpConfig(),
12861287
"google_identity_platform_tenant_default_supported_idp_config": resourceIdentityPlatformTenantDefaultSupportedIdpConfig(),
12871288
"google_identity_platform_inbound_saml_config": resourceIdentityPlatformInboundSamlConfig(),
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package google
16+
17+
import (
18+
"fmt"
19+
"log"
20+
"reflect"
21+
"strings"
22+
"time"
23+
24+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
25+
)
26+
27+
func resourceIdentityPlatformConfig() *schema.Resource {
28+
return &schema.Resource{
29+
Create: resourceIdentityPlatformConfigCreate,
30+
Read: resourceIdentityPlatformConfigRead,
31+
Update: resourceIdentityPlatformConfigUpdate,
32+
Delete: resourceIdentityPlatformConfigDelete,
33+
34+
Importer: &schema.ResourceImporter{
35+
State: resourceIdentityPlatformConfigImport,
36+
},
37+
38+
Timeouts: &schema.ResourceTimeout{
39+
Create: schema.DefaultTimeout(20 * time.Minute),
40+
Update: schema.DefaultTimeout(20 * time.Minute),
41+
Delete: schema.DefaultTimeout(20 * time.Minute),
42+
},
43+
44+
Schema: map[string]*schema.Schema{
45+
"autodelete_anonymous_users": {
46+
Type: schema.TypeBool,
47+
Optional: true,
48+
Description: `Whether anonymous users will be auto-deleted after a period of 30 days`,
49+
},
50+
"name": {
51+
Type: schema.TypeString,
52+
Computed: true,
53+
Description: `The name of the Config resource`,
54+
},
55+
"project": {
56+
Type: schema.TypeString,
57+
Optional: true,
58+
Computed: true,
59+
ForceNew: true,
60+
},
61+
},
62+
UseJSONNumber: true,
63+
}
64+
}
65+
66+
func resourceIdentityPlatformConfigCreate(d *schema.ResourceData, meta interface{}) error {
67+
config := meta.(*Config)
68+
userAgent, err := generateUserAgentString(d, config.userAgent)
69+
if err != nil {
70+
return err
71+
}
72+
73+
obj := make(map[string]interface{})
74+
autodeleteAnonymousUsersProp, err := expandIdentityPlatformConfigAutodeleteAnonymousUsers(d.Get("autodelete_anonymous_users"), d, config)
75+
if err != nil {
76+
return err
77+
} else if v, ok := d.GetOkExists("autodelete_anonymous_users"); !isEmptyValue(reflect.ValueOf(autodeleteAnonymousUsersProp)) && (ok || !reflect.DeepEqual(v, autodeleteAnonymousUsersProp)) {
78+
obj["autodeleteAnonymousUsers"] = autodeleteAnonymousUsersProp
79+
}
80+
81+
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/identityPlatform:initializeAuth")
82+
if err != nil {
83+
return err
84+
}
85+
86+
log.Printf("[DEBUG] Creating new Config: %#v", obj)
87+
billingProject := ""
88+
89+
project, err := getProject(d, config)
90+
if err != nil {
91+
return fmt.Errorf("Error fetching project for Config: %s", err)
92+
}
93+
billingProject = project
94+
95+
// err == nil indicates that the billing_project value was found
96+
if bp, err := getBillingProject(d, config); err == nil {
97+
billingProject = bp
98+
}
99+
100+
res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate))
101+
if err != nil {
102+
return fmt.Errorf("Error creating Config: %s", err)
103+
}
104+
if err := d.Set("name", flattenIdentityPlatformConfigName(res["name"], d, config)); err != nil {
105+
return fmt.Errorf(`Error setting computed identity field "name": %s`, err)
106+
}
107+
108+
// Store the ID now
109+
id, err := replaceVars(d, config, "projects/{{project}}/config")
110+
if err != nil {
111+
return fmt.Errorf("Error constructing id: %s", err)
112+
}
113+
d.SetId(id)
114+
115+
log.Printf("[DEBUG] Finished creating Config %q: %#v", d.Id(), res)
116+
117+
return resourceIdentityPlatformConfigRead(d, meta)
118+
}
119+
120+
func resourceIdentityPlatformConfigRead(d *schema.ResourceData, meta interface{}) error {
121+
config := meta.(*Config)
122+
userAgent, err := generateUserAgentString(d, config.userAgent)
123+
if err != nil {
124+
return err
125+
}
126+
127+
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/config")
128+
if err != nil {
129+
return err
130+
}
131+
132+
billingProject := ""
133+
134+
project, err := getProject(d, config)
135+
if err != nil {
136+
return fmt.Errorf("Error fetching project for Config: %s", err)
137+
}
138+
billingProject = project
139+
140+
// err == nil indicates that the billing_project value was found
141+
if bp, err := getBillingProject(d, config); err == nil {
142+
billingProject = bp
143+
}
144+
145+
res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil)
146+
if err != nil {
147+
return handleNotFoundError(err, d, fmt.Sprintf("IdentityPlatformConfig %q", d.Id()))
148+
}
149+
150+
if err := d.Set("project", project); err != nil {
151+
return fmt.Errorf("Error reading Config: %s", err)
152+
}
153+
154+
if err := d.Set("name", flattenIdentityPlatformConfigName(res["name"], d, config)); err != nil {
155+
return fmt.Errorf("Error reading Config: %s", err)
156+
}
157+
if err := d.Set("autodelete_anonymous_users", flattenIdentityPlatformConfigAutodeleteAnonymousUsers(res["autodeleteAnonymousUsers"], d, config)); err != nil {
158+
return fmt.Errorf("Error reading Config: %s", err)
159+
}
160+
161+
return nil
162+
}
163+
164+
func resourceIdentityPlatformConfigUpdate(d *schema.ResourceData, meta interface{}) error {
165+
config := meta.(*Config)
166+
userAgent, err := generateUserAgentString(d, config.userAgent)
167+
if err != nil {
168+
return err
169+
}
170+
171+
billingProject := ""
172+
173+
project, err := getProject(d, config)
174+
if err != nil {
175+
return fmt.Errorf("Error fetching project for Config: %s", err)
176+
}
177+
billingProject = project
178+
179+
obj := make(map[string]interface{})
180+
autodeleteAnonymousUsersProp, err := expandIdentityPlatformConfigAutodeleteAnonymousUsers(d.Get("autodelete_anonymous_users"), d, config)
181+
if err != nil {
182+
return err
183+
} else if v, ok := d.GetOkExists("autodelete_anonymous_users"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, autodeleteAnonymousUsersProp)) {
184+
obj["autodeleteAnonymousUsers"] = autodeleteAnonymousUsersProp
185+
}
186+
187+
url, err := replaceVars(d, config, "{{IdentityPlatformBasePath}}projects/{{project}}/config")
188+
if err != nil {
189+
return err
190+
}
191+
192+
log.Printf("[DEBUG] Updating Config %q: %#v", d.Id(), obj)
193+
updateMask := []string{}
194+
195+
if d.HasChange("autodelete_anonymous_users") {
196+
updateMask = append(updateMask, "autodeleteAnonymousUsers")
197+
}
198+
// updateMask is a URL parameter but not present in the schema, so replaceVars
199+
// won't set it
200+
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
201+
if err != nil {
202+
return err
203+
}
204+
205+
// err == nil indicates that the billing_project value was found
206+
if bp, err := getBillingProject(d, config); err == nil {
207+
billingProject = bp
208+
}
209+
210+
res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
211+
212+
if err != nil {
213+
return fmt.Errorf("Error updating Config %q: %s", d.Id(), err)
214+
} else {
215+
log.Printf("[DEBUG] Finished updating Config %q: %#v", d.Id(), res)
216+
}
217+
218+
return resourceIdentityPlatformConfigRead(d, meta)
219+
}
220+
221+
func resourceIdentityPlatformConfigDelete(d *schema.ResourceData, meta interface{}) error {
222+
log.Printf("[WARNING] IdentityPlatform Config resources"+
223+
" cannot be deleted from Google Cloud. The resource %s will be removed from Terraform"+
224+
" state, but will still be present on Google Cloud.", d.Id())
225+
d.SetId("")
226+
227+
return nil
228+
}
229+
230+
func resourceIdentityPlatformConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
231+
config := meta.(*Config)
232+
if err := parseImportId([]string{
233+
"projects/(?P<project>[^/]+)/config",
234+
"projects/(?P<project>[^/]+)",
235+
"(?P<project>[^/]+)",
236+
}, d, config); err != nil {
237+
return nil, err
238+
}
239+
240+
// Replace import id for the resource id
241+
id, err := replaceVars(d, config, "projects/{{project}}/config")
242+
if err != nil {
243+
return nil, fmt.Errorf("Error constructing id: %s", err)
244+
}
245+
d.SetId(id)
246+
247+
return []*schema.ResourceData{d}, nil
248+
}
249+
250+
func flattenIdentityPlatformConfigName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
251+
return v
252+
}
253+
254+
func flattenIdentityPlatformConfigAutodeleteAnonymousUsers(v interface{}, d *schema.ResourceData, config *Config) interface{} {
255+
return v
256+
}
257+
258+
func expandIdentityPlatformConfigAutodeleteAnonymousUsers(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
259+
return v, nil
260+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package google
16+
17+
import (
18+
"testing"
19+
20+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
21+
)
22+
23+
func TestAccIdentityPlatformConfig_identityPlatformConfigBasicExample(t *testing.T) {
24+
skipIfVcr(t)
25+
t.Parallel()
26+
27+
context := map[string]interface{}{
28+
"org_id": getTestOrgFromEnv(t),
29+
"billing_acct": getTestBillingAccountFromEnv(t),
30+
"random_suffix": randString(t, 10),
31+
}
32+
33+
vcrTest(t, resource.TestCase{
34+
PreCheck: func() { testAccPreCheck(t) },
35+
Providers: testAccProviders,
36+
Steps: []resource.TestStep{
37+
{
38+
Config: testAccIdentityPlatformConfig_identityPlatformConfigBasicExample(context),
39+
},
40+
{
41+
ResourceName: "google_identity_platform_config.default",
42+
ImportState: true,
43+
ImportStateVerify: true,
44+
},
45+
},
46+
})
47+
}
48+
49+
func testAccIdentityPlatformConfig_identityPlatformConfigBasicExample(context map[string]interface{}) string {
50+
return Nprintf(`
51+
resource "google_project" "default" {
52+
project_id = "tf-test%{random_suffix}"
53+
name = "tf-test%{random_suffix}"
54+
org_id = "%{org_id}"
55+
billing_account = "%{billing_acct}"
56+
}
57+
58+
resource "google_project_service" "apigee" {
59+
project = google_project.project.project_id
60+
service = "identitytoolkit.googleapis.com"
61+
}
62+
63+
64+
resource "google_identity_platform_config" "default" {
65+
project = google_project.default.project_id
66+
autodelete_anonymous_users = true
67+
}
68+
`, context)
69+
}

0 commit comments

Comments
 (0)