Skip to content

Commit fbca264

Browse files
committed
Add custom import logic
1 parent efd2aea commit fbca264

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

mmv1/products/apihub/ApiHubInstance.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ name: ApiHubInstance
1616
description: An ApiHubInstance represents the instance resources of the API Hub. Currently, only one ApiHub instance is allowed for each project.
1717
base_url: projects/{{project}}/locations/{{location}}/apiHubInstances
1818
immutable: true
19-
self_link: projects/{{project}}/locations/{{location}}/apiHubInstances/{{api_hub_instance_id}}
19+
self_link: '{{name}}'
2020
create_url: projects/{{project}}/locations/{{location}}/apiHubInstances?apiHubInstanceId={{api_hub_instance_id}}
21-
id_format: projects/{{project}}/locations/{{location}}/apiHubInstances/{{api_hub_instance_id}}
21+
id_format: '{{name}}'
2222
import_format:
2323
- projects/{{project}}/locations/{{location}}/apiHubInstances/{{api_hub_instance_id}}
24+
custom_code:
25+
custom_import: 'templates/terraform/custom_import/apihub_api_hub_instance_set_id.go.tmpl'
2426
examples:
2527
- name: apihub_api_hub_instance_basic
2628
primary_resource_id: apihub-instance
@@ -63,7 +65,6 @@ parameters:
6365
are `/a-z[0-9]-_/`.
6466
immutable: true
6567
url_param_only: true
66-
required: true
6768
properties:
6869
- name: description
6970
type: String
@@ -108,6 +109,7 @@ properties:
108109
properties:
109110
- name: encryptionType
110111
type: String
112+
default_from_api: true
111113
description: |-
112114
Optional. Encryption type for the region. If the encryption type is CMEK, the
113115
cmek_key_name must be provided. If no encryption type is provided,

mmv1/products/apihub/product.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ scopes:
1919
versions:
2020
- base_url: https://apihub.googleapis.com/v1/
2121
name: ga
22-
caibaseurl: ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
config := meta.(*transport_tpg.Config)
2+
if err := tpgresource.ParseImportId([]string{
3+
"^projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/apiHubInstances/(?P<api_hub_instance_id>[^/]+)$",
4+
"^(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<api_hub_instance_id>[^/]+)$",
5+
"^(?P<location>[^/]+)/(?P<api_hub_instance_id>[^/]+)$",
6+
}, d, config); err != nil {
7+
return nil, err
8+
}
9+
10+
// Set name based on the components
11+
if err := d.Set("name", "projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/apiHubInstances/{{"{{"}}api_hub_instance_id{{"}}"}}"); err != nil {
12+
return nil, fmt.Errorf("Error setting name: %s", err)
13+
}
14+
15+
// Replace import id for the resource id
16+
id, err := tpgresource.ReplaceVars(d, config, d.Get("name").(string))
17+
if err != nil {
18+
return nil, fmt.Errorf("Error constructing id: %s", err)
19+
}
20+
d.SetId(id)
21+
22+
return []*schema.ResourceData{d}, nil
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
resource "google_apihub_api_hub_instance" "{{$.PrimaryResourceId}}"{
2-
api_hub_instance_id = "{{index $.Vars "instance_id"}}"
32
location = "us-central1"
43
config {
5-
encryption_type = "GMEK"
64
disable_search = true
75
}
86
}

0 commit comments

Comments
 (0)