diff --git a/mmv1/products/networkservices/TlsRoute.yaml b/mmv1/products/networkservices/TlsRoute.yaml index 4eaf78f5b2b2..2e1c847d37da 100644 --- a/mmv1/products/networkservices/TlsRoute.yaml +++ b/mmv1/products/networkservices/TlsRoute.yaml @@ -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 @@ -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' @@ -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: @@ -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 @@ -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/ + Each mesh reference should match the pattern: projects/*/locations/*/meshes/ The attached Mesh should be of a type SIDECAR send_empty_value: true item_type: @@ -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/ + Each gateway reference should match the pattern: projects/*/locations/*/gateways/ send_empty_value: true item_type: type: String diff --git a/mmv1/templates/terraform/examples/network_services_tls_route_regional_basic.tf.tmpl b/mmv1/templates/terraform/examples/network_services_tls_route_regional_basic.tf.tmpl new file mode 100644 index 000000000000..9ec89ba71e61 --- /dev/null +++ b/mmv1/templates/terraform/examples/network_services_tls_route_regional_basic.tf.tmpl @@ -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 + } + } + } +} diff --git a/mmv1/templates/terraform/state_migrations/network_services_tls_route.go.tmpl b/mmv1/templates/terraform/state_migrations/network_services_tls_route.go.tmpl new file mode 100644 index 000000000000..157a05972dab --- /dev/null +++ b/mmv1/templates/terraform/state_migrations/network_services_tls_route.go.tmpl @@ -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/`, + 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/ +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 +}