Skip to content

Commit 08ecbc9

Browse files
authored
Add location field to google_network_services_mesh (GoogleCloudPlatform#12991)
1 parent 366c857 commit 08ecbc9

File tree

3 files changed

+124
-4
lines changed

3 files changed

+124
-4
lines changed

mmv1/products/networkservices/Mesh.yaml

+21-4
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ references:
2222
guides:
2323
api: 'https://cloud.google.com/traffic-director/docs/reference/network-services/rest/v1beta1/projects.locations.meshes'
2424
docs:
25-
base_url: 'projects/{{project}}/locations/global/meshes'
26-
self_link: 'projects/{{project}}/locations/global/meshes/{{name}}'
27-
create_url: 'projects/{{project}}/locations/global/meshes?meshId={{name}}'
25+
base_url: 'projects/{{project}}/locations/{{location}}/meshes'
26+
self_link: 'projects/{{project}}/locations/{{location}}/meshes/{{name}}'
27+
create_url: 'projects/{{project}}/locations/{{location}}/meshes?meshId={{name}}'
2828
update_verb: 'PATCH'
2929
update_mask: true
3030
import_format:
31-
- 'projects/{{project}}/locations/global/meshes/{{name}}'
31+
- 'projects/{{project}}/locations/{{location}}/meshes/{{name}}'
3232
timeouts:
3333
insert_minutes: 30
3434
update_minutes: 30
@@ -46,6 +46,8 @@ async:
4646
result:
4747
resource_inside_response: false
4848
custom_code:
49+
schema_version: 1
50+
state_upgraders: true
4951
examples:
5052
- name: 'network_services_mesh_basic'
5153
primary_resource_id: 'default'
@@ -57,6 +59,11 @@ examples:
5759
min_version: 'beta'
5860
vars:
5961
resource_name: 'my-mesh-noport'
62+
- name: 'network_services_mesh_location'
63+
primary_resource_id: 'default'
64+
min_version: 'beta'
65+
vars:
66+
resource_name: 'my-mesh'
6067
parameters:
6168
- name: 'name'
6269
type: String
@@ -102,3 +109,13 @@ properties:
102109
'15001' is used as the interception port. This will is applicable only for sidecar proxy
103110
deployments.
104111
min_version: 'beta'
112+
- name: 'location'
113+
type: String
114+
description: |
115+
Location (region) of the Mesh resource to be created. Only the value 'global' is currently allowed; defaults to 'global' if omitted.
116+
min_version: 'beta'
117+
url_param_only: true
118+
immutable: true
119+
default_value: 'global'
120+
validation:
121+
regex: '^global$'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "google_network_services_mesh" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
name = "{{index $.Vars "resource_name"}}"
4+
location = "global"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
func resourceNetworkServicesMeshResourceV0() *schema.Resource {
2+
return &schema.Resource{
3+
Create: resourceNetworkServicesMeshCreate,
4+
Read: resourceNetworkServicesMeshRead,
5+
Update: resourceNetworkServicesMeshUpdate,
6+
Delete: resourceNetworkServicesMeshDelete,
7+
8+
Importer: &schema.ResourceImporter{
9+
State: resourceNetworkServicesMeshImport,
10+
},
11+
12+
Timeouts: &schema.ResourceTimeout{
13+
Create: schema.DefaultTimeout(30 * time.Minute),
14+
Update: schema.DefaultTimeout(30 * time.Minute),
15+
Delete: schema.DefaultTimeout(30 * time.Minute),
16+
},
17+
18+
CustomizeDiff: customdiff.All(
19+
tpgresource.SetLabelsDiff,
20+
tpgresource.DefaultProviderProject,
21+
),
22+
23+
Schema: map[string]*schema.Schema{
24+
"name": {
25+
Type: schema.TypeString,
26+
Required: true,
27+
Description: `Short name of the Mesh resource to be created.`,
28+
},
29+
"description": {
30+
Type: schema.TypeString,
31+
Optional: true,
32+
Description: `A free-text description of the resource. Max length 1024 characters.`,
33+
},
34+
"interception_port": {
35+
Type: schema.TypeInt,
36+
Optional: true,
37+
Description: `Optional. If set to a valid TCP port (1-65535), instructs the SIDECAR proxy to listen on the
38+
specified port of localhost (127.0.0.1) address. The SIDECAR proxy will expect all traffic to
39+
be redirected to this port regardless of its actual ip:port destination. If unset, a port
40+
'15001' is used as the interception port. This will is applicable only for sidecar proxy
41+
deployments.`,
42+
},
43+
"labels": {
44+
Type: schema.TypeMap,
45+
Optional: true,
46+
Description: `Set of label tags associated with the Mesh resource.
47+
48+
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
49+
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
50+
Elem: &schema.Schema{Type: schema.TypeString},
51+
},
52+
"create_time": {
53+
Type: schema.TypeString,
54+
Computed: true,
55+
Description: `Time the Mesh was created in UTC.`,
56+
},
57+
"effective_labels": {
58+
Type: schema.TypeMap,
59+
Computed: true,
60+
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
61+
Elem: &schema.Schema{Type: schema.TypeString},
62+
},
63+
"self_link": {
64+
Type: schema.TypeString,
65+
Computed: true,
66+
Description: `Server-defined URL of this resource.`,
67+
},
68+
"terraform_labels": {
69+
Type: schema.TypeMap,
70+
Computed: true,
71+
Description: `The combination of labels configured directly on the resource
72+
and default labels configured on the provider.`,
73+
Elem: &schema.Schema{Type: schema.TypeString},
74+
},
75+
"update_time": {
76+
Type: schema.TypeString,
77+
Computed: true,
78+
Description: `Time the Mesh was updated in UTC.`,
79+
},
80+
"project": {
81+
Type: schema.TypeString,
82+
Optional: true,
83+
Computed: true,
84+
ForceNew: true,
85+
},
86+
},
87+
UseJSONNumber: true,
88+
}
89+
}
90+
91+
func ResourceNetworkServicesMeshUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error){
92+
log.Printf("[DEBUG] Attributes before migration: %#v", rawState)
93+
if _, ok := rawState["location"]; !ok {
94+
rawState["location"] = "global"
95+
}
96+
log.Printf("[DEBUG] Attributes after migration: %#v", rawState)
97+
return rawState, nil
98+
}

0 commit comments

Comments
 (0)