Skip to content

Commit 678c890

Browse files
Added code for Apigee environment groups (#4570) (#3039)
* Added code for Apigee Environment * Update api.yaml * Update api.yaml * Added code for Apigee Environment * Added code for Apigee environment groups * Update api.yaml * Added code for Apigee Environment * Update api.yaml * Update api.yaml * Added code for Apigee Environment * Incorporating review comments for Apigee environment groups * Incorporating review comments for Apigee environment groups * Update reverse_check_membership.sh * Update reverse_check_membership.sh * Update check_membership.sh * Update mmv1/products/apigee/api.yaml Co-authored-by: Sam Levenick <[email protected]> * Added code for Apigee Environment * Update api.yaml * Update api.yaml * Added code for Apigee Environment * Update api.yaml * Added code for Apigee Environment * Update api.yaml * Update api.yaml * Added code for Apigee Environment * Update api.yaml * Update api.yaml * Added code for Apigee Environment * Update api.yaml * Added code for Apigee Environment * Update api.yaml * Update api.yaml * Added code for Apigee Environment * Update mmv1/products/apigee/api.yaml Co-authored-by: Sam Levenick <[email protected]> * fixing .ci errors Co-authored-by: Sam Levenick <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Sam Levenick <[email protected]>
1 parent dea7cfa commit 678c890

File tree

8 files changed

+741
-3
lines changed

8 files changed

+741
-3
lines changed

.changelog/4570.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_apigee_envgroup
3+
```

google-beta/provider.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,9 @@ func Provider() *schema.Provider {
825825
return provider
826826
}
827827

828-
// Generated resources: 213
828+
// Generated resources: 214
829829
// Generated IAM resources: 108
830-
// Total generated resources: 321
830+
// Total generated resources: 322
831831
func ResourceMap() map[string]*schema.Resource {
832832
resourceMap, _ := ResourceMapWithErrors()
833833
return resourceMap
@@ -864,6 +864,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
864864
"google_apigee_organization": resourceApigeeOrganization(),
865865
"google_apigee_instance": resourceApigeeInstance(),
866866
"google_apigee_environment": resourceApigeeEnvironment(),
867+
"google_apigee_envgroup": resourceApigeeEnvgroup(),
867868
"google_app_engine_domain_mapping": resourceAppEngineDomainMapping(),
868869
"google_app_engine_firewall_rule": resourceAppEngineFirewallRule(),
869870
"google_app_engine_standard_app_version": resourceAppEngineStandardAppVersion(),
Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
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 resourceApigeeEnvgroup() *schema.Resource {
28+
return &schema.Resource{
29+
Create: resourceApigeeEnvgroupCreate,
30+
Read: resourceApigeeEnvgroupRead,
31+
Update: resourceApigeeEnvgroupUpdate,
32+
Delete: resourceApigeeEnvgroupDelete,
33+
34+
Importer: &schema.ResourceImporter{
35+
State: resourceApigeeEnvgroupImport,
36+
},
37+
38+
Timeouts: &schema.ResourceTimeout{
39+
Create: schema.DefaultTimeout(30 * time.Minute),
40+
Update: schema.DefaultTimeout(4 * time.Minute),
41+
Delete: schema.DefaultTimeout(30 * time.Minute),
42+
},
43+
44+
Schema: map[string]*schema.Schema{
45+
"name": {
46+
Type: schema.TypeString,
47+
Required: true,
48+
ForceNew: true,
49+
Description: `The resource ID of the environment group.`,
50+
},
51+
"org_id": {
52+
Type: schema.TypeString,
53+
Required: true,
54+
ForceNew: true,
55+
Description: `The Apigee Organization associated with the Apigee environment group,
56+
in the format 'organizations/{{org_name}}'.`,
57+
},
58+
"hostnames": {
59+
Type: schema.TypeList,
60+
Optional: true,
61+
Description: `Hostnames of the environment group.`,
62+
Elem: &schema.Schema{
63+
Type: schema.TypeString,
64+
},
65+
},
66+
},
67+
UseJSONNumber: true,
68+
}
69+
}
70+
71+
func resourceApigeeEnvgroupCreate(d *schema.ResourceData, meta interface{}) error {
72+
config := meta.(*Config)
73+
userAgent, err := generateUserAgentString(d, config.userAgent)
74+
if err != nil {
75+
return err
76+
}
77+
78+
obj := make(map[string]interface{})
79+
nameProp, err := expandApigeeEnvgroupName(d.Get("name"), d, config)
80+
if err != nil {
81+
return err
82+
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
83+
obj["name"] = nameProp
84+
}
85+
hostnamesProp, err := expandApigeeEnvgroupHostnames(d.Get("hostnames"), d, config)
86+
if err != nil {
87+
return err
88+
} else if v, ok := d.GetOkExists("hostnames"); !isEmptyValue(reflect.ValueOf(hostnamesProp)) && (ok || !reflect.DeepEqual(v, hostnamesProp)) {
89+
obj["hostnames"] = hostnamesProp
90+
}
91+
92+
url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/envgroups")
93+
if err != nil {
94+
return err
95+
}
96+
97+
log.Printf("[DEBUG] Creating new Envgroup: %#v", obj)
98+
billingProject := ""
99+
100+
// err == nil indicates that the billing_project value was found
101+
if bp, err := getBillingProject(d, config); err == nil {
102+
billingProject = bp
103+
}
104+
105+
res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate))
106+
if err != nil {
107+
return fmt.Errorf("Error creating Envgroup: %s", err)
108+
}
109+
110+
// Store the ID now
111+
id, err := replaceVars(d, config, "{{org_id}}/envgroups/{{name}}")
112+
if err != nil {
113+
return fmt.Errorf("Error constructing id: %s", err)
114+
}
115+
d.SetId(id)
116+
117+
// Use the resource in the operation response to populate
118+
// identity fields and d.Id() before read
119+
var opRes map[string]interface{}
120+
err = apigeeOperationWaitTimeWithResponse(
121+
config, res, &opRes, "Creating Envgroup", userAgent,
122+
d.Timeout(schema.TimeoutCreate))
123+
if err != nil {
124+
// The resource didn't actually create
125+
d.SetId("")
126+
return fmt.Errorf("Error waiting to create Envgroup: %s", err)
127+
}
128+
129+
if err := d.Set("name", flattenApigeeEnvgroupName(opRes["name"], d, config)); err != nil {
130+
return err
131+
}
132+
133+
// This may have caused the ID to update - update it if so.
134+
id, err = replaceVars(d, config, "{{org_id}}/envgroups/{{name}}")
135+
if err != nil {
136+
return fmt.Errorf("Error constructing id: %s", err)
137+
}
138+
d.SetId(id)
139+
140+
log.Printf("[DEBUG] Finished creating Envgroup %q: %#v", d.Id(), res)
141+
142+
return resourceApigeeEnvgroupRead(d, meta)
143+
}
144+
145+
func resourceApigeeEnvgroupRead(d *schema.ResourceData, meta interface{}) error {
146+
config := meta.(*Config)
147+
userAgent, err := generateUserAgentString(d, config.userAgent)
148+
if err != nil {
149+
return err
150+
}
151+
152+
url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/envgroups/{{name}}")
153+
if err != nil {
154+
return err
155+
}
156+
157+
billingProject := ""
158+
159+
// err == nil indicates that the billing_project value was found
160+
if bp, err := getBillingProject(d, config); err == nil {
161+
billingProject = bp
162+
}
163+
164+
res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil)
165+
if err != nil {
166+
return handleNotFoundError(err, d, fmt.Sprintf("ApigeeEnvgroup %q", d.Id()))
167+
}
168+
169+
if err := d.Set("name", flattenApigeeEnvgroupName(res["name"], d, config)); err != nil {
170+
return fmt.Errorf("Error reading Envgroup: %s", err)
171+
}
172+
if err := d.Set("hostnames", flattenApigeeEnvgroupHostnames(res["hostnames"], d, config)); err != nil {
173+
return fmt.Errorf("Error reading Envgroup: %s", err)
174+
}
175+
176+
return nil
177+
}
178+
179+
func resourceApigeeEnvgroupUpdate(d *schema.ResourceData, meta interface{}) error {
180+
config := meta.(*Config)
181+
userAgent, err := generateUserAgentString(d, config.userAgent)
182+
if err != nil {
183+
return err
184+
}
185+
186+
billingProject := ""
187+
188+
obj := make(map[string]interface{})
189+
nameProp, err := expandApigeeEnvgroupName(d.Get("name"), d, config)
190+
if err != nil {
191+
return err
192+
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
193+
obj["name"] = nameProp
194+
}
195+
hostnamesProp, err := expandApigeeEnvgroupHostnames(d.Get("hostnames"), d, config)
196+
if err != nil {
197+
return err
198+
} else if v, ok := d.GetOkExists("hostnames"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, hostnamesProp)) {
199+
obj["hostnames"] = hostnamesProp
200+
}
201+
202+
url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/envgroups/{{name}}")
203+
if err != nil {
204+
return err
205+
}
206+
207+
log.Printf("[DEBUG] Updating Envgroup %q: %#v", d.Id(), obj)
208+
209+
// err == nil indicates that the billing_project value was found
210+
if bp, err := getBillingProject(d, config); err == nil {
211+
billingProject = bp
212+
}
213+
214+
res, err := sendRequestWithTimeout(config, "PUT", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
215+
216+
if err != nil {
217+
return fmt.Errorf("Error updating Envgroup %q: %s", d.Id(), err)
218+
} else {
219+
log.Printf("[DEBUG] Finished updating Envgroup %q: %#v", d.Id(), res)
220+
}
221+
222+
err = apigeeOperationWaitTime(
223+
config, res, "Updating Envgroup", userAgent,
224+
d.Timeout(schema.TimeoutUpdate))
225+
226+
if err != nil {
227+
return err
228+
}
229+
230+
return resourceApigeeEnvgroupRead(d, meta)
231+
}
232+
233+
func resourceApigeeEnvgroupDelete(d *schema.ResourceData, meta interface{}) error {
234+
config := meta.(*Config)
235+
userAgent, err := generateUserAgentString(d, config.userAgent)
236+
if err != nil {
237+
return err
238+
}
239+
240+
billingProject := ""
241+
242+
url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/envgroups/{{name}}")
243+
if err != nil {
244+
return err
245+
}
246+
247+
var obj map[string]interface{}
248+
log.Printf("[DEBUG] Deleting Envgroup %q", d.Id())
249+
250+
// err == nil indicates that the billing_project value was found
251+
if bp, err := getBillingProject(d, config); err == nil {
252+
billingProject = bp
253+
}
254+
255+
res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete))
256+
if err != nil {
257+
return handleNotFoundError(err, d, "Envgroup")
258+
}
259+
260+
err = apigeeOperationWaitTime(
261+
config, res, "Deleting Envgroup", userAgent,
262+
d.Timeout(schema.TimeoutDelete))
263+
264+
if err != nil {
265+
return err
266+
}
267+
268+
log.Printf("[DEBUG] Finished deleting Envgroup %q: %#v", d.Id(), res)
269+
return nil
270+
}
271+
272+
func resourceApigeeEnvgroupImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
273+
config := meta.(*Config)
274+
275+
// current import_formats cannot import fields with forward slashes in their value
276+
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
277+
return nil, err
278+
}
279+
280+
nameParts := strings.Split(d.Get("name").(string), "/")
281+
if len(nameParts) == 4 {
282+
// `organizations/{{org_name}}/envgroups/{{name}}`
283+
orgId := fmt.Sprintf("organizations/%s", nameParts[1])
284+
if err := d.Set("org_id", orgId); err != nil {
285+
return nil, fmt.Errorf("Error setting org_id: %s", err)
286+
}
287+
if err := d.Set("name", nameParts[3]); err != nil {
288+
return nil, fmt.Errorf("Error setting name: %s", err)
289+
}
290+
} else if len(nameParts) == 3 {
291+
// `organizations/{{org_name}}/{{name}}`
292+
orgId := fmt.Sprintf("organizations/%s", nameParts[1])
293+
if err := d.Set("org_id", orgId); err != nil {
294+
return nil, fmt.Errorf("Error setting org_id: %s", err)
295+
}
296+
if err := d.Set("name", nameParts[2]); err != nil {
297+
return nil, fmt.Errorf("Error setting name: %s", err)
298+
}
299+
} else {
300+
return nil, fmt.Errorf(
301+
"Saw %s when the name is expected to have shape %s or %s",
302+
d.Get("name"),
303+
"organizations/{{org_name}}/envgroups/{{name}}",
304+
"organizations/{{org_name}}/{{name}}")
305+
}
306+
307+
// Replace import id for the resource id
308+
id, err := replaceVars(d, config, "{{org_id}}/envgroups/{{name}}")
309+
if err != nil {
310+
return nil, fmt.Errorf("Error constructing id: %s", err)
311+
}
312+
d.SetId(id)
313+
314+
return []*schema.ResourceData{d}, nil
315+
}
316+
317+
func flattenApigeeEnvgroupName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
318+
return v
319+
}
320+
321+
func flattenApigeeEnvgroupHostnames(v interface{}, d *schema.ResourceData, config *Config) interface{} {
322+
return v
323+
}
324+
325+
func expandApigeeEnvgroupName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
326+
return v, nil
327+
}
328+
329+
func expandApigeeEnvgroupHostnames(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
330+
return v, nil
331+
}

0 commit comments

Comments
 (0)