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

Add endpointAttachment in Apigee #11157

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 .changelog/5717.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_apigee_endpoint_attachment`
```
5 changes: 3 additions & 2 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 216
// Generated resources: 217
// Generated IAM resources: 96
// Total generated resources: 312
// Total generated resources: 313
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -854,6 +854,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_apigee_envgroup": resourceApigeeEnvgroup(),
"google_apigee_instance_attachment": resourceApigeeInstanceAttachment(),
"google_apigee_envgroup_attachment": resourceApigeeEnvgroupAttachment(),
"google_apigee_endpoint_attachment": resourceApigeeEndpointAttachment(),
"google_app_engine_domain_mapping": resourceAppEngineDomainMapping(),
"google_app_engine_firewall_rule": resourceAppEngineFirewallRule(),
"google_app_engine_standard_app_version": resourceAppEngineStandardAppVersion(),
Expand Down
294 changes: 294 additions & 0 deletions google/resource_apigee_endpoint_attachment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
// ----------------------------------------------------------------------------
//
// *** 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 google

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

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

func resourceApigeeEndpointAttachment() *schema.Resource {
return &schema.Resource{
Create: resourceApigeeEndpointAttachmentCreate,
Read: resourceApigeeEndpointAttachmentRead,
Delete: resourceApigeeEndpointAttachmentDelete,

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

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

Schema: map[string]*schema.Schema{
"endpoint_attachment_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `ID of the endpoint attachment.`,
},
"location": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Location of the endpoint attachment.`,
},
"org_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The Apigee Organization associated with the Apigee instance,
in the format 'organizations/{{org_name}}'.`,
},
"service_attachment": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Format: projects/*/regions/*/serviceAttachments/*`,
},
"host": {
Type: schema.TypeString,
Computed: true,
Description: `Host that can be used in either HTTP Target Endpoint directly, or as the host in Target Server.`,
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: `Name of the Endpoint Attachment in the following format:
organizations/{organization}/endpointAttachments/{endpointAttachment}.`,
},
},
UseJSONNumber: true,
}
}

func resourceApigeeEndpointAttachmentCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
}

obj := make(map[string]interface{})
locationProp, err := expandApigeeEndpointAttachmentLocation(d.Get("location"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("location"); !isEmptyValue(reflect.ValueOf(locationProp)) && (ok || !reflect.DeepEqual(v, locationProp)) {
obj["location"] = locationProp
}
serviceAttachmentProp, err := expandApigeeEndpointAttachmentServiceAttachment(d.Get("service_attachment"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("service_attachment"); !isEmptyValue(reflect.ValueOf(serviceAttachmentProp)) && (ok || !reflect.DeepEqual(v, serviceAttachmentProp)) {
obj["serviceAttachment"] = serviceAttachmentProp
}

url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/endpointAttachments?endpointAttachmentId={{endpoint_attachment_id}}")
if err != nil {
return err
}

log.Printf("[DEBUG] Creating new EndpointAttachment: %#v", obj)
billingProject := ""

// err == nil indicates that the billing_project value was found
if bp, err := getBillingProject(d, config); err == nil {
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate))
if err != nil {
return fmt.Errorf("Error creating EndpointAttachment: %s", err)
}

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

// Use the resource in the operation response to populate
// identity fields and d.Id() before read
var opRes map[string]interface{}
err = apigeeOperationWaitTimeWithResponse(
config, res, &opRes, "Creating EndpointAttachment", userAgent,
d.Timeout(schema.TimeoutCreate))
if err != nil {
// The resource didn't actually create
d.SetId("")
return fmt.Errorf("Error waiting to create EndpointAttachment: %s", err)
}

if err := d.Set("name", flattenApigeeEndpointAttachmentName(opRes["name"], d, config)); err != nil {
return err
}

// This may have caused the ID to update - update it if so.
id, err = replaceVars(d, config, "{{org_id}}/endpointAttachments/{{endpoint_attachment_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

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

return resourceApigeeEndpointAttachmentRead(d, meta)
}

func resourceApigeeEndpointAttachmentRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
}

url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/endpointAttachments/{{endpoint_attachment_id}}")
if err != nil {
return err
}

billingProject := ""

// err == nil indicates that the billing_project value was found
if bp, err := getBillingProject(d, config); err == nil {
billingProject = bp
}

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

if err := d.Set("name", flattenApigeeEndpointAttachmentName(res["name"], d, config)); err != nil {
return fmt.Errorf("Error reading EndpointAttachment: %s", err)
}
if err := d.Set("location", flattenApigeeEndpointAttachmentLocation(res["location"], d, config)); err != nil {
return fmt.Errorf("Error reading EndpointAttachment: %s", err)
}
if err := d.Set("host", flattenApigeeEndpointAttachmentHost(res["host"], d, config)); err != nil {
return fmt.Errorf("Error reading EndpointAttachment: %s", err)
}
if err := d.Set("service_attachment", flattenApigeeEndpointAttachmentServiceAttachment(res["serviceAttachment"], d, config)); err != nil {
return fmt.Errorf("Error reading EndpointAttachment: %s", err)
}

return nil
}

func resourceApigeeEndpointAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
}

billingProject := ""

url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/endpointAttachments/{{endpoint_attachment_id}}")
if err != nil {
return err
}

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

// err == nil indicates that the billing_project value was found
if bp, err := getBillingProject(d, config); err == nil {
billingProject = bp
}

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

err = apigeeOperationWaitTime(
config, res, "Deleting EndpointAttachment", userAgent,
d.Timeout(schema.TimeoutDelete))

if err != nil {
return err
}

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

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

// current import_formats cannot import fields with forward slashes in their value
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}

nameParts := strings.Split(d.Get("name").(string), "/")
if len(nameParts) == 4 {
// `organizations/{{org_name}}/endpointAttachment/{{endpoint_attachment_id}}`
orgId := fmt.Sprintf("organizations/%s", nameParts[1])
if err := d.Set("org_id", orgId); err != nil {
return nil, fmt.Errorf("Error setting org_id: %s", err)
}
if err := d.Set("endpoint_attachment_id", nameParts[3]); err != nil {
return nil, fmt.Errorf("Error setting endpoint_attachment_id: %s", err)
}
} else {
return nil, fmt.Errorf(
"Saw %s when the name is expected to have shape %s",
d.Get("name"),
"organizations/{{org_name}}/environments/{{name}}")
}

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

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

func flattenApigeeEndpointAttachmentName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenApigeeEndpointAttachmentLocation(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenApigeeEndpointAttachmentHost(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenApigeeEndpointAttachmentServiceAttachment(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

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

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