diff --git a/google-beta/provider.go b/google-beta/provider.go index 5b3ca083250..466dc832c12 100644 --- a/google-beta/provider.go +++ b/google-beta/provider.go @@ -472,9 +472,9 @@ func Provider() terraform.ResourceProvider { return provider } -// Generated resources: 93 +// Generated resources: 94 // Generated IAM resources: 24 -// Total generated resources: 117 +// Total generated resources: 118 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -526,6 +526,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_compute_node_template": resourceComputeNodeTemplate(), "google_compute_region_autoscaler": resourceComputeRegionAutoscaler(), "google_compute_region_disk": resourceComputeRegionDisk(), + "google_compute_region_url_map": resourceComputeRegionUrlMap(), "google_compute_region_health_check": resourceComputeRegionHealthCheck(), "google_compute_resource_policy": resourceComputeResourcePolicy(), "google_compute_route": resourceComputeRoute(), diff --git a/google-beta/resource_compute_region_backend_service.go b/google-beta/resource_compute_region_backend_service.go index c7f486240e9..77bbd6477b0 100644 --- a/google-beta/resource_compute_region_backend_service.go +++ b/google-beta/resource_compute_region_backend_service.go @@ -114,7 +114,7 @@ func resourceComputeRegionBackendService() *schema.Resource { Type: schema.TypeString, Computed: true, Optional: true, - ValidateFunc: validation.StringInSlice([]string{"TCP", "UDP", ""}, false), + ValidateFunc: validation.StringInSlice([]string{"HTTP", "HTTPS", "HTTP2", "SSL", "TCP", "UDP", ""}, false), }, "region": { Type: schema.TypeString, diff --git a/google-beta/resource_compute_region_url_map.go b/google-beta/resource_compute_region_url_map.go new file mode 100644 index 00000000000..e599ffe43ce --- /dev/null +++ b/google-beta/resource_compute_region_url_map.go @@ -0,0 +1,913 @@ +// ---------------------------------------------------------------------------- +// +// *** 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" + "google.golang.org/api/compute/v1" +) + +func resourceComputeRegionUrlMap() *schema.Resource { + return &schema.Resource{ + Create: resourceComputeRegionUrlMapCreate, + Read: resourceComputeRegionUrlMapRead, + Update: resourceComputeRegionUrlMapUpdate, + Delete: resourceComputeRegionUrlMapDelete, + + Importer: &schema.ResourceImporter{ + State: resourceComputeRegionUrlMapImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(4 * time.Minute), + Update: schema.DefaultTimeout(4 * time.Minute), + Delete: schema.DefaultTimeout(4 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "default_service": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + "host_rule": { + Type: schema.TypeSet, + Optional: true, + Elem: computeRegionUrlMapHostRuleSchema(), + // Default schema.HashSchema is used. + }, + "path_matcher": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "default_service": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + "path_rule": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "paths": { + Type: schema.TypeSet, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Set: schema.HashString, + }, + "service": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + }, + }, + }, + }, + }, + }, + "region": { + Type: schema.TypeString, + Computed: true, + Optional: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "test": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "host": { + Type: schema.TypeString, + Required: true, + }, + "path": { + Type: schema.TypeString, + Required: true, + }, + "service": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "creation_timestamp": { + Type: schema.TypeString, + Computed: true, + }, + "fingerprint": { + Type: schema.TypeString, + Computed: true, + }, + "map_id": { + Type: schema.TypeInt, + Computed: true, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "self_link": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func computeRegionUrlMapHostRuleSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "hosts": { + Type: schema.TypeSet, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Set: schema.HashString, + }, + "path_matcher": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + }, + } +} + +func resourceComputeRegionUrlMapCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + defaultServiceProp, err := expandComputeRegionUrlMapDefaultService(d.Get("default_service"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("default_service"); !isEmptyValue(reflect.ValueOf(defaultServiceProp)) && (ok || !reflect.DeepEqual(v, defaultServiceProp)) { + obj["defaultService"] = defaultServiceProp + } + descriptionProp, err := expandComputeRegionUrlMapDescription(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 + } + hostRulesProp, err := expandComputeRegionUrlMapHostRule(d.Get("host_rule"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("host_rule"); !isEmptyValue(reflect.ValueOf(hostRulesProp)) && (ok || !reflect.DeepEqual(v, hostRulesProp)) { + obj["hostRules"] = hostRulesProp + } + fingerprintProp, err := expandComputeRegionUrlMapFingerprint(d.Get("fingerprint"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("fingerprint"); !isEmptyValue(reflect.ValueOf(fingerprintProp)) && (ok || !reflect.DeepEqual(v, fingerprintProp)) { + obj["fingerprint"] = fingerprintProp + } + nameProp, err := expandComputeRegionUrlMapName(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 + } + pathMatchersProp, err := expandComputeRegionUrlMapPathMatcher(d.Get("path_matcher"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("path_matcher"); !isEmptyValue(reflect.ValueOf(pathMatchersProp)) && (ok || !reflect.DeepEqual(v, pathMatchersProp)) { + obj["pathMatchers"] = pathMatchersProp + } + testsProp, err := expandComputeRegionUrlMapTest(d.Get("test"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("test"); !isEmptyValue(reflect.ValueOf(testsProp)) && (ok || !reflect.DeepEqual(v, testsProp)) { + obj["tests"] = testsProp + } + regionProp, err := expandComputeRegionUrlMapRegion(d.Get("region"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("region"); !isEmptyValue(reflect.ValueOf(regionProp)) && (ok || !reflect.DeepEqual(v, regionProp)) { + obj["region"] = regionProp + } + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/urlMaps") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new RegionUrlMap: %#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 RegionUrlMap: %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) + + op := &compute.Operation{} + err = Convert(res, op) + if err != nil { + return err + } + + waitErr := computeOperationWaitTime( + config.clientCompute, op, project, "Creating RegionUrlMap", + int(d.Timeout(schema.TimeoutCreate).Minutes())) + + if waitErr != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create RegionUrlMap: %s", waitErr) + } + + log.Printf("[DEBUG] Finished creating RegionUrlMap %q: %#v", d.Id(), res) + + return resourceComputeRegionUrlMapRead(d, meta) +} + +func resourceComputeRegionUrlMapRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/urlMaps/{{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("ComputeRegionUrlMap %q", d.Id())) + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + + if err := d.Set("creation_timestamp", flattenComputeRegionUrlMapCreationTimestamp(res["creationTimestamp"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("default_service", flattenComputeRegionUrlMapDefaultService(res["defaultService"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("description", flattenComputeRegionUrlMapDescription(res["description"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("host_rule", flattenComputeRegionUrlMapHostRule(res["hostRules"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("map_id", flattenComputeRegionUrlMapMapId(res["id"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("fingerprint", flattenComputeRegionUrlMapFingerprint(res["fingerprint"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("name", flattenComputeRegionUrlMapName(res["name"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("path_matcher", flattenComputeRegionUrlMapPathMatcher(res["pathMatchers"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("test", flattenComputeRegionUrlMapTest(res["tests"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("region", flattenComputeRegionUrlMapRegion(res["region"], d)); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil { + return fmt.Errorf("Error reading RegionUrlMap: %s", err) + } + + return nil +} + +func resourceComputeRegionUrlMapUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + defaultServiceProp, err := expandComputeRegionUrlMapDefaultService(d.Get("default_service"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("default_service"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultServiceProp)) { + obj["defaultService"] = defaultServiceProp + } + descriptionProp, err := expandComputeRegionUrlMapDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + hostRulesProp, err := expandComputeRegionUrlMapHostRule(d.Get("host_rule"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("host_rule"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, hostRulesProp)) { + obj["hostRules"] = hostRulesProp + } + fingerprintProp, err := expandComputeRegionUrlMapFingerprint(d.Get("fingerprint"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("fingerprint"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, fingerprintProp)) { + obj["fingerprint"] = fingerprintProp + } + nameProp, err := expandComputeRegionUrlMapName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } + pathMatchersProp, err := expandComputeRegionUrlMapPathMatcher(d.Get("path_matcher"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("path_matcher"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, pathMatchersProp)) { + obj["pathMatchers"] = pathMatchersProp + } + testsProp, err := expandComputeRegionUrlMapTest(d.Get("test"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("test"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, testsProp)) { + obj["tests"] = testsProp + } + regionProp, err := expandComputeRegionUrlMapRegion(d.Get("region"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("region"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, regionProp)) { + obj["region"] = regionProp + } + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/urlMaps/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating RegionUrlMap %q: %#v", d.Id(), obj) + res, err := sendRequestWithTimeout(config, "PUT", project, url, obj, d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return fmt.Errorf("Error updating RegionUrlMap %q: %s", d.Id(), err) + } + + op := &compute.Operation{} + err = Convert(res, op) + if err != nil { + return err + } + + err = computeOperationWaitTime( + config.clientCompute, op, project, "Updating RegionUrlMap", + int(d.Timeout(schema.TimeoutUpdate).Minutes())) + + if err != nil { + return err + } + + return resourceComputeRegionUrlMapRead(d, meta) +} + +func resourceComputeRegionUrlMapDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/urlMaps/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting RegionUrlMap %q", d.Id()) + + res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "RegionUrlMap") + } + + op := &compute.Operation{} + err = Convert(res, op) + if err != nil { + return err + } + + err = computeOperationWaitTime( + config.clientCompute, op, project, "Deleting RegionUrlMap", + int(d.Timeout(schema.TimeoutDelete).Minutes())) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting RegionUrlMap %q: %#v", d.Id(), res) + return nil +} + +func resourceComputeRegionUrlMapImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if err := parseImportId([]string{ + "projects/(?P[^/]+)/regions/(?P[^/]+)/urlMaps/(?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, "{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenComputeRegionUrlMapCreationTimestamp(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapDefaultService(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return ConvertSelfLinkToV1(v.(string)) +} + +func flattenComputeRegionUrlMapDescription(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapHostRule(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := schema.NewSet(schema.HashResource(computeRegionUrlMapHostRuleSchema()), []interface{}{}) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed.Add(map[string]interface{}{ + "description": flattenComputeRegionUrlMapHostRuleDescription(original["description"], d), + "hosts": flattenComputeRegionUrlMapHostRuleHosts(original["hosts"], d), + "path_matcher": flattenComputeRegionUrlMapHostRulePathMatcher(original["pathMatcher"], d), + }) + } + return transformed +} +func flattenComputeRegionUrlMapHostRuleDescription(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapHostRuleHosts(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return schema.NewSet(schema.HashString, v.([]interface{})) +} + +func flattenComputeRegionUrlMapHostRulePathMatcher(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapMapId(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 flattenComputeRegionUrlMapFingerprint(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapPathMatcher(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "default_service": flattenComputeRegionUrlMapPathMatcherDefaultService(original["defaultService"], d), + "description": flattenComputeRegionUrlMapPathMatcherDescription(original["description"], d), + "name": flattenComputeRegionUrlMapPathMatcherName(original["name"], d), + "path_rule": flattenComputeRegionUrlMapPathMatcherPathRule(original["pathRules"], d), + }) + } + return transformed +} +func flattenComputeRegionUrlMapPathMatcherDefaultService(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return ConvertSelfLinkToV1(v.(string)) +} + +func flattenComputeRegionUrlMapPathMatcherDescription(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapPathMatcherName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapPathMatcherPathRule(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "paths": flattenComputeRegionUrlMapPathMatcherPathRulePaths(original["paths"], d), + "service": flattenComputeRegionUrlMapPathMatcherPathRuleService(original["service"], d), + }) + } + return transformed +} +func flattenComputeRegionUrlMapPathMatcherPathRulePaths(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return schema.NewSet(schema.HashString, v.([]interface{})) +} + +func flattenComputeRegionUrlMapPathMatcherPathRuleService(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return ConvertSelfLinkToV1(v.(string)) +} + +func flattenComputeRegionUrlMapTest(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "description": flattenComputeRegionUrlMapTestDescription(original["description"], d), + "host": flattenComputeRegionUrlMapTestHost(original["host"], d), + "path": flattenComputeRegionUrlMapTestPath(original["path"], d), + "service": flattenComputeRegionUrlMapTestService(original["service"], d), + }) + } + return transformed +} +func flattenComputeRegionUrlMapTestDescription(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapTestHost(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapTestPath(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionUrlMapTestService(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return ConvertSelfLinkToV1(v.(string)) +} + +func flattenComputeRegionUrlMapRegion(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return NameFromSelfLinkStateFunc(v) +} + +func expandComputeRegionUrlMapDefaultService(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseRegionalFieldValue("backendServices", v.(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for default_service: %s", err) + } + return f.RelativeLink(), nil +} + +func expandComputeRegionUrlMapDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapHostRule(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + v = v.(*schema.Set).List() + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedDescription, err := expandComputeRegionUrlMapHostRuleDescription(original["description"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDescription); val.IsValid() && !isEmptyValue(val) { + transformed["description"] = transformedDescription + } + + transformedHosts, err := expandComputeRegionUrlMapHostRuleHosts(original["hosts"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedHosts); val.IsValid() && !isEmptyValue(val) { + transformed["hosts"] = transformedHosts + } + + transformedPathMatcher, err := expandComputeRegionUrlMapHostRulePathMatcher(original["path_matcher"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPathMatcher); val.IsValid() && !isEmptyValue(val) { + transformed["pathMatcher"] = transformedPathMatcher + } + + req = append(req, transformed) + } + return req, nil +} + +func expandComputeRegionUrlMapHostRuleDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapHostRuleHosts(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + v = v.(*schema.Set).List() + return v, nil +} + +func expandComputeRegionUrlMapHostRulePathMatcher(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapFingerprint(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapPathMatcher(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedDefaultService, err := expandComputeRegionUrlMapPathMatcherDefaultService(original["default_service"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDefaultService); val.IsValid() && !isEmptyValue(val) { + transformed["defaultService"] = transformedDefaultService + } + + transformedDescription, err := expandComputeRegionUrlMapPathMatcherDescription(original["description"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDescription); val.IsValid() && !isEmptyValue(val) { + transformed["description"] = transformedDescription + } + + transformedName, err := expandComputeRegionUrlMapPathMatcherName(original["name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedName); val.IsValid() && !isEmptyValue(val) { + transformed["name"] = transformedName + } + + transformedPathRule, err := expandComputeRegionUrlMapPathMatcherPathRule(original["path_rule"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPathRule); val.IsValid() && !isEmptyValue(val) { + transformed["pathRules"] = transformedPathRule + } + + req = append(req, transformed) + } + return req, nil +} + +func expandComputeRegionUrlMapPathMatcherDefaultService(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseRegionalFieldValue("backendServices", v.(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for default_service: %s", err) + } + return f.RelativeLink(), nil +} + +func expandComputeRegionUrlMapPathMatcherDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapPathMatcherName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapPathMatcherPathRule(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedPaths, err := expandComputeRegionUrlMapPathMatcherPathRulePaths(original["paths"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPaths); val.IsValid() && !isEmptyValue(val) { + transformed["paths"] = transformedPaths + } + + transformedService, err := expandComputeRegionUrlMapPathMatcherPathRuleService(original["service"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedService); val.IsValid() && !isEmptyValue(val) { + transformed["service"] = transformedService + } + + req = append(req, transformed) + } + return req, nil +} + +func expandComputeRegionUrlMapPathMatcherPathRulePaths(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + v = v.(*schema.Set).List() + return v, nil +} + +func expandComputeRegionUrlMapPathMatcherPathRuleService(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseRegionalFieldValue("backendServices", v.(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for service: %s", err) + } + return f.RelativeLink(), nil +} + +func expandComputeRegionUrlMapTest(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedDescription, err := expandComputeRegionUrlMapTestDescription(original["description"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDescription); val.IsValid() && !isEmptyValue(val) { + transformed["description"] = transformedDescription + } + + transformedHost, err := expandComputeRegionUrlMapTestHost(original["host"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedHost); val.IsValid() && !isEmptyValue(val) { + transformed["host"] = transformedHost + } + + transformedPath, err := expandComputeRegionUrlMapTestPath(original["path"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPath); val.IsValid() && !isEmptyValue(val) { + transformed["path"] = transformedPath + } + + transformedService, err := expandComputeRegionUrlMapTestService(original["service"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedService); val.IsValid() && !isEmptyValue(val) { + transformed["service"] = transformedService + } + + req = append(req, transformed) + } + return req, nil +} + +func expandComputeRegionUrlMapTestDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapTestHost(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapTestPath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionUrlMapTestService(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseRegionalFieldValue("backendServices", v.(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for service: %s", err) + } + return f.RelativeLink(), nil +} + +func expandComputeRegionUrlMapRegion(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseGlobalFieldValue("regions", v.(string), "project", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for region: %s", err) + } + return f.RelativeLink(), nil +} diff --git a/google-beta/resource_compute_region_url_map_generated_test.go b/google-beta/resource_compute_region_url_map_generated_test.go new file mode 100644 index 00000000000..63362c12ab1 --- /dev/null +++ b/google-beta/resource_compute_region_url_map_generated_test.go @@ -0,0 +1,141 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 TestAccComputeRegionUrlMap_regionUrlMapBasicExample(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: testAccCheckComputeRegionUrlMapDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionUrlMap_regionUrlMapBasicExample(context), + }, + { + ResourceName: "google_compute_region_url_map.regionurlmap", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionUrlMap_regionUrlMapBasicExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_url_map" "regionurlmap" { + name = "regionurlmap%{random_suffix}" + description = "a description" + region = "us-central1" + + default_service = "${google_compute_region_backend_service.home.self_link}" + + host_rule { + hosts = ["mysite.com"] + path_matcher = "allpaths" + } + + path_matcher { + name = "allpaths" + default_service = "${google_compute_region_backend_service.home.self_link}" + + path_rule { + paths = ["/home"] + service = "${google_compute_region_backend_service.home.self_link}" + } + + path_rule { + paths = ["/login"] + service = "${google_compute_region_backend_service.login.self_link}" + } + } + + test { + service = "${google_compute_region_backend_service.home.self_link}" + host = "hi.com" + path = "/home" + } +} + +resource "google_compute_region_backend_service" "login" { + name = "login%{random_suffix}" + region = "us-central1" + protocol = "HTTP" + timeout_sec = 10 + + health_checks = ["${google_compute_region_health_check.default.self_link}"] +} + +resource "google_compute_region_backend_service" "home" { + name = "home%{random_suffix}" + region = "us-central1" + protocol = "HTTP" + timeout_sec = 10 + + health_checks = ["${google_compute_region_health_check.default.self_link}"] +} + +resource "google_compute_region_health_check" "default" { + name = "health-check%{random_suffix}" + region = "us-central1" + check_interval_sec = 1 + timeout_sec = 1 + http_health_check { + port = 80 + request_path = "/" + } +} +`, context) +} + +func testAccCheckComputeRegionUrlMapDestroy(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_compute_region_url_map" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := testAccProvider.Meta().(*Config) + + url, err := replaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/urlMaps/{{name}}") + if err != nil { + return err + } + + _, err = sendRequest(config, "GET", "", url, nil) + if err == nil { + return fmt.Errorf("ComputeRegionUrlMap still exists at %s", url) + } + } + + return nil +} diff --git a/google-beta/resource_compute_region_url_map_test.go b/google-beta/resource_compute_region_url_map_test.go new file mode 100644 index 00000000000..90e0eb4b0ac --- /dev/null +++ b/google-beta/resource_compute_region_url_map_test.go @@ -0,0 +1,357 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccComputeRegionUrlMap_update_path_matcher(t *testing.T) { + t.Parallel() + + randomSuffix := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeUrlMapDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionUrlMap_basic1(randomSuffix), + }, + { + ResourceName: "google_compute_region_url_map.foobar", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccComputeRegionUrlMap_basic2(randomSuffix), + }, + { + ResourceName: "google_compute_region_url_map.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccComputeRegionUrlMap_advanced(t *testing.T) { + t.Parallel() + + randomSuffix := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeUrlMapDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionUrlMap_advanced1(randomSuffix), + }, + { + ResourceName: "google_compute_region_url_map.foobar", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccComputeRegionUrlMap_advanced2(randomSuffix), + }, + { + ResourceName: "google_compute_region_url_map.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccComputeRegionUrlMap_noPathRulesWithUpdate(t *testing.T) { + t.Parallel() + + randomSuffix := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeUrlMapDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionUrlMap_noPathRules(randomSuffix), + }, + { + ResourceName: "google_compute_region_url_map.foobar", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccComputeRegionUrlMap_basic1(randomSuffix), + }, + { + ResourceName: "google_compute_region_url_map.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionUrlMap_basic1(randomSuffix string) string { + return fmt.Sprintf(` +resource "google_compute_region_backend_service" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + protocol = "HTTP" + health_checks = ["${google_compute_region_health_check.zero.self_link}"] +} + +resource "google_compute_region_health_check" "zero" { + region = "us-central1" + name = "regionurlmap-test-%s" + http_health_check { + } +} + +resource "google_compute_region_url_map" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + default_service = "${google_compute_region_backend_service.foobar.self_link}" + + host_rule { + hosts = ["mysite.com", "myothersite.com"] + path_matcher = "boop" + } + + path_matcher { + default_service = "${google_compute_region_backend_service.foobar.self_link}" + name = "boop" + + path_rule { + paths = ["/*"] + service = "${google_compute_region_backend_service.foobar.self_link}" + } + } + + test { + host = "mysite.com" + path = "/*" + service = "${google_compute_region_backend_service.foobar.self_link}" + } +} +`, randomSuffix, randomSuffix, randomSuffix) +} + +func testAccComputeRegionUrlMap_basic2(randomSuffix string) string { + return fmt.Sprintf(` +resource "google_compute_region_backend_service" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + protocol = "HTTP" + health_checks = ["${google_compute_region_health_check.zero.self_link}"] +} + +resource "google_compute_region_health_check" "zero" { + region = "us-central1" + name = "regionurlmap-test-%s" + http_health_check { + } +} + +resource "google_compute_region_url_map" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + default_service = "${google_compute_region_backend_service.foobar.self_link}" + + host_rule { + hosts = ["mysite.com", "myothersite.com"] + path_matcher = "blip" + } + + path_matcher { + default_service = "${google_compute_region_backend_service.foobar.self_link}" + name = "blip" + + path_rule { + paths = ["/*", "/home"] + service = "${google_compute_region_backend_service.foobar.self_link}" + } + } + + test { + host = "mysite.com" + path = "/test" + service = "${google_compute_region_backend_service.foobar.self_link}" + } +} +`, randomSuffix, randomSuffix, randomSuffix) +} + +func testAccComputeRegionUrlMap_advanced1(randomSuffix string) string { + return fmt.Sprintf(` +resource "google_compute_region_backend_service" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + protocol = "HTTP" + health_checks = ["${google_compute_region_health_check.zero.self_link}"] +} + +resource "google_compute_region_health_check" "zero" { + region = "us-central1" + name = "regionurlmap-test-%s" + http_health_check { + } +} + +resource "google_compute_region_url_map" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + default_service = "${google_compute_region_backend_service.foobar.self_link}" + + host_rule { + hosts = ["mysite.com", "myothersite.com"] + path_matcher = "blop" + } + + host_rule { + hosts = ["myfavoritesite.com"] + path_matcher = "blip" + } + + path_matcher { + default_service = "${google_compute_region_backend_service.foobar.self_link}" + name = "blop" + + path_rule { + paths = ["/*", "/home"] + service = "${google_compute_region_backend_service.foobar.self_link}" + } + } + + path_matcher { + default_service = "${google_compute_region_backend_service.foobar.self_link}" + name = "blip" + + path_rule { + paths = ["/*", "/home"] + service = "${google_compute_region_backend_service.foobar.self_link}" + } + } +} +`, randomSuffix, randomSuffix, randomSuffix) +} + +func testAccComputeRegionUrlMap_advanced2(randomSuffix string) string { + return fmt.Sprintf(` +resource "google_compute_region_backend_service" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + protocol = "HTTP" + health_checks = ["${google_compute_region_health_check.zero.self_link}"] +} + +resource "google_compute_region_health_check" "zero" { + region = "us-central1" + name = "regionurlmap-test-%s" + http_health_check { + } +} + +resource "google_compute_region_url_map" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + default_service = "${google_compute_region_backend_service.foobar.self_link}" + + host_rule { + hosts = ["mysite.com", "myothersite.com"] + path_matcher = "blep" + } + + host_rule { + hosts = ["myfavoritesite.com"] + path_matcher = "blip" + } + + host_rule { + hosts = ["myleastfavoritesite.com"] + path_matcher = "blub" + } + + path_matcher { + default_service = "${google_compute_region_backend_service.foobar.self_link}" + name = "blep" + + path_rule { + paths = ["/home"] + service = "${google_compute_region_backend_service.foobar.self_link}" + } + + path_rule { + paths = ["/login"] + service = "${google_compute_region_backend_service.foobar.self_link}" + } + } + + path_matcher { + default_service = "${google_compute_region_backend_service.foobar.self_link}" + name = "blub" + + path_rule { + paths = ["/*", "/blub"] + service = "${google_compute_region_backend_service.foobar.self_link}" + } + } + + path_matcher { + default_service = "${google_compute_region_backend_service.foobar.self_link}" + name = "blip" + + path_rule { + paths = ["/*", "/home"] + service = "${google_compute_region_backend_service.foobar.self_link}" + } + } +} +`, randomSuffix, randomSuffix, randomSuffix) +} + +func testAccComputeRegionUrlMap_noPathRules(randomSuffix string) string { + return fmt.Sprintf(` +resource "google_compute_region_backend_service" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + protocol = "HTTP" + health_checks = ["${google_compute_region_health_check.zero.self_link}"] +} + +resource "google_compute_region_health_check" "zero" { + region = "us-central1" + name = "regionurlmap-test-%s" + http_health_check { + } +} + +resource "google_compute_region_url_map" "foobar" { + region = "us-central1" + name = "regionurlmap-test-%s" + default_service = "${google_compute_region_backend_service.foobar.self_link}" + + host_rule { + hosts = ["mysite.com", "myothersite.com"] + path_matcher = "boop" + } + + path_matcher { + default_service = "${google_compute_region_backend_service.foobar.self_link}" + name = "boop" + } + + test { + host = "mysite.com" + path = "/*" + service = "${google_compute_region_backend_service.foobar.self_link}" + } +} +`, randomSuffix, randomSuffix, randomSuffix) +} diff --git a/website/docs/r/compute_region_url_map.html.markdown b/website/docs/r/compute_region_url_map.html.markdown new file mode 100644 index 00000000000..c57921d05a3 --- /dev/null +++ b/website/docs/r/compute_region_url_map.html.markdown @@ -0,0 +1,268 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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_region_url_map" +sidebar_current: "docs-google-compute-region-url-map" +description: |- + UrlMaps are used to route requests to a backend service based on rules + that you define for the host and path of an incoming URL. +--- + +# google\_compute\_region\_url\_map + +UrlMaps are used to route requests to a backend service based on rules +that you define for the host and path of an incoming URL. + + + + +## Example Usage - Region Url Map Basic + + +```hcl +resource "google_compute_region_url_map" "regionurlmap" { + name = "regionurlmap" + description = "a description" + region = "us-central1" + + default_service = "${google_compute_region_backend_service.home.self_link}" + + host_rule { + hosts = ["mysite.com"] + path_matcher = "allpaths" + } + + path_matcher { + name = "allpaths" + default_service = "${google_compute_region_backend_service.home.self_link}" + + path_rule { + paths = ["/home"] + service = "${google_compute_region_backend_service.home.self_link}" + } + + path_rule { + paths = ["/login"] + service = "${google_compute_region_backend_service.login.self_link}" + } + } + + test { + service = "${google_compute_region_backend_service.home.self_link}" + host = "hi.com" + path = "/home" + } +} + +resource "google_compute_region_backend_service" "login" { + name = "login" + region = "us-central1" + protocol = "HTTP" + timeout_sec = 10 + + health_checks = ["${google_compute_region_health_check.default.self_link}"] +} + +resource "google_compute_region_backend_service" "home" { + name = "home" + region = "us-central1" + protocol = "HTTP" + timeout_sec = 10 + + health_checks = ["${google_compute_region_health_check.default.self_link}"] +} + +resource "google_compute_region_health_check" "default" { + name = "health-check" + region = "us-central1" + check_interval_sec = 1 + timeout_sec = 1 + http_health_check { + port = 80 + request_path = "/" + } +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `default_service` - + (Required) + A reference to RegionBackendService resource if none of the hostRules match. + +* `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. + + +- - - + + +* `description` - + (Optional) + An optional description of this resource. Provide this property when + you create the resource. + +* `host_rule` - + (Optional) + The list of HostRules to use against the URL. Structure is documented below. + +* `path_matcher` - + (Optional) + The list of named PathMatchers to use against the URL. Structure is documented below. + +* `test` - + (Optional) + The list of expected URL mappings. Requests to update this UrlMap will + succeed only if all of the test cases pass. Structure is documented below. + +* `region` - + (Optional) + The Region in which the url map should reside. + If it is not provided, the provider region is used. + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + +The `host_rule` block supports: + +* `description` - + (Optional) + An optional description of this HostRule. Provide this property + when you create the resource. + +* `hosts` - + (Required) + The list of host patterns to match. They must be valid + hostnames, except * will match any string of ([a-z0-9-.]*). In + that case, * must be the first character and must be followed in + the pattern by either - or .. + +* `path_matcher` - + (Required) + The name of the PathMatcher to use to match the path portion of + the URL if the hostRule matches the URL's host portion. + +The `path_matcher` block supports: + +* `default_service` - + (Required) + A reference to a RegionBackendService resource. This will be used if + none of the pathRules defined by this PathMatcher is matched by + the URL's path portion. + +* `description` - + (Optional) + An optional description of this resource. + +* `name` - + (Required) + The name to which this PathMatcher is referred by the HostRule. + +* `path_rule` - + (Optional) + The list of path rules. Structure is documented below. + + +The `path_rule` block supports: + +* `paths` - + (Required) + The list of path patterns to match. Each must start with / + and the only place a * is allowed is at the end following + a /. The string fed to the path matcher does not include + any text after the first ? or #, and those chars are not + allowed here. + +* `service` - + (Required) + A reference to the RegionBackendService resource if this rule is + matched. + +The `test` block supports: + +* `description` - + (Optional) + Description of this test case. + +* `host` - + (Required) + Host portion of the URL. + +* `path` - + (Required) + Path portion of the URL. + +* `service` - + (Required) + A reference to expected RegionBackendService resource the given URL should be mapped to. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + + +* `creation_timestamp` - + Creation timestamp in RFC3339 text format. + +* `map_id` - + The unique identifier for the resource. + +* `fingerprint` - + Fingerprint of this resource. This field is used internally during + updates of this resource. +* `self_link` - The URI of the created resource. + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 4 minutes. +- `update` - Default is 4 minutes. +- `delete` - Default is 4 minutes. + +## Import + +RegionUrlMap can be imported using any of these accepted formats: + +``` +$ terraform import google_compute_region_url_map.default projects/{{project}}/regions/{{region}}/urlMaps/{{name}} +$ terraform import google_compute_region_url_map.default {{project}}/{{region}}/{{name}} +$ terraform import google_compute_region_url_map.default {{region}}/{{name}} +$ terraform import google_compute_region_url_map.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/provider_reference.html#user_project_override).