From 03d11221a2aaf0bc8d99b2062d9a6f9c48a8f197 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 14 Jun 2019 11:45:47 -0700 Subject: [PATCH] Enable network endpoint groups and endpoints in GA (#3832) Signed-off-by: Modular Magician --- google/provider_compute_gen.go | 2 + google/resource_compute_network_endpoint.go | 406 ++++++++++++++++++ ...resource_compute_network_endpoint_group.go | 384 +++++++++++++++++ ...e_network_endpoint_group_generated_test.go | 98 +++++ .../resource_compute_network_endpoint_test.go | 248 ++++++++++- .../r/compute_network_endpoint.html.markdown | 150 +++++++ ...mpute_network_endpoint_group.html.markdown | 153 +++++++ 7 files changed, 1440 insertions(+), 1 deletion(-) create mode 100644 google/resource_compute_network_endpoint.go create mode 100644 google/resource_compute_network_endpoint_group.go create mode 100644 google/resource_compute_network_endpoint_group_generated_test.go create mode 100644 website/docs/r/compute_network_endpoint.html.markdown create mode 100644 website/docs/r/compute_network_endpoint_group.html.markdown diff --git a/google/provider_compute_gen.go b/google/provider_compute_gen.go index fc39707ab58..f3f5f2b2c81 100644 --- a/google/provider_compute_gen.go +++ b/google/provider_compute_gen.go @@ -48,6 +48,8 @@ var GeneratedComputeResourcesMap = map[string]*schema.Resource{ "google_compute_image": resourceComputeImage(), "google_compute_interconnect_attachment": resourceComputeInterconnectAttachment(), "google_compute_network": resourceComputeNetwork(), + "google_compute_network_endpoint": resourceComputeNetworkEndpoint(), + "google_compute_network_endpoint_group": resourceComputeNetworkEndpointGroup(), "google_compute_node_group": resourceComputeNodeGroup(), "google_compute_node_template": resourceComputeNodeTemplate(), "google_compute_region_autoscaler": resourceComputeRegionAutoscaler(), diff --git a/google/resource_compute_network_endpoint.go b/google/resource_compute_network_endpoint.go new file mode 100644 index 00000000000..6a8174aeeea --- /dev/null +++ b/google/resource_compute_network_endpoint.go @@ -0,0 +1,406 @@ +// ---------------------------------------------------------------------------- +// +// *** 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" + "time" + + "github.com/hashicorp/terraform/helper/schema" + "google.golang.org/api/compute/v1" +) + +func resourceComputeNetworkEndpoint() *schema.Resource { + return &schema.Resource{ + Create: resourceComputeNetworkEndpointCreate, + Read: resourceComputeNetworkEndpointRead, + Delete: resourceComputeNetworkEndpointDelete, + + Importer: &schema.ResourceImporter{ + State: resourceComputeNetworkEndpointImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(240 * time.Second), + Delete: schema.DefaultTimeout(240 * time.Second), + }, + + Schema: map[string]*schema.Schema{ + "instance": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "ip_address": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "network_endpoint_group": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "port": { + Type: schema.TypeInt, + Required: true, + ForceNew: true, + }, + "zone": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + } +} + +func resourceComputeNetworkEndpointCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + instanceProp, err := expandComputeNetworkEndpointInstance(d.Get("instance"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("instance"); !isEmptyValue(reflect.ValueOf(instanceProp)) && (ok || !reflect.DeepEqual(v, instanceProp)) { + obj["instance"] = instanceProp + } + portProp, err := expandComputeNetworkEndpointPort(d.Get("port"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("port"); !isEmptyValue(reflect.ValueOf(portProp)) && (ok || !reflect.DeepEqual(v, portProp)) { + obj["port"] = portProp + } + ipAddressProp, err := expandComputeNetworkEndpointIpAddress(d.Get("ip_address"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("ip_address"); !isEmptyValue(reflect.ValueOf(ipAddressProp)) && (ok || !reflect.DeepEqual(v, ipAddressProp)) { + obj["ipAddress"] = ipAddressProp + } + + obj, err = resourceComputeNetworkEndpointEncoder(d, meta, obj) + if err != nil { + return err + } + + lockName, err := replaceVars(d, config, "networkEndpoint/{{project}}/{{zone}}/{{network_endpoint_group}}") + if err != nil { + return err + } + mutexKV.Lock(lockName) + defer mutexKV.Unlock(lockName) + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}/attachNetworkEndpoints") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new NetworkEndpoint: %#v", obj) + res, err := sendRequestWithTimeout(config, "POST", url, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating NetworkEndpoint: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{project}}/{{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} + err = Convert(res, op) + if err != nil { + return err + } + + waitErr := computeOperationWaitTime( + config.clientCompute, op, project, "Creating NetworkEndpoint", + int(d.Timeout(schema.TimeoutCreate).Minutes())) + + if waitErr != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create NetworkEndpoint: %s", waitErr) + } + + log.Printf("[DEBUG] Finished creating NetworkEndpoint %q: %#v", d.Id(), res) + + return resourceComputeNetworkEndpointRead(d, meta) +} + +func resourceComputeNetworkEndpointRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}/listNetworkEndpoints") + if err != nil { + return err + } + + res, err := sendRequest(config, "POST", url, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("ComputeNetworkEndpoint %q", d.Id())) + } + + res, err = flattenNestedComputeNetworkEndpoint(d, meta, res) + if err != nil { + return err + } + + if res == nil { + // Object isn't there any more - remove it from the state. + log.Printf("[DEBUG] Removing ComputeNetworkEndpoint because it couldn't be matched.") + d.SetId("") + return nil + } + + res, err = resourceComputeNetworkEndpointDecoder(d, meta, res) + if err != nil { + return err + } + + project, err := getProject(d, config) + if err != nil { + return err + } + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading NetworkEndpoint: %s", err) + } + + if err := d.Set("instance", flattenComputeNetworkEndpointInstance(res["instance"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpoint: %s", err) + } + if err := d.Set("port", flattenComputeNetworkEndpointPort(res["port"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpoint: %s", err) + } + if err := d.Set("ip_address", flattenComputeNetworkEndpointIpAddress(res["ipAddress"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpoint: %s", err) + } + + return nil +} + +func resourceComputeNetworkEndpointDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + lockName, err := replaceVars(d, config, "networkEndpoint/{{project}}/{{zone}}/{{network_endpoint_group}}") + if err != nil { + return err + } + mutexKV.Lock(lockName) + defer mutexKV.Unlock(lockName) + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}/detachNetworkEndpoints") + if err != nil { + return err + } + + var obj map[string]interface{} + toDelete := make(map[string]interface{}) + instanceProp, err := expandComputeNetworkEndpointInstance(d.Get("instance"), d, config) + if err != nil { + return err + } + toDelete["instance"] = instanceProp + + portProp, err := expandComputeNetworkEndpointPort(d.Get("port"), d, config) + if err != nil { + return err + } + toDelete["port"] = portProp + + ipAddressProp, err := expandComputeNetworkEndpointIpAddress(d.Get("ip_address"), d, config) + if err != nil { + return err + } + toDelete["ipAddress"] = ipAddressProp + + obj = map[string]interface{}{ + "networkEndpoints": []map[string]interface{}{toDelete}, + } + log.Printf("[DEBUG] Deleting NetworkEndpoint %q", d.Id()) + res, err := sendRequestWithTimeout(config, "POST", url, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "NetworkEndpoint") + } + + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} + err = Convert(res, op) + if err != nil { + return err + } + + err = computeOperationWaitTime( + config.clientCompute, op, project, "Deleting NetworkEndpoint", + int(d.Timeout(schema.TimeoutDelete).Minutes())) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting NetworkEndpoint %q: %#v", d.Id(), res) + return nil +} + +func resourceComputeNetworkEndpointImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if err := parseImportId([]string{"projects/(?P[^/]+)/zones/(?P[^/]+)/networkEndpointGroups/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/(?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, "{{project}}/{{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenComputeNetworkEndpointInstance(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return ConvertSelfLinkToV1(v.(string)) +} + +func flattenComputeNetworkEndpointPort(v interface{}, d *schema.ResourceData) interface{} { + // Handles int given in float64 format + if floatVal, ok := v.(float64); ok { + return int(floatVal) + } + return v +} + +func flattenComputeNetworkEndpointIpAddress(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func expandComputeNetworkEndpointInstance(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return GetResourceNameFromSelfLink(v.(string)), nil +} + +func expandComputeNetworkEndpointPort(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeNetworkEndpointIpAddress(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func resourceComputeNetworkEndpointEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { + wrappedReq := map[string]interface{}{ + "networkEndpoints": []interface{}{obj}, + } + return wrappedReq, nil +} + +func flattenNestedComputeNetworkEndpoint(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { + var v interface{} + var ok bool + + v, ok = res["items"] + if !ok || v == nil { + return nil, nil + } + + switch v.(type) { + case []interface{}: + break + case map[string]interface{}: + // Construct list out of single nested resource + v = []interface{}{v} + default: + return nil, fmt.Errorf("expected list or map for value items. Actual value: %v", v) + } + + expectedInstance, err := expandComputeNetworkEndpointInstance(d.Get("instance"), d, meta.(*Config)) + if err != nil { + return nil, err + } + expectedPort, err := expandComputeNetworkEndpointPort(d.Get("port"), d, meta.(*Config)) + if err != nil { + return nil, err + } + expectedIpAddress, err := expandComputeNetworkEndpointIpAddress(d.Get("ip_address"), d, meta.(*Config)) + if err != nil { + return nil, err + } + + // Search list for this resource. + items := v.([]interface{}) + for _, itemRaw := range items { + if itemRaw == nil { + continue + } + item := itemRaw.(map[string]interface{}) + + // Decode list item before comparing. + item, err := resourceComputeNetworkEndpointDecoder(d, meta, item) + if err != nil { + return nil, err + } + + itemInstance := flattenComputeNetworkEndpointInstance(item["instance"], d) + if !reflect.DeepEqual(itemInstance, expectedInstance) { + log.Printf("[DEBUG] Skipping item with instance= %#v, looking for %#v)", itemInstance, expectedInstance) + continue + } + itemPort := flattenComputeNetworkEndpointPort(item["port"], d) + if !reflect.DeepEqual(itemPort, expectedPort) { + log.Printf("[DEBUG] Skipping item with port= %#v, looking for %#v)", itemPort, expectedPort) + continue + } + itemIpAddress := flattenComputeNetworkEndpointIpAddress(item["ipAddress"], d) + if !reflect.DeepEqual(itemIpAddress, expectedIpAddress) { + log.Printf("[DEBUG] Skipping item with ipAddress= %#v, looking for %#v)", itemIpAddress, expectedIpAddress) + continue + } + log.Printf("[DEBUG] Found item for resource %q: %#v)", d.Id(), item) + return item, nil + } + + return nil, nil +} + +func resourceComputeNetworkEndpointDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { + v, ok := res["networkEndpoint"] + if !ok || v == nil { + return res, nil + } + + return v.(map[string]interface{}), nil +} diff --git a/google/resource_compute_network_endpoint_group.go b/google/resource_compute_network_endpoint_group.go new file mode 100644 index 00000000000..69d42eb6006 --- /dev/null +++ b/google/resource_compute_network_endpoint_group.go @@ -0,0 +1,384 @@ +// ---------------------------------------------------------------------------- +// +// *** 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/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "google.golang.org/api/compute/v1" +) + +func resourceComputeNetworkEndpointGroup() *schema.Resource { + return &schema.Resource{ + Create: resourceComputeNetworkEndpointGroupCreate, + Read: resourceComputeNetworkEndpointGroupRead, + Delete: resourceComputeNetworkEndpointGroupDelete, + + Importer: &schema.ResourceImporter{ + State: resourceComputeNetworkEndpointGroupImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(240 * time.Second), + Delete: schema.DefaultTimeout(240 * time.Second), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateGCPName, + }, + "network": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "default_port": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "network_endpoint_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"GCE_VM_IP_PORT", ""}, false), + Default: "GCE_VM_IP_PORT", + }, + "subnetwork": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "zone": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "size": { + Type: schema.TypeInt, + Computed: true, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + } +} + +func resourceComputeNetworkEndpointGroupCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + nameProp, err := expandComputeNetworkEndpointGroupName(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 + } + descriptionProp, err := expandComputeNetworkEndpointGroupDescription(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 + } + networkEndpointTypeProp, err := expandComputeNetworkEndpointGroupNetworkEndpointType(d.Get("network_endpoint_type"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("network_endpoint_type"); !isEmptyValue(reflect.ValueOf(networkEndpointTypeProp)) && (ok || !reflect.DeepEqual(v, networkEndpointTypeProp)) { + obj["networkEndpointType"] = networkEndpointTypeProp + } + networkProp, err := expandComputeNetworkEndpointGroupNetwork(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 + } + subnetworkProp, err := expandComputeNetworkEndpointGroupSubnetwork(d.Get("subnetwork"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("subnetwork"); !isEmptyValue(reflect.ValueOf(subnetworkProp)) && (ok || !reflect.DeepEqual(v, subnetworkProp)) { + obj["subnetwork"] = subnetworkProp + } + defaultPortProp, err := expandComputeNetworkEndpointGroupDefaultPort(d.Get("default_port"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("default_port"); !isEmptyValue(reflect.ValueOf(defaultPortProp)) && (ok || !reflect.DeepEqual(v, defaultPortProp)) { + obj["defaultPort"] = defaultPortProp + } + zoneProp, err := expandComputeNetworkEndpointGroupZone(d.Get("zone"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("zone"); !isEmptyValue(reflect.ValueOf(zoneProp)) && (ok || !reflect.DeepEqual(v, zoneProp)) { + obj["zone"] = zoneProp + } + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/networkEndpointGroups") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new NetworkEndpointGroup: %#v", obj) + res, err := sendRequestWithTimeout(config, "POST", url, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating NetworkEndpointGroup: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} + err = Convert(res, op) + if err != nil { + return err + } + + waitErr := computeOperationWaitTime( + config.clientCompute, op, project, "Creating NetworkEndpointGroup", + int(d.Timeout(schema.TimeoutCreate).Minutes())) + + if waitErr != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create NetworkEndpointGroup: %s", waitErr) + } + + log.Printf("[DEBUG] Finished creating NetworkEndpointGroup %q: %#v", d.Id(), res) + + return resourceComputeNetworkEndpointGroupRead(d, meta) +} + +func resourceComputeNetworkEndpointGroupRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}}") + if err != nil { + return err + } + + res, err := sendRequest(config, "GET", url, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("ComputeNetworkEndpointGroup %q", d.Id())) + } + + project, err := getProject(d, config) + if err != nil { + return err + } + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) + } + + if err := d.Set("name", flattenComputeNetworkEndpointGroupName(res["name"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) + } + if err := d.Set("description", flattenComputeNetworkEndpointGroupDescription(res["description"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) + } + if err := d.Set("network_endpoint_type", flattenComputeNetworkEndpointGroupNetworkEndpointType(res["networkEndpointType"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) + } + if err := d.Set("size", flattenComputeNetworkEndpointGroupSize(res["size"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) + } + if err := d.Set("network", flattenComputeNetworkEndpointGroupNetwork(res["network"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) + } + if err := d.Set("subnetwork", flattenComputeNetworkEndpointGroupSubnetwork(res["subnetwork"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) + } + if err := d.Set("default_port", flattenComputeNetworkEndpointGroupDefaultPort(res["defaultPort"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) + } + if err := d.Set("zone", flattenComputeNetworkEndpointGroupZone(res["zone"], d)); err != nil { + return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) + } + + return nil +} + +func resourceComputeNetworkEndpointGroupDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting NetworkEndpointGroup %q", d.Id()) + res, err := sendRequestWithTimeout(config, "DELETE", url, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "NetworkEndpointGroup") + } + + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} + err = Convert(res, op) + if err != nil { + return err + } + + err = computeOperationWaitTime( + config.clientCompute, op, project, "Deleting NetworkEndpointGroup", + int(d.Timeout(schema.TimeoutDelete).Minutes())) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting NetworkEndpointGroup %q: %#v", d.Id(), res) + return nil +} + +func resourceComputeNetworkEndpointGroupImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if err := parseImportId([]string{"projects/(?P[^/]+)/zones/(?P[^/]+)/networkEndpointGroups/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config); err != nil { + return nil, err + } + + // 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 flattenComputeNetworkEndpointGroupName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeNetworkEndpointGroupDescription(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeNetworkEndpointGroupNetworkEndpointType(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeNetworkEndpointGroupSize(v interface{}, d *schema.ResourceData) 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 flattenComputeNetworkEndpointGroupNetwork(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return ConvertSelfLinkToV1(v.(string)) +} + +func flattenComputeNetworkEndpointGroupSubnetwork(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return ConvertSelfLinkToV1(v.(string)) +} + +func flattenComputeNetworkEndpointGroupDefaultPort(v interface{}, d *schema.ResourceData) 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 flattenComputeNetworkEndpointGroupZone(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return ConvertSelfLinkToV1(v.(string)) +} + +func expandComputeNetworkEndpointGroupName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeNetworkEndpointGroupDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeNetworkEndpointGroupNetworkEndpointType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeNetworkEndpointGroupNetwork(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseGlobalFieldValue("networks", v.(string), "project", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for network: %s", err) + } + return f.RelativeLink(), nil +} + +func expandComputeNetworkEndpointGroupSubnetwork(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseRegionalFieldValue("subnetworks", v.(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for subnetwork: %s", err) + } + return f.RelativeLink(), nil +} + +func expandComputeNetworkEndpointGroupDefaultPort(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeNetworkEndpointGroupZone(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseGlobalFieldValue("zones", v.(string), "project", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for zone: %s", err) + } + return f.RelativeLink(), nil +} diff --git a/google/resource_compute_network_endpoint_group_generated_test.go b/google/resource_compute_network_endpoint_group_generated_test.go new file mode 100644 index 00000000000..bfb34b3af6f --- /dev/null +++ b/google/resource_compute_network_endpoint_group_generated_test.go @@ -0,0 +1,98 @@ +// ---------------------------------------------------------------------------- +// +// *** 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/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccComputeNetworkEndpointGroup_networkEndpointGroupExample(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: testAccCheckComputeNetworkEndpointGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeNetworkEndpointGroup_networkEndpointGroupExample(context), + }, + { + ResourceName: "google_compute_network_endpoint_group.neg", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeNetworkEndpointGroup_networkEndpointGroupExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_network_endpoint_group" "neg" { + name = "my-lb-neg-%{random_suffix}" + network = "${google_compute_network.default.self_link}" + subnetwork = "${google_compute_subnetwork.default.self_link}" + default_port = "90" + zone = "us-central1-a" +} + +resource "google_compute_network" "default" { + name = "neg-network-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "default" { + name = "neg-subnetwork-%{random_suffix}" + ip_cidr_range = "10.0.0.0/16" + region = "us-central1" + network = "${google_compute_network.default.self_link}" +} +`, context) +} + +func testAccCheckComputeNetworkEndpointGroupDestroy(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_compute_network_endpoint_group" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := testAccProvider.Meta().(*Config) + + url, err := replaceVarsForTest(rs, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}}") + if err != nil { + return err + } + + _, err = sendRequest(config, "GET", url, nil) + if err == nil { + return fmt.Errorf("ComputeNetworkEndpointGroup still exists at %s", url) + } + } + + return nil +} diff --git a/google/resource_compute_network_endpoint_test.go b/google/resource_compute_network_endpoint_test.go index 93cfad7a2a0..d35fec4aef3 100644 --- a/google/resource_compute_network_endpoint_test.go +++ b/google/resource_compute_network_endpoint_test.go @@ -1,3 +1,249 @@ package google -// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now. +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccComputeNetworkEndpoint_networkEndpointsBasic(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + "default_port": 90, + "modified_port": 100, + "add1_port": 101, + "add2_port": 102, + } + negId := fmt.Sprintf("projects/%s/zones/%s/networkEndpointGroups/neg-%s", + getTestProjectFromEnv(), getTestZoneFromEnv(), context["random_suffix"]) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + // Create one endpoint + Config: testAccComputeNetworkEndpoint_networkEndpointsBasic(context), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeNetworkEndpointWithPortExists("google_compute_network_endpoint.default", "90"), + ), + }, + { + ResourceName: "google_compute_network_endpoint.default", + ImportState: true, + ImportStateVerify: true, + }, + { + // Force-recreate old endpoint + Config: testAccComputeNetworkEndpoint_networkEndpointsModified(context), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeNetworkEndpointWithPortExists("google_compute_network_endpoint.default", "100"), + testAccCheckComputeNetworkEndpointWithPortsDestroyed(negId, "90"), + ), + }, + { + // Add two new endpoints + Config: testAccComputeNetworkEndpoint_networkEndpointsAdditional(context), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeNetworkEndpointWithPortExists("google_compute_network_endpoint.default", "100"), + testAccCheckComputeNetworkEndpointWithPortExists("google_compute_network_endpoint.add1", "101"), + testAccCheckComputeNetworkEndpointWithPortExists("google_compute_network_endpoint.add2", "102"), + ), + }, + { + // delete all endpoints + Config: testAccComputeNetworkEndpoint_noNetworkEndpoints(context), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeNetworkEndpointWithPortsDestroyed(negId, "100"), + ), + }, + }, + }) +} + +func testAccComputeNetworkEndpoint_networkEndpointsBasic(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_network_endpoint" "default" { + zone = "us-central1-a" + network_endpoint_group = "${google_compute_network_endpoint_group.neg.name}" + + instance = "${google_compute_instance.default.name}" + ip_address = "${google_compute_instance.default.network_interface.0.network_ip}" + port = "${google_compute_network_endpoint_group.neg.default_port}" +} +`, context) + testAccComputeNetworkEndpoint_noNetworkEndpoints(context) +} + +func testAccComputeNetworkEndpoint_networkEndpointsModified(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_network_endpoint" "default" { + zone = "us-central1-a" + network_endpoint_group = "${google_compute_network_endpoint_group.neg.name}" + + instance = "${google_compute_instance.default.name}" + ip_address = "${google_compute_instance.default.network_interface.0.network_ip}" + port = "%{modified_port}" +}`, context) + testAccComputeNetworkEndpoint_noNetworkEndpoints(context) +} + +func testAccComputeNetworkEndpoint_networkEndpointsAdditional(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_network_endpoint" "default" { + zone = "us-central1-a" + network_endpoint_group = "${google_compute_network_endpoint_group.neg.name}" + + instance = "${google_compute_instance.default.name}" + ip_address = "${google_compute_instance.default.network_interface.0.network_ip}" + port = "%{modified_port}" +} + +resource "google_compute_network_endpoint" "add1" { + zone = "us-central1-a" + network_endpoint_group = "${google_compute_network_endpoint_group.neg.name}" + + instance = "${google_compute_instance.default.name}" + ip_address = "${google_compute_instance.default.network_interface.0.network_ip}" + port = "%{add1_port}" +} + +resource "google_compute_network_endpoint" "add2" { + zone = "us-central1-a" + network_endpoint_group = "${google_compute_network_endpoint_group.neg.name}" + + instance = "${google_compute_instance.default.name}" + ip_address = "${google_compute_instance.default.network_interface.0.network_ip}" + port = "%{add2_port}" +} + +`, context) + testAccComputeNetworkEndpoint_noNetworkEndpoints(context) +} + +func testAccComputeNetworkEndpoint_noNetworkEndpoints(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_network_endpoint_group" "neg" { + name = "neg-%{random_suffix}" + zone = "us-central1-a" + network = "${google_compute_network.default.self_link}" + subnetwork = "${google_compute_subnetwork.default.self_link}" + default_port = "%{default_port}" +} + +resource "google_compute_network" "default" { + name = "neg-network-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "default" { + name = "neg-subnetwork-%{random_suffix}" + ip_cidr_range = "10.0.0.0/16" + region = "us-central1" + network = "${google_compute_network.default.self_link}" +} + +resource "google_compute_instance" "default" { + name = "neg-instance1-%{random_suffix}" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params{ + image = "${data.google_compute_image.my_image.self_link}" + } + } + + network_interface { + subnetwork = "${google_compute_subnetwork.default.self_link}" + access_config { } + } +} + +data "google_compute_image" "my_image" { + family = "debian-9" + project = "debian-cloud" +} +`, context) +} + +// testAccCheckComputeNetworkEndpointExists makes sure the resource with given +// (Terraform) name exists, and returns identifying information about the +// existing endpoint +func testAccCheckComputeNetworkEndpointWithPortExists(name, port string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("resource %q not in path %q", name, s.RootModule().Path) + } + + if rs.Type != "google_compute_network_endpoint" { + return fmt.Errorf("resource %q has unexpected type %q", name, rs.Type) + } + + if rs.Primary.Attributes["port"] != port { + return fmt.Errorf("unexpected port %s for resource %s, expected %s", rs.Primary.Attributes["port"], name, port) + } + + negResourceId, err := replaceVarsForTest(rs, "projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}") + if err != nil { + return fmt.Errorf("creating URL for getting network endpoint %q failed: %v", name, err) + } + + foundPorts, err := testAccComputeNetworkEndpointsListEndpointPorts(negResourceId) + if err != nil { + return fmt.Errorf("unable to confirm endpoints with port %s exists: %v", port, err) + } + if _, ok := foundPorts[port]; !ok { + return fmt.Errorf("did not find endpoint with port %s", port) + } + return nil + } +} + +// testAccCheckComputeNetworkEndpointDestroyed makes sure the endpoint with +// given Terraform resource name and previous information (obtained from Exists) +// was destroyed properly. +func testAccCheckComputeNetworkEndpointWithPortsDestroyed(negId string, ports ...string) resource.TestCheckFunc { + return func(s *terraform.State) error { + foundPorts, err := testAccComputeNetworkEndpointsListEndpointPorts(negId) + if err != nil { + return fmt.Errorf("unable to confirm endpoints with ports %+v was destroyed: %v", ports, err) + } + for _, p := range ports { + if _, ok := foundPorts[p]; ok { + return fmt.Errorf("network endpoint with port %s still exists", p) + } + } + + return nil + } +} + +func testAccComputeNetworkEndpointsListEndpointPorts(negId string) (map[string]struct{}, error) { + config := testAccProvider.Meta().(*Config) + + url := fmt.Sprintf("https://www.googleapis.com/compute/beta/%s/listNetworkEndpoints", negId) + res, err := sendRequest(config, "POST", url, nil) + if err != nil { + return nil, err + } + + v, ok := res["items"] + if !ok || v == nil { + return nil, nil + } + items := v.([]interface{}) + ports := make(map[string]struct{}) + for _, item := range items { + endptWithHealth := item.(map[string]interface{}) + v, ok := endptWithHealth["networkEndpoint"] + if !ok || v == nil { + continue + } + endpt := v.(map[string]interface{}) + ports[fmt.Sprintf("%v", endpt["port"])] = struct{}{} + } + return ports, nil +} diff --git a/website/docs/r/compute_network_endpoint.html.markdown b/website/docs/r/compute_network_endpoint.html.markdown new file mode 100644 index 00000000000..ccd287c4c56 --- /dev/null +++ b/website/docs/r/compute_network_endpoint.html.markdown @@ -0,0 +1,150 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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. +# +# ---------------------------------------------------------------------------- +layout: "google" +page_title: "Google: google_compute_network_endpoint" +sidebar_current: "docs-google-compute-network-endpoint" +description: |- + A Network endpoint represents a IP address and port combination that is + part of a specific network endpoint group (NEG). +--- + +# google\_compute\_network\_endpoint + +A Network endpoint represents a IP address and port combination that is +part of a specific network endpoint group (NEG). NEGs are zonals +collection of these endpoints for GCP resources within a +single subnet. **NOTE**: Network endpoints cannot be created outside of a +network endpoint group. + + +To get more information about NetworkEndpoint, see: + +* [API documentation](https://cloud.google.com/compute/docs/reference/rest/beta/networkEndpointGroups) +* How-to Guides + * [Official Documentation](https://cloud.google.com/load-balancing/docs/negs/) + +## Example Usage - Network Endpoint + + +```hcl +resource "google_compute_network_endpoint" "default-endpoint { + network_endpoint_group = "${google_compute_network_endpoint_group.neg.name}" + + instance = "${google_compute_instance.endpoint-instance.name}" + port = "${google_compute_network_endpoint_group.neg.default_port}" + ip_address = "${google_compute_instance.endpoint-instance.network_interface.0.network_ip}" +} + +data "google_compute_image" "my_image" { + family = "debian-9" + project = "debian-cloud" +} + +resource "google_compute_instance" "endpoint-instance" { + name = "endpoint-instance" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params{ + image = "${data.google_compute_image.my_image.self_link}" + } + } + + network_interface { + subnetwork = "${google_compute_subnetwork.default.self_link}" + access_config { } + } +} + +resource "google_compute_network_endpoint_group" "group" { + name = "my-lb-neg" + network = "${google_compute_network.default.self_link}" + subnetwork = "${google_compute_subnetwork.default.self_link}" + default_port = "90" + zone = "us-central1-a" +} + +resource "google_compute_network" "default" { + name = "neg-network" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "default" { + name = "neg-subnetwork" + ip_cidr_range = "10.0.0.1/16" + region = "us-central1" + network = "${google_compute_network.default.self_link}" +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `instance` - + (Required) + The name for a specific VM instance that the IP address belongs to. + This is required for network endpoints of type GCE_VM_IP_PORT. + The instance must be in the same zone of network endpoint group. + +* `port` - + (Required) + Port number of network endpoint. + +* `ip_address` - + (Required) + IPv4 address of network endpoint. The IP address must belong + to a VM in GCE (either the primary IP or as part of an aliased IP + range). + +* `network_endpoint_group` - + (Required) + The network endpoint group this endpoint is part of. + + +- - - + + +* `zone` - + (Optional) + Zone where the containing network endpoint group is located. + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 4 minutes. +- `delete` - Default is 4 minutes. + +## Import + +NetworkEndpoint can be imported using any of these accepted formats: + +``` +$ terraform import google_compute_network_endpoint.default projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}/{{name}} +$ terraform import google_compute_network_endpoint.default {{project}}/{{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}} +$ terraform import google_compute_network_endpoint.default {{project}}/{{zone}}/{{network_endpoint_group}}/{{name}} +$ terraform import google_compute_network_endpoint.default {{network_endpoint_group}}/{{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. diff --git a/website/docs/r/compute_network_endpoint_group.html.markdown b/website/docs/r/compute_network_endpoint_group.html.markdown new file mode 100644 index 00000000000..fb33505dcfe --- /dev/null +++ b/website/docs/r/compute_network_endpoint_group.html.markdown @@ -0,0 +1,153 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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. +# +# ---------------------------------------------------------------------------- +layout: "google" +page_title: "Google: google_compute_network_endpoint_group" +sidebar_current: "docs-google-compute-network-endpoint-group" +description: |- + Network endpoint groups (NEGs) are zonal resources that represent + collections of IP address and port combinations for GCP resources within a + single subnet. +--- + +# google\_compute\_network\_endpoint\_group + +Network endpoint groups (NEGs) are zonal resources that represent +collections of IP address and port combinations for GCP resources within a +single subnet. Each IP address and port combination is called a network +endpoint. + +Network endpoint groups can be used as backends in backend services for +HTTP(S), TCP proxy, and SSL proxy load balancers. You cannot use NEGs as a +backend with internal load balancers. Because NEG backends allow you to +specify IP addresses and ports, you can distribute traffic in a granular +fashion among applications or containers running within VM instances. + + +To get more information about NetworkEndpointGroup, see: + +* [API documentation](https://cloud.google.com/compute/docs/reference/rest/beta/networkEndpointGroups) +* How-to Guides + * [Official Documentation](https://cloud.google.com/load-balancing/docs/negs/) + + +## Example Usage - Network Endpoint Group + + +```hcl +resource "google_compute_network_endpoint_group" "neg" { + name = "my-lb-neg" + network = "${google_compute_network.default.self_link}" + subnetwork = "${google_compute_subnetwork.default.self_link}" + default_port = "90" + zone = "us-central1-a" +} + +resource "google_compute_network" "default" { + name = "neg-network" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "default" { + name = "neg-subnetwork" + ip_cidr_range = "10.0.0.0/16" + region = "us-central1" + network = "${google_compute_network.default.self_link}" +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `name` - + (Required) + Name of the resource; provided by the client when the resource is + created. The name must be 1-63 characters long, and comply with + RFC1035. Specifically, the name must be 1-63 characters long and match + the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the + first character must be a lowercase letter, and all following + characters must be a dash, lowercase letter, or digit, except the last + character, which cannot be a dash. + +* `network` - + (Required) + The network to which all network endpoints in the NEG belong. + Uses "default" project network if unspecified. + + +- - - + + +* `description` - + (Optional) + An optional description of this resource. Provide this property when + you create the resource. + +* `network_endpoint_type` - + (Optional) + Type of network endpoints in this network endpoint group. Currently + the only supported value is GCE_VM_IP_PORT. + +* `subnetwork` - + (Optional) + Optional subnetwork to which all network endpoints in the NEG belong. + +* `default_port` - + (Optional) + The default port used if the port number is not specified in the + network endpoint. + +* `zone` - + (Optional) + Zone where the network endpoint group is located. + +* `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: + + +* `size` - + Number of network endpoints in the network endpoint group. + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 4 minutes. +- `delete` - Default is 4 minutes. + +## Import + +NetworkEndpointGroup can be imported using any of these accepted formats: + +``` +$ terraform import google_compute_network_endpoint_group.default projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}} +$ terraform import google_compute_network_endpoint_group.default {{project}}/{{zone}}/{{name}} +$ terraform import google_compute_network_endpoint_group.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.