-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new Apigee resource /v1/organizations/<apigee_org>/environments…
…/<apigee_env>/addonsConfig (#12616) Co-authored-by: Stephen Lewis (Burrows) <[email protected]> [upstream:716d7b69f8bb52a666ec199dc1b214535cfd8fa8] Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
85d91a1
commit 1357ef2
Showing
6 changed files
with
531 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
`google_apigee_environment_addons_config` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
280 changes: 280 additions & 0 deletions
280
google-beta/services/apigee/resource_apigee_environment_addons_config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,280 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// 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 apigee | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"reflect" | ||
"strings" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" | ||
) | ||
|
||
func ResourceApigeeEnvironmentAddonsConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceApigeeEnvironmentAddonsConfigCreate, | ||
Read: resourceApigeeEnvironmentAddonsConfigRead, | ||
Update: resourceApigeeEnvironmentAddonsConfigUpdate, | ||
Delete: resourceApigeeEnvironmentAddonsConfigDelete, | ||
|
||
Importer: &schema.ResourceImporter{ | ||
State: resourceApigeeEnvironmentAddonsConfigImport, | ||
}, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(5 * time.Minute), | ||
Update: schema.DefaultTimeout(5 * time.Minute), | ||
Delete: schema.DefaultTimeout(0 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"env_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: `The Apigee environment group associated with the Apigee environment, | ||
in the format 'organizations/{{org_name}}/environments/{{env_name}}'.`, | ||
}, | ||
"analytics_enabled": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: `Flag to enable/disable Analytics.`, | ||
}, | ||
}, | ||
UseJSONNumber: true, | ||
} | ||
} | ||
|
||
func resourceApigeeEnvironmentAddonsConfigCreate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*transport_tpg.Config) | ||
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := make(map[string]interface{}) | ||
analyticsEnabledProp, err := expandApigeeEnvironmentAddonsConfigAnalyticsEnabled(d.Get("analytics_enabled"), d, config) | ||
if err != nil { | ||
return err | ||
} else if v, ok := d.GetOkExists("analytics_enabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(analyticsEnabledProp)) && (ok || !reflect.DeepEqual(v, analyticsEnabledProp)) { | ||
obj["analyticsEnabled"] = analyticsEnabledProp | ||
} | ||
|
||
url, err := tpgresource.ReplaceVars(d, config, "{{ApigeeBasePath}}{{env_id}}/addonsConfig:setAddonEnablement") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Creating new EnvironmentAddonsConfig: %#v", obj) | ||
billingProject := "" | ||
|
||
// err == nil indicates that the billing_project value was found | ||
if bp, err := tpgresource.GetBillingProject(d, config); err == nil { | ||
billingProject = bp | ||
} | ||
|
||
headers := make(http.Header) | ||
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "POST", | ||
Project: billingProject, | ||
RawURL: url, | ||
UserAgent: userAgent, | ||
Body: obj, | ||
Timeout: d.Timeout(schema.TimeoutCreate), | ||
Headers: headers, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error creating EnvironmentAddonsConfig: %s", err) | ||
} | ||
|
||
// Store the ID now | ||
id, err := tpgresource.ReplaceVars(d, config, "{{env_id}}") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
err = ApigeeOperationWaitTime( | ||
config, res, "Creating EnvironmentAddonsConfig", userAgent, | ||
d.Timeout(schema.TimeoutCreate)) | ||
|
||
if err != nil { | ||
// The resource didn't actually create | ||
d.SetId("") | ||
return fmt.Errorf("Error waiting to create EnvironmentAddonsConfig: %s", err) | ||
} | ||
|
||
log.Printf("[DEBUG] Finished creating EnvironmentAddonsConfig %q: %#v", d.Id(), res) | ||
|
||
return resourceApigeeEnvironmentAddonsConfigRead(d, meta) | ||
} | ||
|
||
func resourceApigeeEnvironmentAddonsConfigRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*transport_tpg.Config) | ||
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
url, err := tpgresource.ReplaceVars(d, config, "{{ApigeeBasePath}}{{env_id}}/addonsConfig") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
billingProject := "" | ||
|
||
// err == nil indicates that the billing_project value was found | ||
if bp, err := tpgresource.GetBillingProject(d, config); err == nil { | ||
billingProject = bp | ||
} | ||
|
||
headers := make(http.Header) | ||
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "GET", | ||
Project: billingProject, | ||
RawURL: url, | ||
UserAgent: userAgent, | ||
Headers: headers, | ||
}) | ||
if err != nil { | ||
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("ApigeeEnvironmentAddonsConfig %q", d.Id())) | ||
} | ||
|
||
res, err = resourceApigeeEnvironmentAddonsConfigDecoder(d, meta, res) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if res == nil { | ||
// Decoding the object has resulted in it being gone. It may be marked deleted | ||
log.Printf("[DEBUG] Removing ApigeeEnvironmentAddonsConfig because it no longer exists.") | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
if err := d.Set("analytics_enabled", flattenApigeeEnvironmentAddonsConfigAnalyticsEnabled(res["analyticsEnabled"], d, config)); err != nil { | ||
return fmt.Errorf("Error reading EnvironmentAddonsConfig: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceApigeeEnvironmentAddonsConfigUpdate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*transport_tpg.Config) | ||
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
billingProject := "" | ||
|
||
obj := make(map[string]interface{}) | ||
analyticsEnabledProp, err := expandApigeeEnvironmentAddonsConfigAnalyticsEnabled(d.Get("analytics_enabled"), d, config) | ||
if err != nil { | ||
return err | ||
} else if v, ok := d.GetOkExists("analytics_enabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, analyticsEnabledProp)) { | ||
obj["analyticsEnabled"] = analyticsEnabledProp | ||
} | ||
|
||
url, err := tpgresource.ReplaceVars(d, config, "{{ApigeeBasePath}}{{env_id}}/addonsConfig:setAddonEnablement") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Updating EnvironmentAddonsConfig %q: %#v", d.Id(), obj) | ||
headers := make(http.Header) | ||
|
||
// err == nil indicates that the billing_project value was found | ||
if bp, err := tpgresource.GetBillingProject(d, config); err == nil { | ||
billingProject = bp | ||
} | ||
|
||
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "POST", | ||
Project: billingProject, | ||
RawURL: url, | ||
UserAgent: userAgent, | ||
Body: obj, | ||
Timeout: d.Timeout(schema.TimeoutUpdate), | ||
Headers: headers, | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error updating EnvironmentAddonsConfig %q: %s", d.Id(), err) | ||
} else { | ||
log.Printf("[DEBUG] Finished updating EnvironmentAddonsConfig %q: %#v", d.Id(), res) | ||
} | ||
|
||
err = ApigeeOperationWaitTime( | ||
config, res, "Updating EnvironmentAddonsConfig", userAgent, | ||
d.Timeout(schema.TimeoutUpdate)) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return resourceApigeeEnvironmentAddonsConfigRead(d, meta) | ||
} | ||
|
||
func resourceApigeeEnvironmentAddonsConfigDelete(d *schema.ResourceData, meta interface{}) error { | ||
log.Printf("[WARNING] Apigee EnvironmentAddonsConfig resources"+ | ||
" cannot be deleted from Google Cloud. The resource %s will be removed from Terraform"+ | ||
" state, but will still be present on Google Cloud.", d.Id()) | ||
d.SetId("") | ||
|
||
return nil | ||
} | ||
|
||
func resourceApigeeEnvironmentAddonsConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||
config := meta.(*transport_tpg.Config) | ||
|
||
// current import_formats cannot import fields with forward slashes in their value | ||
if err := tpgresource.ParseImportId([]string{"(?P<env_id>.+)"}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
id := d.Get("env_id").(string) | ||
nameParts := strings.Split(id, "/") | ||
if len(nameParts) != 4 { | ||
return nil, fmt.Errorf("env is expected to have shape organizations/{{org_id}}/environments/{{env}}, got %s instead", id) | ||
} | ||
d.SetId(id) | ||
return []*schema.ResourceData{d}, nil | ||
} | ||
|
||
func flattenApigeeEnvironmentAddonsConfigAnalyticsEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
return v | ||
} | ||
|
||
func expandApigeeEnvironmentAddonsConfigAnalyticsEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
return v, nil | ||
} | ||
|
||
func resourceApigeeEnvironmentAddonsConfigDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { | ||
res["analyticsEnabled"] = res["analyticsConfig"].(map[string]interface{})["enabled"] | ||
return res, nil | ||
} |
5 changes: 5 additions & 0 deletions
5
google-beta/services/apigee/resource_apigee_environment_addons_config_generated_meta.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource: 'google_apigee_environment_addons_config' | ||
generation_type: 'mmv1' | ||
api_service_name: 'apigee.googleapis.com' | ||
api_version: 'v1' | ||
api_resource_type_kind: 'AddonsConfig' |
Oops, something went wrong.