Skip to content

Commit

Permalink
Add location field to google_network_services_mesh (#12991)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshZhang authored Feb 10, 2025
1 parent 366c857 commit 08ecbc9
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 4 deletions.
25 changes: 21 additions & 4 deletions mmv1/products/networkservices/Mesh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ references:
guides:
api: 'https://cloud.google.com/traffic-director/docs/reference/network-services/rest/v1beta1/projects.locations.meshes'
docs:
base_url: 'projects/{{project}}/locations/global/meshes'
self_link: 'projects/{{project}}/locations/global/meshes/{{name}}'
create_url: 'projects/{{project}}/locations/global/meshes?meshId={{name}}'
base_url: 'projects/{{project}}/locations/{{location}}/meshes'
self_link: 'projects/{{project}}/locations/{{location}}/meshes/{{name}}'
create_url: 'projects/{{project}}/locations/{{location}}/meshes?meshId={{name}}'
update_verb: 'PATCH'
update_mask: true
import_format:
- 'projects/{{project}}/locations/global/meshes/{{name}}'
- 'projects/{{project}}/locations/{{location}}/meshes/{{name}}'
timeouts:
insert_minutes: 30
update_minutes: 30
Expand All @@ -46,6 +46,8 @@ async:
result:
resource_inside_response: false
custom_code:
schema_version: 1
state_upgraders: true
examples:
- name: 'network_services_mesh_basic'
primary_resource_id: 'default'
Expand All @@ -57,6 +59,11 @@ examples:
min_version: 'beta'
vars:
resource_name: 'my-mesh-noport'
- name: 'network_services_mesh_location'
primary_resource_id: 'default'
min_version: 'beta'
vars:
resource_name: 'my-mesh'
parameters:
- name: 'name'
type: String
Expand Down Expand Up @@ -102,3 +109,13 @@ properties:
'15001' is used as the interception port. This will is applicable only for sidecar proxy
deployments.
min_version: 'beta'
- name: 'location'
type: String
description: |
Location (region) of the Mesh resource to be created. Only the value 'global' is currently allowed; defaults to 'global' if omitted.
min_version: 'beta'
url_param_only: true
immutable: true
default_value: 'global'
validation:
regex: '^global$'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "google_network_services_mesh" "{{$.PrimaryResourceId}}" {
provider = google-beta
name = "{{index $.Vars "resource_name"}}"
location = "global"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
func resourceNetworkServicesMeshResourceV0() *schema.Resource {
return &schema.Resource{
Create: resourceNetworkServicesMeshCreate,
Read: resourceNetworkServicesMeshRead,
Update: resourceNetworkServicesMeshUpdate,
Delete: resourceNetworkServicesMeshDelete,

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

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.SetLabelsDiff,
tpgresource.DefaultProviderProject,
),

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: `Short name of the Mesh resource to be created.`,
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: `A free-text description of the resource. Max length 1024 characters.`,
},
"interception_port": {
Type: schema.TypeInt,
Optional: true,
Description: `Optional. If set to a valid TCP port (1-65535), instructs the SIDECAR proxy to listen on the
specified port of localhost (127.0.0.1) address. The SIDECAR proxy will expect all traffic to
be redirected to this port regardless of its actual ip:port destination. If unset, a port
'15001' is used as the interception port. This will is applicable only for sidecar proxy
deployments.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Set of label tags associated with the Mesh resource.

**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: `Time the Mesh was created in UTC.`,
},
"effective_labels": {
Type: schema.TypeMap,
Computed: true,
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"self_link": {
Type: schema.TypeString,
Computed: true,
Description: `Server-defined URL of this resource.`,
},
"terraform_labels": {
Type: schema.TypeMap,
Computed: true,
Description: `The combination of labels configured directly on the resource
and default labels configured on the provider.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Description: `Time the Mesh was updated in UTC.`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
UseJSONNumber: true,
}
}

func ResourceNetworkServicesMeshUpgradeV0(_ 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
}

0 comments on commit 08ecbc9

Please sign in to comment.