From 161e3a027cc7f20204795dc41b78ba48e8028ab6 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 24 Feb 2021 10:43:48 -0800 Subject: [PATCH] Apigee instance (#4503) (#8546) * Added code for Apigee instance * Apigee instance fixes * re-add vcr tests * skip_vcr tests Co-authored-by: Priya Saxena Signed-off-by: Modular Magician Co-authored-by: Priya Saxena --- .changelog/4503.txt | 3 + google/provider.go | 5 +- google/resource_apigee_instance.go | 395 ++++++++++++++++++ ...resource_apigee_instance_generated_test.go | 152 +++++++ .../resource_apigee_instance_sweeper_test.go | 128 ++++++ website/docs/r/apigee_instance.html.markdown | 221 ++++++++++ .../docs/r/apigee_organization.html.markdown | 2 +- website/google.erb | 4 + 8 files changed, 907 insertions(+), 3 deletions(-) create mode 100644 .changelog/4503.txt create mode 100644 google/resource_apigee_instance.go create mode 100644 google/resource_apigee_instance_generated_test.go create mode 100644 google/resource_apigee_instance_sweeper_test.go create mode 100644 website/docs/r/apigee_instance.html.markdown diff --git a/.changelog/4503.txt b/.changelog/4503.txt new file mode 100644 index 00000000000..adc8881e826 --- /dev/null +++ b/.changelog/4503.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +google_apigee_instance +``` diff --git a/google/provider.go b/google/provider.go index cd2dc696260..614d4679aac 100644 --- a/google/provider.go +++ b/google/provider.go @@ -717,9 +717,9 @@ func Provider() *schema.Provider { return provider } -// Generated resources: 181 +// Generated resources: 182 // Generated IAM resources: 75 -// Total generated resources: 256 +// Total generated resources: 257 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -742,6 +742,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_active_directory_domain": resourceActiveDirectoryDomain(), "google_active_directory_domain_trust": resourceActiveDirectoryDomainTrust(), "google_apigee_organization": resourceApigeeOrganization(), + "google_apigee_instance": resourceApigeeInstance(), "google_app_engine_domain_mapping": resourceAppEngineDomainMapping(), "google_app_engine_firewall_rule": resourceAppEngineFirewallRule(), "google_app_engine_standard_app_version": resourceAppEngineStandardAppVersion(), diff --git a/google/resource_apigee_instance.go b/google/resource_apigee_instance.go new file mode 100644 index 00000000000..e199aecb421 --- /dev/null +++ b/google/resource_apigee_instance.go @@ -0,0 +1,395 @@ +// ---------------------------------------------------------------------------- +// +// *** 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/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func resourceApigeeInstance() *schema.Resource { + return &schema.Resource{ + Create: resourceApigeeInstanceCreate, + Read: resourceApigeeInstanceRead, + Delete: resourceApigeeInstanceDelete, + + Importer: &schema.ResourceImporter{ + State: resourceApigeeInstanceImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "location": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `Compute Engine location where the instance resides. For trial organization +subscriptions, the location must be a Compute Engine zone. For paid organization +subscriptions, it should correspond to a Compute Engine region.`, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `Resource ID of the instance.`, + }, + "org_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The Apigee Organization associated with the Apigee instance, +in the format 'organizations/{{org_name}}'.`, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: `Description of the instance.`, + }, + "disk_encryption_key_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: `Customer Managed Encryption Key (CMEK) used for disk and volume encryption. Required for Apigee paid subscriptions only. +Use the following format: 'projects/([^/]+)/locations/([^/]+)/keyRings/([^/]+)/cryptoKeys/([^/]+)'`, + }, + "display_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: `Display name of the instance.`, + }, + "peering_cidr_range": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"SLASH_16", "SLASH_20", ""}, false), + Description: `The size of the CIDR block range that will be reserved by the instance. Default value: "SLASH_16" Possible values: ["SLASH_16", "SLASH_20"]`, + Default: "SLASH_16", + }, + "host": { + Type: schema.TypeString, + Computed: true, + Description: `Output only. Hostname or IP address of the exposed Apigee endpoint used by clients to connect to the service.`, + }, + "port": { + Type: schema.TypeString, + Computed: true, + Description: `Output only. Port number of the exposed Apigee endpoint.`, + }, + }, + UseJSONNumber: true, + } +} + +func resourceApigeeInstanceCreate(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{}) + nameProp, err := expandApigeeInstanceName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } + locationProp, err := expandApigeeInstanceLocation(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 + } + peeringCidrRangeProp, err := expandApigeeInstancePeeringCidrRange(d.Get("peering_cidr_range"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("peering_cidr_range"); !isEmptyValue(reflect.ValueOf(peeringCidrRangeProp)) && (ok || !reflect.DeepEqual(v, peeringCidrRangeProp)) { + obj["peeringCidrRange"] = peeringCidrRangeProp + } + descriptionProp, err := expandApigeeInstanceDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + displayNameProp, err := expandApigeeInstanceDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + diskEncryptionKeyNameProp, err := expandApigeeInstanceDiskEncryptionKeyName(d.Get("disk_encryption_key_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("disk_encryption_key_name"); !isEmptyValue(reflect.ValueOf(diskEncryptionKeyNameProp)) && (ok || !reflect.DeepEqual(v, diskEncryptionKeyNameProp)) { + obj["diskEncryptionKeyName"] = diskEncryptionKeyNameProp + } + + url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/instances") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Instance: %#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 Instance: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{org_id}}/instances/{{name}}") + 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 Instance", userAgent, + d.Timeout(schema.TimeoutCreate)) + if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create Instance: %s", err) + } + + if err := d.Set("name", flattenApigeeInstanceName(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}}/instances/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating Instance %q: %#v", d.Id(), res) + + return resourceApigeeInstanceRead(d, meta) +} + +func resourceApigeeInstanceRead(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}}/instances/{{name}}") + 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("ApigeeInstance %q", d.Id())) + } + + if err := d.Set("name", flattenApigeeInstanceName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error reading Instance: %s", err) + } + if err := d.Set("location", flattenApigeeInstanceLocation(res["location"], d, config)); err != nil { + return fmt.Errorf("Error reading Instance: %s", err) + } + if err := d.Set("peering_cidr_range", flattenApigeeInstancePeeringCidrRange(res["peeringCidrRange"], d, config)); err != nil { + return fmt.Errorf("Error reading Instance: %s", err) + } + if err := d.Set("description", flattenApigeeInstanceDescription(res["description"], d, config)); err != nil { + return fmt.Errorf("Error reading Instance: %s", err) + } + if err := d.Set("display_name", flattenApigeeInstanceDisplayName(res["displayName"], d, config)); err != nil { + return fmt.Errorf("Error reading Instance: %s", err) + } + if err := d.Set("disk_encryption_key_name", flattenApigeeInstanceDiskEncryptionKeyName(res["diskEncryptionKeyName"], d, config)); err != nil { + return fmt.Errorf("Error reading Instance: %s", err) + } + if err := d.Set("host", flattenApigeeInstanceHost(res["host"], d, config)); err != nil { + return fmt.Errorf("Error reading Instance: %s", err) + } + if err := d.Set("port", flattenApigeeInstancePort(res["port"], d, config)); err != nil { + return fmt.Errorf("Error reading Instance: %s", err) + } + + return nil +} + +func resourceApigeeInstanceDelete(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}}/instances/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Instance %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, "Instance") + } + + err = apigeeOperationWaitTime( + config, res, "Deleting Instance", userAgent, + d.Timeout(schema.TimeoutDelete)) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting Instance %q: %#v", d.Id(), res) + return nil +} + +func resourceApigeeInstanceImport(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.+)"}, d, config); err != nil { + return nil, err + } + + nameParts := strings.Split(d.Get("name").(string), "/") + if len(nameParts) == 4 { + // `organizations/{{org_name}}/instances/{{name}}` + 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("name", nameParts[3]); err != nil { + return nil, fmt.Errorf("Error setting name: %s", err) + } + } else if len(nameParts) == 3 { + // `organizations/{{org_name}}/{{name}}` + 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("name", nameParts[2]); err != nil { + return nil, fmt.Errorf("Error setting name: %s", err) + } + } else { + return nil, fmt.Errorf( + "Saw %s when the name is expected to have shape %s or %s", + d.Get("name"), + "organizations/{{org_name}}/instances/{{name}}", + "organizations/{{org_name}}/{{name}}") + } + + // Replace import id for the resource id + id, err := replaceVars(d, config, "{{org_id}}/instances/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenApigeeInstanceName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenApigeeInstanceLocation(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenApigeeInstancePeeringCidrRange(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenApigeeInstanceDescription(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenApigeeInstanceDisplayName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenApigeeInstanceDiskEncryptionKeyName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenApigeeInstanceHost(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenApigeeInstancePort(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func expandApigeeInstanceName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandApigeeInstanceLocation(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandApigeeInstancePeeringCidrRange(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandApigeeInstanceDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandApigeeInstanceDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandApigeeInstanceDiskEncryptionKeyName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google/resource_apigee_instance_generated_test.go b/google/resource_apigee_instance_generated_test.go new file mode 100644 index 00000000000..64ea8a8e9df --- /dev/null +++ b/google/resource_apigee_instance_generated_test.go @@ -0,0 +1,152 @@ +// ---------------------------------------------------------------------------- +// +// *** 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" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccApigeeInstance_apigeeInstanceBasicTestExample(t *testing.T) { + skipIfVcr(t) + t.Parallel() + + context := map[string]interface{}{ + "org_id": getTestOrgFromEnv(t), + "billing_account": getTestBillingAccountFromEnv(t), + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + ExternalProviders: map[string]resource.ExternalProvider{ + "random": {}, + }, + CheckDestroy: testAccCheckApigeeInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccApigeeInstance_apigeeInstanceBasicTestExample(context), + }, + { + ResourceName: "google_apigee_instance.apigee_instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"org_id"}, + }, + }, + }) +} + +func testAccApigeeInstance_apigeeInstanceBasicTestExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_project" "project" { + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" +} + +resource "google_project_service" "apigee" { + project = google_project.project.project_id + service = "apigee.googleapis.com" +} + +resource "google_project_service" "compute" { + project = google_project.project.project_id + service = "compute.googleapis.com" +} + +resource "google_project_service" "servicenetworking" { + project = google_project.project.project_id + service = "servicenetworking.googleapis.com" +} + +resource "google_compute_network" "apigee_network" { + name = "apigee-network" + project = google_project.project.project_id + depends_on = [google_project_service.compute] +} + +resource "google_compute_global_address" "apigee_range" { + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id + project = google_project.project.project_id +} + +resource "google_service_networking_connection" "apigee_vpc_connection" { + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] + depends_on = [google_project_service.servicenetworking] +} + +resource "google_apigee_organization" "apigee_org" { + analytics_region = "us-central1" + project_id = google_project.project.project_id + authorized_network = google_compute_network.apigee_network.id + depends_on = [ + google_service_networking_connection.apigee_vpc_connection, + google_project_service.apigee, + ] +} + +resource "google_apigee_instance" "apigee_instance" { + name = "tf-test%{random_suffix}" + location = "us-central1-b" + org_id = google_apigee_organization.apigee_org.id +} +`, context) +} + +func testAccCheckApigeeInstanceDestroyProducer(t *testing.T) func(s *terraform.State) error { + return func(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_apigee_instance" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := googleProviderConfig(t) + + url, err := replaceVarsForTest(config, rs, "{{ApigeeBasePath}}{{org_id}}/instances/{{name}}") + if err != nil { + return err + } + + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) + if err == nil { + return fmt.Errorf("ApigeeInstance still exists at %s", url) + } + } + + return nil + } +} diff --git a/google/resource_apigee_instance_sweeper_test.go b/google/resource_apigee_instance_sweeper_test.go new file mode 100644 index 00000000000..063c29475f7 --- /dev/null +++ b/google/resource_apigee_instance_sweeper_test.go @@ -0,0 +1,128 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 ( + "context" + "log" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func init() { + resource.AddTestSweepers("ApigeeInstance", &resource.Sweeper{ + Name: "ApigeeInstance", + F: testSweepApigeeInstance, + }) +} + +// At the time of writing, the CI only passes us-central1 as the region +func testSweepApigeeInstance(region string) error { + resourceName := "ApigeeInstance" + log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s", resourceName) + + config, err := sharedConfigForRegion(region) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error getting shared config for region: %s", err) + return err + } + + err = config.LoadAndValidate(context.Background()) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error loading: %s", err) + return err + } + + t := &testing.T{} + billingId := getTestBillingAccountFromEnv(t) + + // Setup variables to replace in list template + d := &ResourceDataMock{ + FieldsInSchema: map[string]interface{}{ + "project": config.Project, + "region": region, + "location": region, + "zone": "-", + "billing_account": billingId, + }, + } + + listTemplate := strings.Split("https://apigee.googleapis.com/v1/instances", "?")[0] + listUrl, err := replaceVars(d, config, listTemplate) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s", err) + return nil + } + + res, err := sendRequest(config, "GET", config.Project, listUrl, config.userAgent, nil) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error in response from request %s: %s", listUrl, err) + return nil + } + + resourceList, ok := res["instances"] + if !ok { + log.Printf("[INFO][SWEEPER_LOG] Nothing found in response.") + return nil + } + + rl := resourceList.([]interface{}) + + log.Printf("[INFO][SWEEPER_LOG] Found %d items in %s list response.", len(rl), resourceName) + // Keep count of items that aren't sweepable for logging. + nonPrefixCount := 0 + for _, ri := range rl { + obj := ri.(map[string]interface{}) + var name string + // Id detected in the delete URL, attempt to use id. + if obj["id"] != nil { + name = GetResourceNameFromSelfLink(obj["id"].(string)) + } else if obj["name"] != nil { + name = GetResourceNameFromSelfLink(obj["name"].(string)) + } else { + log.Printf("[INFO][SWEEPER_LOG] %s resource name and id were nil", resourceName) + return nil + } + // Skip resources that shouldn't be sweeped + if !isSweepableTestResource(name) { + nonPrefixCount++ + continue + } + + deleteTemplate := "https://apigee.googleapis.com/v1/{{org_id}}/instances/{{name}}" + deleteUrl, err := replaceVars(d, config, deleteTemplate) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err) + return nil + } + deleteUrl = deleteUrl + name + + // Don't wait on operations as we may have a lot to delete + _, err = sendRequest(config, "DELETE", config.Project, deleteUrl, config.userAgent, nil) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error deleting for url %s : %s", deleteUrl, err) + } else { + log.Printf("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s", resourceName, name) + } + } + + if nonPrefixCount > 0 { + log.Printf("[INFO][SWEEPER_LOG] %d items were non-sweepable and skipped.", nonPrefixCount) + } + + return nil +} diff --git a/website/docs/r/apigee_instance.html.markdown b/website/docs/r/apigee_instance.html.markdown new file mode 100644 index 00000000000..8a31b249e67 --- /dev/null +++ b/website/docs/r/apigee_instance.html.markdown @@ -0,0 +1,221 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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. +# +# ---------------------------------------------------------------------------- +subcategory: "Apigee" +layout: "google" +page_title: "Google: google_apigee_instance" +sidebar_current: "docs-google-apigee-instance" +description: |- + An `Instance` is the runtime dataplane in Apigee. +--- + +# google\_apigee\_instance + +An `Instance` is the runtime dataplane in Apigee. + + +To get more information about Instance, see: + +* [API documentation](https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.instances/create) +* How-to Guides + * [Creating a runtime instance](https://cloud.google.com/apigee/docs/api-platform/get-started/create-instance) + +## Example Usage - Apigee Instance Basic + + +```hcl +data "google_client_config" "current" {} + +resource "google_compute_network" "apigee_network" { + name = "apigee-network" +} + +resource "google_compute_global_address" "apigee_range" { + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id +} + +resource "google_service_networking_connection" "apigee_vpc_connection" { + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] +} + +resource "google_apigee_organization" "apigee_org" { + analytics_region = "us-central1" + project_id = data.google_client_config.current.project + authorized_network = google_compute_network.apigee_network.id + depends_on = [google_service_networking_connection.apigee_vpc_connection] +} + +resource "google_apigee_instance" "apigee_instance" { + name = "tf-test%{random_suffix}" + location = "us-central1-b" + org_id = google_apigee_organization.apigee_org.id +} +``` +## Example Usage - Apigee Instance Full + + +```hcl +data "google_client_config" "current" {} + +resource "google_compute_network" "apigee_network" { + name = "apigee-network" +} + +resource "google_compute_global_address" "apigee_range" { + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id +} + +resource "google_service_networking_connection" "apigee_vpc_connection" { + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] +} + +resource "google_kms_key_ring" "apigee_keyring" { + name = "apigee-keyring" + location = "us-central1" +} + +resource "google_kms_crypto_key" "apigee_key" { + name = "apigee-key" + key_ring = google_kms_key_ring.apigee_keyring.id + + lifecycle { + prevent_destroy = true + } +} + +resource "google_project_service_identity" "apigee_sa" { + provider = google-beta + project = google_project.project.project_id + service = google_project_service.apigee.service +} + +resource "google_kms_crypto_key_iam_binding" "apigee_sa_keyuser" { + crypto_key_id = google_kms_crypto_key.apigee_key.id + role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" + + members = [ + "serviceAccount:${google_project_service_identity.apigee_sa.email}", + ] +} + +resource "google_apigee_organization" "apigee_org" { + analytics_region = "us-central1" + display_name = "apigee-org" + description = "Terraform-provisioned Apigee Org." + project_id = data.google_client_config.current.project + authorized_network = google_compute_network.apigee_network.id + runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id + + depends_on = [ + google_service_networking_connection.apigee_vpc_connection, + google_kms_crypto_key_iam_binding.apigee_sa_keyuser, + ] +} + +resource "google_apigee_instance" "apigee_instance" { + name = "tf-test%{random_suffix}" + location = "us-central1-b" + description = "Terraform-managed Apigee Runtime Instance" + display_name = "tf-test%{random_suffix}" + org_id = google_apigee_organization.apigee_org.id + disk_encryption_key_name = google_kms_crypto_key.apigee_key.id +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `name` - + (Required) + Resource ID of the instance. + +* `location` - + (Required) + Compute Engine location where the instance resides. For trial organization + subscriptions, the location must be a Compute Engine zone. For paid organization + subscriptions, it should correspond to a Compute Engine region. + +* `org_id` - + (Required) + The Apigee Organization associated with the Apigee instance, + in the format `organizations/{{org_name}}`. + + +- - - + + +* `peering_cidr_range` - + (Optional) + The size of the CIDR block range that will be reserved by the instance. + Default value is `SLASH_16`. + Possible values are `SLASH_16` and `SLASH_20`. + +* `description` - + (Optional) + Description of the instance. + +* `display_name` - + (Optional) + Display name of the instance. + +* `disk_encryption_key_name` - + (Optional) + Customer Managed Encryption Key (CMEK) used for disk and volume encryption. Required for Apigee paid subscriptions only. + Use the following format: `projects/([^/]+)/locations/([^/]+)/keyRings/([^/]+)/cryptoKeys/([^/]+)` + + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `{{org_id}}/instances/{{name}}` + +* `host` - + Output only. Hostname or IP address of the exposed Apigee endpoint used by clients to connect to the service. + +* `port` - + Output only. Port number of the exposed Apigee endpoint. + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 30 minutes. +- `delete` - Default is 30 minutes. + +## Import + + +Instance can be imported using any of these accepted formats: + +``` +$ terraform import google_apigee_instance.default {{org_id}}/instances/{{name}} +$ terraform import google_apigee_instance.default {{org_id}}/{{name}} +``` diff --git a/website/docs/r/apigee_organization.html.markdown b/website/docs/r/apigee_organization.html.markdown index 914437807cd..23d8c3668c6 100644 --- a/website/docs/r/apigee_organization.html.markdown +++ b/website/docs/r/apigee_organization.html.markdown @@ -121,7 +121,7 @@ resource "google_apigee_organization" "org" { description = "Terraform-provisioned Apigee Org." project_id = data.google_client_config.current.project authorized_network = google_compute_network.apigee_network.id - runtime_database_encryption_key_name = google_kms_key.apigee_key.id + runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id depends_on = [ google_service_networking_connection.apigee_vpc_connection, diff --git a/website/google.erb b/website/google.erb index 82aad3b1409..b10d111b98f 100644 --- a/website/google.erb +++ b/website/google.erb @@ -170,6 +170,10 @@ Resources