Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions mmv1/products/networkservices/TlsRoute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ references:
guides:
api: 'https://cloud.google.com/traffic-director/docs/reference/network-services/rest/v1beta1/projects.locations.tlsRoutes'
docs:
base_url: 'projects/{{project}}/locations/global/tlsRoutes'
self_link: 'projects/{{project}}/locations/global/tlsRoutes/{{name}}'
create_url: 'projects/{{project}}/locations/global/tlsRoutes?tlsRouteId={{name}}'
base_url: 'projects/{{project}}/locations/{{location}}/tlsRoutes'
self_link: 'projects/{{project}}/locations/{{location}}/tlsRoutes/{{name}}'
create_url: 'projects/{{project}}/locations/{{location}}/tlsRoutes?tlsRouteId={{name}}'
update_verb: 'PATCH'
update_mask: true
import_format:
- 'projects/{{project}}/locations/{{location}}/tlsRoutes/{{name}}'
- 'projects/{{project}}/locations/global/tlsRoutes/{{name}}'
timeouts:
insert_minutes: 30
Expand All @@ -42,6 +43,8 @@ async:
delete_minutes: 30
result:
resource_inside_response: false
schema_version: 1
state_upgraders: true
custom_code:
examples:
- name: 'network_services_tls_route_basic'
Expand All @@ -50,6 +53,12 @@ examples:
resource_name: 'my-tls-route'
backend_service_name: 'my-backend-service'
http_health_check_name: 'backend-service-health-check'
- name: 'network_services_tls_route_regional_basic'
primary_resource_id: 'default'
vars:
resource_name: 'my-tls-route'
backend_service_name: 'my-backend-service'
health_check_name: 'backend-service-health-check'
- name: 'network_services_tls_route_mesh_basic'
primary_resource_id: 'default'
vars:
Expand All @@ -70,6 +79,13 @@ parameters:
url_param_only: true
required: true
immutable: true
- name: 'location'
type: 'String'
description: |
Location (region) of the TLS Route.
immutable: true
default_value: 'global'
url_param_only: true
properties:
- name: 'selfLink'
type: String
Expand All @@ -94,7 +110,7 @@ properties:
type: Array
description: |
Meshes defines a list of meshes this TlsRoute is attached to, as one of the routing rules to route the requests served by the mesh.
Each mesh reference should match the pattern: projects/*/locations/global/meshes/<mesh_name>
Each mesh reference should match the pattern: projects/*/locations/*/meshes/<mesh_name>
The attached Mesh should be of a type SIDECAR
send_empty_value: true
item_type:
Expand All @@ -103,7 +119,7 @@ properties:
type: Array
description: |
Gateways defines a list of gateways this TlsRoute is attached to, as one of the routing rules to route the requests served by the gateway.
Each gateway reference should match the pattern: projects/*/locations/global/gateways/<gateway_name>
Each gateway reference should match the pattern: projects/*/locations/*/gateways/<gateway_name>
send_empty_value: true
item_type:
type: String
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
resource "google_compute_region_backend_service" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "backend_service_name"}}"
protocol = "TCP"
timeout_sec = 10
region = "europe-west4"

health_checks = [google_compute_region_health_check.{{$.PrimaryResourceId}}.id]
load_balancing_scheme = "EXTERNAL_MANAGED"
}

resource "google_compute_region_health_check" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "health_check_name"}}"
region = "europe-west4"
timeout_sec = 1
check_interval_sec = 1
tcp_health_check {
port = "80"
}
}

resource "google_network_services_tls_route" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "resource_name"}}"
location = "europe-west4"
rules {
matches {
sni_host = ["example.com"]
}
action {
destinations {
service_name = google_compute_region_backend_service.{{$.PrimaryResourceId}}.self_link
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
func resourceNetworkServicesTlsRouteResourceV0() *schema.Resource {
return &schema.Resource{
Create: resourceNetworkServicesTlsRouteCreate,
Read: resourceNetworkServicesTlsRouteRead,
Update: resourceNetworkServicesTlsRouteUpdate,
Delete: resourceNetworkServicesTlsRouteDelete,

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

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

CustomizeDiff: customdiff.All(
tpgresource.DefaultProviderProject,
),

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Name of the TlsRoute resource.`,
},
"rules": {
Type: schema.TypeList,
Required: true,
Description: `Rules that define how traffic is routed and handled.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"action": {
Type: schema.TypeList,
Required: true,
Description: `Required. A detailed rule defining how to route traffic.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"destinations": {
Type: schema.TypeList,
Optional: true,
Description: `The destination to which traffic should be forwarded.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Optional: true,
Description: `The URL of a BackendService to route traffic to.`,
},
"weight": {
Type: schema.TypeInt,
Optional: true,
Description: `Specifies the proportion of requests forwarded to the backend referenced by the serviceName field.`,
},
},
},
},
},
},
},
"matches": {
Type: schema.TypeList,
Required: true,
Description: `Matches define the predicate used to match requests to a given action.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"alpn": {
Type: schema.TypeList,
Optional: true,
Description: `ALPN (Application-Layer Protocol Negotiation) to match against. Examples: "http/1.1", "h2". At least one of sniHost and alpn is required. Up to 5 alpns across all matches can be set.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"sni_host": {
Type: schema.TypeList,
Optional: true,
Description: `SNI (server name indicator) to match against. SNI will be matched against all wildcard domains, i.e. www.example.com will be first matched against www.example.com, then *.example.com, then *.com.
Partial wildcards are not supported, and values like *w.example.com are invalid. At least one of sniHost and alpn is required. Up to 5 sni hosts across all matches can be set.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: `A free-text description of the resource. Max length 1024 characters.`,
},
"gateways": {
Type: schema.TypeList,
Optional: true,
Description: `Gateways defines a list of gateways this TlsRoute is attached to, as one of the routing rules to route the requests served by the gateway.
Each gateway reference should match the pattern: projects/*/locations/*/gateways/<gateway_name>`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"meshes": {
Type: schema.TypeList,
Optional: true,
Description: `Meshes defines a list of meshes this TlsRoute is attached to, as one of the routing rules to route the requests served by the mesh.
Each mesh reference should match the pattern: projects/*/locations/*/meshes/<mesh_name>
The attached Mesh should be of a type SIDECAR`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: `Time the TlsRoute was created in UTC.`,
},
"self_link": {
Type: schema.TypeString,
Computed: true,
Description: `Server-defined URL of this resource.`,
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Description: `Time the TlsRoute was updated in UTC.`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
UseJSONNumber: true,
}
}

func ResourceNetworkServicesTlsRouteUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error){
log.Printf("[DEBUG] Attributes before migration: %#v", rawState)
if _, ok := rawState["location"]; !ok {
rawState["location"] = "global"
}
log.Printf("[DEBUG] Attributes after migration: %#v", rawState)
return rawState, nil
}
Loading