Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new Apigee resource /v1/organizations/<apigee_org>/environments/<apigee_env>/addonsConfig #12616

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
'Enable ApiSecurity Add-On': 'https://cloud.google.com/apigee/docs/api-platform/reference/manage-security-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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need addonsConfig, since it's not a "real" resource - leaving it off better matches the AddonsConfig resource behavior.

Suggested change
self_link: '{{env_id}}/addonsConfig'
self_link: '{{env_id}}'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove '/addonsConfig' from self_link Get resource fails and I get error like "inplace update not happened. expected analytics_enabled True found False"

create_url: '{{env_id}}/addonsConfig:setAddonEnablement'
update_url: '{{env_id}}/addonsConfig:setAddonEnablement'
update_verb: 'POST'
exclude_delete: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you think about sending a POST request to unset AddonEnablement on delete? This would match the behavior of AddonsConfig.

Suggested change
exclude_delete: true
delete_url: '{{env_id}}/addonsConfig:setAddonEnablement'
delete_verb: 'POST'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible with this api because Delete operation test sends null object as input to api. AddonsConfig api allows null object as input but this api doesn't allow.

sharmajai@jai-desktop:~/magic-modules$ curl -H "$AUTH" -H "Content-Type: application/json" -X POST "https://apigee.googleapis.com/v1/organizations/test-apigee-org:setAddons"
{
  "name": "organizations/test-apigee-org/operations/4296f43d-9fa1-4341-bd00-d8221852dafa",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.apigee.v1.OperationMetadata",
    "operationType": "UPDATE",
    "targetResourceName": "organizations/test-apigee-org",
    "state": "IN_PROGRESS"
  }
}
sharmajai@jai-desktop:~/magic-modules$ curl -H "$AUTH" "https://apigee.googleapis.com/v1/organizations/test-apigee-org/operations/4296f43d-9fa1-4341-bd00-d8221852dafa"
{
  "name": "organizations/test-apigee-org/operations/4296f43d-9fa1-4341-bd00-d8221852dafa",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.apigee.v1.OperationMetadata",
    "operationType": "UPDATE",
    "targetResourceName": "organizations/test-apigee-org",
    "state": "FINISHED"
  },
  "done": true
}
sharmajai@jai-desktop:~/magic-modules$ curl -H "$AUTH" -H "Content-Type: application/json" -X POST "https://apigee.googleapis.com/v1/organizations/test-apigee-org/environments/test/addonsConfig:setAddonEnablement"
{
  "error": {
    "code": 400,
    "message": "addon enablement request \u003cnil\u003e is not supported",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.RequestInfo",
        "requestId": "2385760879381416100"
      },
      {
        "@type": "type.googleapis.com/google.rpc.DebugInfo",
        "detail": "[ORIGINAL ERROR] generic::invalid_argument: addon enablement request \u003cnil\u003e is not supported [google.rpc.error_details_ext] { message: \"addon enablement request \u003cnil\u003e is not supported\" details { [type.googleapis.com/google.rpc.RequestInfo] { request_id: \"2385760879381416100\" } } }"
      }
    ]
  }
}

timeouts:
insert_minutes: 5
update_minutes: 5
Comment on lines +31 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to double-check that this is desired; we usually only lengthen the timeouts, not shorten them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 minute timeout is ok. This api usually takes < 1 minute.

async:
actions: ['create', 'update']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(if delete support is added)

Suggested change
actions: ['create', 'update']
actions: ['create', 'update', 'delete']

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous comment on supporting delete

type: 'OpAsync'
operation:
base_url: '{{op_id}}'
import_format:
- '{{env_id}}/addonsConfig'
custom_code:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(if delete support is added) you'll also need a test_check_destroy similar to AddonsConfig

test_check_destroy: 'templates/terraform/custom_check_destroy/apigee_addons_override.go.tmpl'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous comment on supporting delete

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be at least one docs example; you could add a doc-only example similar to AddonsConfig:

- name: 'apigee_addons_basic'
exclude_test: true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

- 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>.+)/addonsConfig"}, d, config); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err := tpgresource.ParseImportId([]string{"(?P<env_id>.+)/addonsConfig"}, d, config); err != nil {
if err := tpgresource.ParseImportId([]string{"(?P<env_id>.+)"}, d, config); err != nil {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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,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
}