From 0db8796bc5960d7c635276a195736569a9bb76f8 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 25 Feb 2020 01:35:09 +0000 Subject: [PATCH] VPC serverless access update version from beta to GA (#3053) * remove beta provider vpc access connector is now GA https://cloud.google.com/functions/docs/release-notes#December_11_2019 * updated versions for VPC serverless acess * add back beta version * remove beta references in resource * remove google-beta provider from example Signed-off-by: Modular Magician --- .changelog/3053.txt | 3 + google/config.go | 3 + google/provider.go | 14 +- google/resource_vpc_access_connector.go | 388 ++++++++++++++++++ ...rce_vpc_access_connector_generated_test.go | 86 ++++ ...ource_vpc_access_connector_sweeper_test.go | 119 ++++++ google/vpc_access_operation.go | 71 ++++ .../docs/r/vpc_access_connector.html.markdown | 125 ++++++ 8 files changed, 807 insertions(+), 2 deletions(-) create mode 100644 .changelog/3053.txt create mode 100644 google/resource_vpc_access_connector.go create mode 100644 google/resource_vpc_access_connector_generated_test.go create mode 100644 google/resource_vpc_access_connector_sweeper_test.go create mode 100644 google/vpc_access_operation.go create mode 100644 website/docs/r/vpc_access_connector.html.markdown diff --git a/.changelog/3053.txt b/.changelog/3053.txt new file mode 100644 index 00000000000..cc2fa5ac5e7 --- /dev/null +++ b/.changelog/3053.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_vpc_access_connector` (GA provider) +``` diff --git a/google/config.go b/google/config.go index 13fb6182c22..ebc08baea64 100644 --- a/google/config.go +++ b/google/config.go @@ -109,6 +109,7 @@ type Config struct { SQLBasePath string StorageBasePath string TPUBasePath string + VPCAccessBasePath string CloudBillingBasePath string clientBilling *cloudbilling.APIService @@ -242,6 +243,7 @@ var SpannerDefaultBasePath = "https://spanner.googleapis.com/v1/" var SQLDefaultBasePath = "https://sqladmin.googleapis.com/sql/v1beta4/" var StorageDefaultBasePath = "https://www.googleapis.com/storage/v1/" var TPUDefaultBasePath = "https://tpu.googleapis.com/v1/" +var VPCAccessDefaultBasePath = "https://vpcaccess.googleapis.com/v1/" var defaultClientScopes = []string{ "https://www.googleapis.com/auth/compute", @@ -720,6 +722,7 @@ func ConfigureBasePaths(c *Config) { c.SQLBasePath = SQLDefaultBasePath c.StorageBasePath = StorageDefaultBasePath c.TPUBasePath = TPUDefaultBasePath + c.VPCAccessBasePath = VPCAccessDefaultBasePath // Handwritten Products / Versioned / Atypical Entries c.CloudBillingBasePath = CloudBillingDefaultBasePath diff --git a/google/provider.go b/google/provider.go index ae9816959a3..5ea76711811 100644 --- a/google/provider.go +++ b/google/provider.go @@ -405,6 +405,14 @@ func Provider() terraform.ResourceProvider { "GOOGLE_TPU_CUSTOM_ENDPOINT", }, TPUDefaultBasePath), }, + "vpc_access_custom_endpoint": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateCustomEndpoint, + DefaultFunc: schema.MultiEnvDefaultFunc([]string{ + "GOOGLE_VPC_ACCESS_CUSTOM_ENDPOINT", + }, VPCAccessDefaultBasePath), + }, // Handwritten Products / Versioned / Atypical Entries CloudBillingCustomEndpointEntryKey: CloudBillingCustomEndpointEntry, @@ -503,9 +511,9 @@ func Provider() terraform.ResourceProvider { return provider } -// Generated resources: 102 +// Generated resources: 103 // Generated IAM resources: 51 -// Total generated resources: 153 +// Total generated resources: 154 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -667,6 +675,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_storage_default_object_access_control": resourceStorageDefaultObjectAccessControl(), "google_storage_hmac_key": resourceStorageHmacKey(), "google_tpu_node": resourceTPUNode(), + "google_vpc_access_connector": resourceVPCAccessConnector(), }, map[string]*schema.Resource{ "google_app_engine_application": resourceAppEngineApplication(), @@ -853,6 +862,7 @@ func providerConfigure(d *schema.ResourceData, p *schema.Provider, terraformVers config.SQLBasePath = d.Get("sql_custom_endpoint").(string) config.StorageBasePath = d.Get("storage_custom_endpoint").(string) config.TPUBasePath = d.Get("tpu_custom_endpoint").(string) + config.VPCAccessBasePath = d.Get("vpc_access_custom_endpoint").(string) // Handwritten Products / Versioned / Atypical Entries diff --git a/google/resource_vpc_access_connector.go b/google/resource_vpc_access_connector.go new file mode 100644 index 00000000000..6f05f9919a6 --- /dev/null +++ b/google/resource_vpc_access_connector.go @@ -0,0 +1,388 @@ +// ---------------------------------------------------------------------------- +// +// *** 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" + "strconv" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" +) + +func resourceVPCAccessConnector() *schema.Resource { + return &schema.Resource{ + Create: resourceVPCAccessConnectorCreate, + Read: resourceVPCAccessConnectorRead, + Delete: resourceVPCAccessConnectorDelete, + + Importer: &schema.ResourceImporter{ + State: resourceVPCAccessConnectorImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(6 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "ip_cidr_range": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The range of internal addresses that follows RFC 4632 notation. Example: '10.132.0.0/28'.`, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The name of the resource (Max 25 characters).`, + }, + "network": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `Name of a VPC network.`, + }, + "region": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `Region where the VPC Access connector resides`, + }, + "max_throughput": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + ValidateFunc: validation.IntBetween(200, 1000), + Description: `Maximum throughput of the connector in Mbps, must be greater than 'min_throughput'. Default is 1000.`, + Default: 1000, + }, + "min_throughput": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + ValidateFunc: validation.IntBetween(200, 1000), + Description: `Minimum throughput of the connector in Mbps. Default and min is 200.`, + Default: 200, + }, + "self_link": { + Type: schema.TypeString, + Computed: true, + Description: `The fully qualified name of this VPC connector`, + }, + "state": { + Type: schema.TypeString, + Computed: true, + Description: `State of the VPC access connector.`, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + } +} + +func resourceVPCAccessConnectorCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + nameProp, err := expandVPCAccessConnectorName(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 + } + networkProp, err := expandVPCAccessConnectorNetwork(d.Get("network"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("network"); !isEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) { + obj["network"] = networkProp + } + ipCidrRangeProp, err := expandVPCAccessConnectorIpCidrRange(d.Get("ip_cidr_range"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("ip_cidr_range"); !isEmptyValue(reflect.ValueOf(ipCidrRangeProp)) && (ok || !reflect.DeepEqual(v, ipCidrRangeProp)) { + obj["ipCidrRange"] = ipCidrRangeProp + } + minThroughputProp, err := expandVPCAccessConnectorMinThroughput(d.Get("min_throughput"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("min_throughput"); !isEmptyValue(reflect.ValueOf(minThroughputProp)) && (ok || !reflect.DeepEqual(v, minThroughputProp)) { + obj["minThroughput"] = minThroughputProp + } + maxThroughputProp, err := expandVPCAccessConnectorMaxThroughput(d.Get("max_throughput"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("max_throughput"); !isEmptyValue(reflect.ValueOf(maxThroughputProp)) && (ok || !reflect.DeepEqual(v, maxThroughputProp)) { + obj["maxThroughput"] = maxThroughputProp + } + + obj, err = resourceVPCAccessConnectorEncoder(d, meta, obj) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{VPCAccessBasePath}}projects/{{project}}/locations/{{region}}/connectors?connectorId={{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Connector: %#v", obj) + project, err := getProject(d, config) + if err != nil { + return err + } + res, err := sendRequestWithTimeout(config, "POST", project, url, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating Connector: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "projects/{{project}}/locations/{{region}}/connectors/{{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 = vpcAccessOperationWaitTimeWithResponse( + config, res, &opRes, project, "Creating Connector", + int(d.Timeout(schema.TimeoutCreate).Minutes())) + if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create Connector: %s", err) + } + + opRes, err = resourceVPCAccessConnectorDecoder(d, meta, opRes) + if err != nil { + return fmt.Errorf("Error decoding response from operation: %s", err) + } + if opRes == nil { + return fmt.Errorf("Error decoding response from operation, could not find object") + } + if err := d.Set("name", flattenVPCAccessConnectorName(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, "projects/{{project}}/locations/{{region}}/connectors/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating Connector %q: %#v", d.Id(), res) + + // This is useful if the resource in question doesn't have a perfectly consistent API + // That is, the Operation for Create might return before the Get operation shows the + // completed state of the resource. + time.Sleep(5 * time.Second) + + return resourceVPCAccessConnectorRead(d, meta) +} + +func resourceVPCAccessConnectorRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "{{VPCAccessBasePath}}projects/{{project}}/locations/{{region}}/connectors/{{name}}") + if err != nil { + return err + } + + project, err := getProject(d, config) + if err != nil { + return err + } + res, err := sendRequest(config, "GET", project, url, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("VPCAccessConnector %q", d.Id())) + } + + res, err = resourceVPCAccessConnectorDecoder(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 VPCAccessConnector because it no longer exists.") + d.SetId("") + return nil + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading Connector: %s", err) + } + + if err := d.Set("name", flattenVPCAccessConnectorName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error reading Connector: %s", err) + } + if err := d.Set("network", flattenVPCAccessConnectorNetwork(res["network"], d, config)); err != nil { + return fmt.Errorf("Error reading Connector: %s", err) + } + if err := d.Set("ip_cidr_range", flattenVPCAccessConnectorIpCidrRange(res["ipCidrRange"], d, config)); err != nil { + return fmt.Errorf("Error reading Connector: %s", err) + } + if err := d.Set("state", flattenVPCAccessConnectorState(res["state"], d, config)); err != nil { + return fmt.Errorf("Error reading Connector: %s", err) + } + if err := d.Set("min_throughput", flattenVPCAccessConnectorMinThroughput(res["minThroughput"], d, config)); err != nil { + return fmt.Errorf("Error reading Connector: %s", err) + } + if err := d.Set("max_throughput", flattenVPCAccessConnectorMaxThroughput(res["maxThroughput"], d, config)); err != nil { + return fmt.Errorf("Error reading Connector: %s", err) + } + + return nil +} + +func resourceVPCAccessConnectorDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{VPCAccessBasePath}}projects/{{project}}/locations/{{region}}/connectors/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Connector %q", d.Id()) + + res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "Connector") + } + + err = vpcAccessOperationWaitTime( + config, res, project, "Deleting Connector", + int(d.Timeout(schema.TimeoutDelete).Minutes())) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting Connector %q: %#v", d.Id(), res) + return nil +} + +func resourceVPCAccessConnectorImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if err := parseImportId([]string{ + "projects/(?P[^/]+)/locations/(?P[^/]+)/connectors/(?P[^/]+)", + "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", + "(?P[^/]+)/(?P[^/]+)", + "(?P[^/]+)", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := replaceVars(d, config, "projects/{{project}}/locations/{{region}}/connectors/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenVPCAccessConnectorName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + return NameFromSelfLinkStateFunc(v) +} + +func flattenVPCAccessConnectorNetwork(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVPCAccessConnectorIpCidrRange(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVPCAccessConnectorState(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVPCAccessConnectorMinThroughput(v interface{}, d *schema.ResourceData, config *Config) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil { + return intVal + } // let terraform core handle it if we can't convert the string to an int. + } + return v +} + +func flattenVPCAccessConnectorMaxThroughput(v interface{}, d *schema.ResourceData, config *Config) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil { + return intVal + } // let terraform core handle it if we can't convert the string to an int. + } + return v +} + +func expandVPCAccessConnectorName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandVPCAccessConnectorNetwork(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandVPCAccessConnectorIpCidrRange(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandVPCAccessConnectorMinThroughput(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandVPCAccessConnectorMaxThroughput(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func resourceVPCAccessConnectorEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { + delete(obj, "name") + return obj, nil +} + +func resourceVPCAccessConnectorDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { + // Take the returned long form of the name and use it as `self_link`. + // Then modify the name to be the user specified form. + // We can't just ignore_read on `name` as the linter will + // complain that the returned `res` is never used afterwards. + // Some field needs to be actually set, and we chose `name`. + d.Set("self_link", res["name"].(string)) + res["name"] = d.Get("name").(string) + return res, nil +} diff --git a/google/resource_vpc_access_connector_generated_test.go b/google/resource_vpc_access_connector_generated_test.go new file mode 100644 index 00000000000..d1972b0e4b2 --- /dev/null +++ b/google/resource_vpc_access_connector_generated_test.go @@ -0,0 +1,86 @@ +// ---------------------------------------------------------------------------- +// +// *** 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/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccVPCAccessConnector_vpcAccessConnectorExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVPCAccessConnectorDestroy, + Steps: []resource.TestStep{ + { + Config: testAccVPCAccessConnector_vpcAccessConnectorExample(context), + }, + { + ResourceName: "google_vpc_access_connector.connector", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"self_link", "region"}, + }, + }, + }) +} + +func testAccVPCAccessConnector_vpcAccessConnectorExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_vpc_access_connector" "connector" { + name = "vpcconn%{random_suffix}" + region = "us-central1" + ip_cidr_range = "10.8.0.0/28" + network = "default" +} +`, context) +} + +func testAccCheckVPCAccessConnectorDestroy(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_vpc_access_connector" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := testAccProvider.Meta().(*Config) + + url, err := replaceVarsForTest(config, rs, "{{VPCAccessBasePath}}projects/{{project}}/locations/{{region}}/connectors/{{name}}") + if err != nil { + return err + } + + _, err = sendRequest(config, "GET", "", url, nil) + if err == nil { + return fmt.Errorf("VPCAccessConnector still exists at %s", url) + } + } + + return nil +} diff --git a/google/resource_vpc_access_connector_sweeper_test.go b/google/resource_vpc_access_connector_sweeper_test.go new file mode 100644 index 00000000000..b7946a6d661 --- /dev/null +++ b/google/resource_vpc_access_connector_sweeper_test.go @@ -0,0 +1,119 @@ +// ---------------------------------------------------------------------------- +// +// *** 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" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func init() { + resource.AddTestSweepers("VPCAccessConnector", &resource.Sweeper{ + Name: "VPCAccessConnector", + F: testSweepVPCAccessConnector, + }) +} + +// At the time of writing, the CI only passes us-central1 as the region +func testSweepVPCAccessConnector(region string) error { + resourceName := "VPCAccessConnector" + 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 + } + + // Setup variables to replace in list template + d := &ResourceDataMock{ + FieldsInSchema: map[string]interface{}{ + "project": config.Project, + "region": region, + "location": region, + "zone": "-", + }, + } + + listTemplate := strings.Split("https://vpcaccess.googleapis.com/v1/projects/{{project}}/locations/{{region}}/connectors", "?")[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, nil) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error in response from request %s: %s", listUrl, err) + return nil + } + + resourceList, ok := res["connectors"] + 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) + // items who don't match the tf-test prefix + nonPrefixCount := 0 + for _, ri := range rl { + obj := ri.(map[string]interface{}) + if obj["name"] == nil { + log.Printf("[INFO][SWEEPER_LOG] %s resource name was nil", resourceName) + return nil + } + + name := GetResourceNameFromSelfLink(obj["name"].(string)) + // Only sweep resources with the test prefix + if !strings.HasPrefix(name, "tf-test") { + nonPrefixCount++ + continue + } + + deleteTemplate := "https://vpcaccess.googleapis.com/v1/projects/{{project}}/locations/{{region}}/connectors/{{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, 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 without tf_test prefix remain.", nonPrefixCount) + } + + return nil +} diff --git a/google/vpc_access_operation.go b/google/vpc_access_operation.go new file mode 100644 index 00000000000..56d5646048b --- /dev/null +++ b/google/vpc_access_operation.go @@ -0,0 +1,71 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 ( + "encoding/json" + "fmt" +) + +type VPCAccessOperationWaiter struct { + Config *Config + Project string + CommonOperationWaiter +} + +func (w *VPCAccessOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } + // Returns the proper get. + url := fmt.Sprintf("https://vpcaccess.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name) + return sendRequest(w.Config, "GET", w.Project, url, nil) +} + +func createVPCAccessWaiter(config *Config, op map[string]interface{}, project, activity string) (*VPCAccessOperationWaiter, error) { + if val, ok := op["name"]; !ok || val == "" { + // This was a synchronous call - there is no operation to wait for. + return nil, nil + } + w := &VPCAccessOperationWaiter{ + Config: config, + Project: project, + } + if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func vpcAccessOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createVPCAccessWaiter(config, op, project, activity) + if err != nil || w == nil { + // If w is nil, the op was synchronous. + return err + } + if err := OperationWait(w, activity, timeoutMinutes); err != nil { + return err + } + return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response) +} + +func vpcAccessOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createVPCAccessWaiter(config, op, project, activity) + if err != nil || w == nil { + // If w is nil, the op was synchronous. + return err + } + return OperationWait(w, activity, timeoutMinutes) +} diff --git a/website/docs/r/vpc_access_connector.html.markdown b/website/docs/r/vpc_access_connector.html.markdown new file mode 100644 index 00000000000..98d7b15aab6 --- /dev/null +++ b/website/docs/r/vpc_access_connector.html.markdown @@ -0,0 +1,125 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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: "Serverless VPC Access" +layout: "google" +page_title: "Google: google_vpc_access_connector" +sidebar_current: "docs-google-vpc-access-connector" +description: |- + Serverless VPC Access connector resource. +--- + +# google\_vpc\_access\_connector + +Serverless VPC Access connector resource. + + +To get more information about Connector, see: + +* [API documentation](https://cloud.google.com/vpc/docs/reference/vpcaccess/rest/v1/projects.locations.connectors) +* How-to Guides + * [Configuring Serverless VPC Access](https://cloud.google.com/vpc/docs/configure-serverless-vpc-access) + + +## Example Usage - VPC Access Connector + + +```hcl +resource "google_vpc_access_connector" "connector" { + name = "vpcconn" + region = "us-central1" + ip_cidr_range = "10.8.0.0/28" + network = "default" +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `name` - + (Required) + The name of the resource (Max 25 characters). + +* `network` - + (Required) + Name of a VPC network. + +* `ip_cidr_range` - + (Required) + The range of internal addresses that follows RFC 4632 notation. Example: `10.132.0.0/28`. + +* `region` - + (Required) + Region where the VPC Access connector resides + + +- - - + + +* `min_throughput` - + (Optional) + Minimum throughput of the connector in Mbps. Default and min is 200. + +* `max_throughput` - + (Optional) + Maximum throughput of the connector in Mbps, must be greater than `min_throughput`. Default is 1000. + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `projects/{{project}}/locations/{{region}}/connectors/{{name}}` + +* `state` - + State of the VPC access connector. + +* `self_link` - + The fully qualified name of this VPC connector + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 6 minutes. +- `delete` - Default is 10 minutes. + +## Import + +Connector can be imported using any of these accepted formats: + +``` +$ terraform import google_vpc_access_connector.default projects/{{project}}/locations/{{region}}/connectors/{{name}} +$ terraform import google_vpc_access_connector.default {{project}}/{{region}}/{{name}} +$ terraform import google_vpc_access_connector.default {{region}}/{{name}} +$ terraform import google_vpc_access_connector.default {{name}} +``` + +-> If you're importing a resource with beta features, make sure to include `-provider=google-beta` +as an argument so that Terraform uses the correct provider to import your resource. + +## User Project Overrides + +This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).