Skip to content

Commit

Permalink
Added new Apigee resource /v1/organizations/<apigee_org>/environments…
Browse files Browse the repository at this point in the history
…/<apigee_env>/addonsConfig (#12616)

Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
  • Loading branch information
sharmajai09 and melinath authored Jan 8, 2025
1 parent c1ae9f3 commit 716d7b6
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
64 changes: 64 additions & 0 deletions mmv1/products/apigee/EnvironmentAddonsConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2024 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.

---
name: 'EnvironmentAddonsConfig'
api_resource_type_kind: AddonsConfig
description: Enable/Disable add-ons for an Apigee environment.
references:
guides:
'Enable Analytics Add-On': 'https://cloud.google.com/apigee/docs/api-platform/reference/manage-analytics-add-on'
api: 'https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments.addonsConfig/setAddonEnablement'
docs:
base_url: '{{env_id}}'
self_link: '{{env_id}}/addonsConfig'
create_url: '{{env_id}}/addonsConfig:setAddonEnablement'
update_url: '{{env_id}}/addonsConfig:setAddonEnablement'
update_verb: 'POST'
exclude_delete: true
timeouts:
insert_minutes: 5
update_minutes: 5
async:
actions: ['create', 'update']
type: 'OpAsync'
operation:
base_url: '{{op_id}}'
import_format:
- '{{env_id}}'
id_format: '{{env_id}}'
custom_code:
custom_import: 'templates/terraform/custom_import/apigee_env_addons.go.tmpl'
decoder: 'templates/terraform/decoders/apigee_env_addons.go.tmpl'
examples:
- name: 'apigee_env_addons_analytics_test'
primary_resource_id: 'apigee_org_addons'
test_env_vars:
org_id: 'ORG_ID'
billing_account: 'BILLING_ACCT'
exclude_docs: true
- name: 'apigee_env_addons_enable_analytics'
exclude_test: true
parameters:
- name: 'envId'
type: String
description: |
The Apigee environment group associated with the Apigee environment,
in the format `organizations/{{org_name}}/environments/{{env_name}}`.
url_param_only: true
required: true
immutable: true
properties:
- name: 'analyticsEnabled'
type: Boolean
description: Flag to enable/disable Analytics.
14 changes: 14 additions & 0 deletions mmv1/templates/terraform/custom_import/apigee_env_addons.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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>.+)"}, d, config); err != nil {
return nil, err
}

id := d.Get("env_id").(string)
nameParts := strings.Split(id, "/")
if len(nameParts) != 4 {
return nil, fmt.Errorf("env is expected to have shape organizations/{{"{{"}}org_id{{"}}"}}/environments/{{"{{"}}env{{"}}"}}, got %s instead", id)
}
d.SetId(id)
return []*schema.ResourceData{d}, nil
2 changes: 2 additions & 0 deletions mmv1/templates/terraform/decoders/apigee_env_addons.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
res["analyticsEnabled"] = res["analyticsConfig"].(map[string]interface{})["enabled"]
return res, nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
resource "google_project" "project" {
project_id = "tf-test-%{random_suffix}"
name = "tf-test-%{random_suffix}"
org_id = "{{index $.TestEnvVars "org_id"}}"
billing_account = "{{index $.TestEnvVars "billing_account"}}"
deletion_policy = "DELETE"
}

resource "google_project_service" "apigee" {
project = google_project.project.project_id
service = "apigee.googleapis.com"
}

resource "google_project_service" "compute" {
project = google_project.project.project_id
service = "compute.googleapis.com"
depends_on = [google_project_service.servicenetworking ]
}

resource "google_project_service" "servicenetworking" {
project = google_project.project.project_id
service = "servicenetworking.googleapis.com"
depends_on = [google_project_service.apigee]
}

resource "google_compute_network" "apigee_network" {
name = "apigee-network"
project = google_project.project.project_id
depends_on = [google_project_service.compute]
}

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
project = google_project.project.project_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]
depends_on = [google_project_service.servicenetworking]
}

resource "google_apigee_organization" "apigee_org" {
analytics_region = "us-central1"
project_id = google_project.project.project_id
authorized_network = google_compute_network.apigee_network.id
billing_type = "PAYG"
depends_on = [
google_service_networking_connection.apigee_vpc_connection,
google_project_service.apigee
]
}

resource "google_apigee_environment" "{{$.PrimaryResourceId}}" {
org_id = google_apigee_organization.apigee_org.id
name = "tf-test%{random_suffix}"
type = "COMPREHENSIVE"
description = "Apigee Environment"
display_name = "environment-1"
}

resource "google_apigee_environment_addons_config" "{{$.PrimaryResourceId}}" {
env_id = google_apigee_environment.{{$.PrimaryResourceId}}.id
analytics_enabled = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "google_apigee_organization" "apigee_org" {
analytics_region = "us-central1"
project_id = google_project.project.project_id
authorized_network = google_compute_network.apigee_network.id
billing_type = "PAYG"
}

resource "google_apigee_environment" "{{$.PrimaryResourceId}}" {
org_id = google_apigee_organization.apigee_org.id
name = "tf-test%{random_suffix}"
type = "COMPREHENSIVE"
description = "Apigee Environment"
display_name = "environment-1"
}

resource "google_apigee_environment_addons_config" "{{$.PrimaryResourceId}}" {
env_id = google_apigee_environment.{{$.PrimaryResourceId}}.id
analytics_enabled = true
}

0 comments on commit 716d7b6

Please sign in to comment.