forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Apigee environment scope KVMs resource support (GoogleCloudPlatfo…
- Loading branch information
1 parent
aea5962
commit 30ab2a2
Showing
12 changed files
with
944 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2023 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Api::Resource | ||
name: 'EnvironmentKeyvaluemaps' | ||
description: | | ||
Collection of key/value string pairs. | ||
references: !ruby/object:Api::Resource::ReferenceLinks | ||
guides: | ||
'Using key value maps': 'https://cloud.google.com/apigee/docs/api-platform/cache/key-value-maps' | ||
api: 'https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments.keyvaluemaps/create' | ||
|
||
base_url: '{{env_id}}/keyvaluemaps' | ||
create_url: '{{env_id}}/keyvaluemaps' | ||
delete_url: '{{env_id}}/keyvaluemaps/{{name}}' | ||
self_link: '{{env_id}}/keyvaluemaps/{{name}}/entries' | ||
import_format: ['{{env_id}}/keyvaluemaps/{{name}}', '{{env_id}}/{{name}}'] | ||
skip_sweeper: true | ||
examples: | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: 'apigee_environment_keyvaluemaps_basic' | ||
primary_resource_id: 'apigee_environment_keyvaluemaps' | ||
test_env_vars: | ||
org_id: :ORG_ID | ||
billing_account: :BILLING_ACCT | ||
skip_test: true | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: 'apigee_environment_keyvaluemaps_test' | ||
primary_resource_id: 'apigee_environment_keyvaluemaps' | ||
test_env_vars: | ||
org_id: :ORG_ID | ||
billing_account: :BILLING_ACCT | ||
skip_docs: true | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: 'apigee_environment_keyvaluemaps_beta_test' | ||
primary_resource_id: 'apigee_environment_keyvaluemaps' | ||
test_env_vars: | ||
org_id: :ORG_ID | ||
billing_account: :BILLING_ACCT | ||
skip_docs: true | ||
min_version: beta | ||
immutable: true | ||
timeouts: !ruby/object:Api::Timeouts | ||
insert_minutes: 1 | ||
delete_minutes: 1 | ||
autogen_async: true | ||
custom_code: !ruby/object:Provider::Terraform::CustomCode | ||
custom_import: templates/terraform/custom_import/apigee_environment_keyvaluemaps.go.erb | ||
custom_create: 'templates/terraform/custom_create/apigee_environment_keyvaluemaps.go' | ||
decoder: templates/terraform/decoders/apigee_environment_keyvaluemaps.go.erb | ||
parameters: | ||
- !ruby/object:Api::Type::String | ||
name: 'envId' | ||
description: | | ||
The Apigee environment group associated with the Apigee environment, | ||
in the format `organizations/{{org_name}}/environments/{{env_name}}`. | ||
required: true | ||
immutable: true | ||
url_param_only: true | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: 'name' | ||
description: | | ||
Required. ID of the key value map. | ||
required: true | ||
immutable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright 2023 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Api::Resource | ||
name: 'EnvironmentKeyvaluemapsEntries' | ||
description: | | ||
Creates key value entries in a key value map scoped to an environment. | ||
references: !ruby/object:Api::Resource::ReferenceLinks | ||
guides: | ||
'Using key value maps': 'https://cloud.google.com/apigee/docs/api-platform/cache/key-value-maps' | ||
api: 'https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.keyvaluemaps.entries/create' | ||
|
||
base_url: '{{env_keyvaluemap_id}}/entries' | ||
create_url: '{{env_keyvaluemap_id}}/entries' | ||
delete_url: '{{env_keyvaluemap_id}}/entries/{{name}}' | ||
self_link: '{{env_keyvaluemap_id}}/entries/{{name}}' | ||
import_format: | ||
['{{env_keyvaluemap_id}}/entries/{{name}}', '{{env_keyvaluemap_id}}/{{name}}'] | ||
skip_sweeper: true | ||
examples: | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: 'apigee_environment_keyvaluemaps_entries_basic' | ||
primary_resource_id: 'apigee_environment_keyvaluemaps_entries' | ||
test_env_vars: | ||
org_id: :ORG_ID | ||
billing_account: :BILLING_ACCT | ||
skip_test: true | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: 'apigee_environment_keyvaluemaps_entries_test' | ||
primary_resource_id: 'apigee_environment_keyvaluemaps_entries' | ||
test_env_vars: | ||
org_id: :ORG_ID | ||
billing_account: :BILLING_ACCT | ||
skip_docs: true | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: 'apigee_environment_keyvaluemaps_entries_beta_test' | ||
primary_resource_id: 'apigee_environment_keyvaluemaps_entries' | ||
test_env_vars: | ||
org_id: :ORG_ID | ||
billing_account: :BILLING_ACCT | ||
skip_docs: true | ||
min_version: beta | ||
timeouts: !ruby/object:Api::Timeouts | ||
insert_minutes: 1 | ||
delete_minutes: 1 | ||
immutable: true | ||
autogen_async: true | ||
custom_code: !ruby/object:Provider::Terraform::CustomCode | ||
custom_import: templates/terraform/custom_import/apigee_environment_keyvaluemaps_entries.go.erb | ||
parameters: | ||
- !ruby/object:Api::Type::String | ||
name: 'env_keyvaluemap_id' | ||
description: | | ||
The Apigee environment keyvalumaps Id associated with the Apigee environment, | ||
in the format `organizations/{{org_name}}/environments/{{env_name}}/keyvaluemaps/{{keyvaluemap_name}}`. | ||
required: true | ||
immutable: true | ||
url_param_only: true | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: 'name' | ||
description: | | ||
Required. Resource URI that can be used to identify the scope of the key value map entries. | ||
required: true | ||
immutable: true | ||
- !ruby/object:Api::Type::String | ||
name: 'value' | ||
description: | | ||
Required. Data or payload that is being retrieved and associated with the unique key. | ||
required: true | ||
immutable: true |
49 changes: 49 additions & 0 deletions
49
mmv1/templates/terraform/custom_create/apigee_environment_keyvaluemaps.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := make(map[string]interface{}) | ||
nameProp, err := expandApigeeEnvironmentKeyvaluemapsName(d.Get("name"), d, config) | ||
if err != nil { | ||
return err | ||
} else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { | ||
obj["name"] = nameProp | ||
} | ||
|
||
url, err := tpgresource.ReplaceVars(d, config, "{{ApigeeBasePath}}{{env_id}}/keyvaluemaps") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Creating new EnvironmentKeyvaluemaps: %#v", obj) | ||
billingProject := "" | ||
|
||
// err == nil indicates that the billing_project value was found | ||
if bp, err := tpgresource.GetBillingProject(d, config); err == nil { | ||
billingProject = bp | ||
} | ||
|
||
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "POST", | ||
Project: billingProject, | ||
RawURL: url, | ||
UserAgent: userAgent, | ||
Body: obj, | ||
Timeout: d.Timeout(schema.TimeoutCreate), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error creating EnvironmentKeyvaluemaps: %s", err) | ||
} | ||
|
||
// Store the ID now | ||
id, err := tpgresource.ReplaceVars(d, config, "{{env_id}}/keyvaluemaps/{{name}}") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
log.Printf("[DEBUG] Finished creating EnvironmentKeyvaluemaps %q: %#v", d.Id(), res) | ||
|
||
return resourceApigeeEnvironmentKeyvaluemapsRead(d, meta) |
18 changes: 18 additions & 0 deletions
18
mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
config := meta.(*transport_tpg.Config) | ||
|
||
// current import_formats cannot import fields with forward slashes in their value | ||
if err := tpgresource.ParseImportId([]string{ | ||
"(?P<env_id>.+)/keyvaluemaps/(?P<name>.+)", | ||
"(?P<env_id>.+)/(?P<name>.+)", | ||
}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Replace import id for the resource id | ||
id, err := tpgresource.ReplaceVars(d, config, "{{env_id}}/keyvaluemaps/{{name}}") | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return []*schema.ResourceData{d}, nil |
18 changes: 18 additions & 0 deletions
18
mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps_entries.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
config := meta.(*transport_tpg.Config) | ||
|
||
// current import_formats cannot import fields with forward slashes in their value | ||
if err := tpgresource.ParseImportId([]string{ | ||
"(?P<env_keyvaluemap_id>.+)/entries/(?P<name>.+)", | ||
"(?P<env_keyvaluemap_id>.+)/(?P<name>.+)", | ||
}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Replace import id for the resource id | ||
id, err := tpgresource.ReplaceVars(d, config, "{{env_keyvaluemap_id}}/entries/{{name}}") | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return []*schema.ResourceData{d}, nil |
10 changes: 10 additions & 0 deletions
10
mmv1/templates/terraform/decoders/apigee_environment_keyvaluemaps.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
config := meta.(*transport_tpg.Config) | ||
name, err := tpgresource.ReplaceVars(d, config, "{{name}}") | ||
if err != nil { | ||
return nil, err | ||
} | ||
res["name"] = name | ||
// "encrypted" field is retained for backward compatibility and the value of encrypted will always be true. Apigee X and hybrid do not support unencrypted key value maps. | ||
res["encrypted"] = true | ||
|
||
return res, nil |
55 changes: 55 additions & 0 deletions
55
mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_basic.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
data "google_client_config" "current" {} | ||
|
||
resource "google_compute_network" "apigee_network" { | ||
name = "apigee-network" | ||
} | ||
|
||
resource "google_compute_global_address" "apigee_range" { | ||
name = "apigee-range" | ||
purpose = "VPC_PEERING" | ||
address_type = "INTERNAL" | ||
prefix_length = 16 | ||
network = google_compute_network.apigee_network.id | ||
} | ||
|
||
resource "google_service_networking_connection" "apigee_vpc_connection" { | ||
network = google_compute_network.apigee_network.id | ||
service = "servicenetworking.googleapis.com" | ||
reserved_peering_ranges = [google_compute_global_address.apigee_range.name] | ||
} | ||
|
||
resource "google_apigee_organization" "apigee_org" { | ||
analytics_region = "us-central1" | ||
project_id = data.google_client_config.current.project | ||
authorized_network = google_compute_network.apigee_network.id | ||
depends_on = [google_service_networking_connection.apigee_vpc_connection] | ||
} | ||
|
||
resource "google_apigee_environment" "apigee_environment" { | ||
org_id = google_apigee_organization.apigee_org.id | ||
name = "tf-test-env" | ||
description = "Apigee Environment" | ||
display_name = "Apigee Environment" | ||
} | ||
|
||
resource "google_apigee_instance" "apigee_instance" { | ||
name = "tf-test-instance" | ||
location = "us-central1" | ||
org_id = google_apigee_organization.apigee_org.id | ||
} | ||
|
||
resource "google_apigee_instance_attachment" "apigee_instance_attachment" { | ||
instance_id = google_apigee_instance.apigee_instance.id | ||
environment = google_apigee_environment.apigee_environment.name | ||
} | ||
|
||
resource "google_apigee_environment_keyvaluemaps" "<%= ctx[:primary_resource_id] %>" { | ||
env_id = google_apigee_environment.apigee_environment.id | ||
name = "tf-test-env-kvms" | ||
depends_on = [ | ||
google_apigee_organization.apigee_org, | ||
google_apigee_environment.apigee_environment, | ||
google_apigee_instance.apigee_instance, | ||
google_apigee_instance_attachment.apigee_instance_attachment | ||
] | ||
} |
Oops, something went wrong.