Skip to content

Commit

Permalink
Add support for nodeConfig in ApigeeEnvironment (#6349)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuchenma authored Aug 25, 2022
1 parent 63a8722 commit 262496e
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mmv1/products/apigee/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ objects:
base_url: 'environments'
create_url: '{{org_id}}/environments'
self_link: '{{org_id}}/environments/{{name}}'
update_url: '{{org_id}}/environments/{{name}}'
update_verb: :PATCH
update_mask: true
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
path: 'name'
Expand Down Expand Up @@ -294,6 +297,7 @@ objects:
description: |
The resource ID of the environment.
required: true
input: true
- !ruby/object:Api::Type::String
name: 'displayName'
description: |
Expand Down Expand Up @@ -331,6 +335,29 @@ objects:
- "PROGRAMMABLE"
- "CONFIGURABLE"
input: true
- !ruby/object:Api::Type::NestedObject
name: 'nodeConfig'
description: |
NodeConfig for setting the min/max number of nodes associated with the environment.
properties:
- !ruby/object:Api::Type::String
name: 'minNodeCount'
description: |
The minimum total number of gateway nodes that the is reserved for all instances that
has the specified environment. If not specified, the default is determined by the
recommended minimum number of nodes for that gateway.
- !ruby/object:Api::Type::String
name: 'maxNodeCount'
description: |
The maximum total number of gateway nodes that the is reserved for all instances that
has the specified environment. If not specified, the default is determined by the
recommended maximum number of nodes for that gateway.
- !ruby/object:Api::Type::String
name: 'currentAggregateNodeCount'
description: |
The current total number of gateway nodes that each environment currently has across
all instances.
output: true
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Creating an environment':
Expand Down
13 changes: 13 additions & 0 deletions mmv1/products/apigee/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,24 @@ overrides: !ruby/object:Overrides::ResourceOverrides
skip_docs: true
# Resource creation race
skip_vcr: true
- !ruby/object:Provider::Terraform::Examples
name: "apigee_environment_nodeconfig_test"
primary_resource_id: "apigee_environment"
primary_resource_name: "fmt.Sprintf(\"organizations/tf-test%s\", context[\"random_suffix\"]), fmt.Sprintf(\"tf-test%s\", context[\"random_suffix\"])"
test_env_vars:
org_id: :ORG_ID
billing_account: :BILLING_ACCT
skip_docs: true
min_version: beta
# Resource creation race
skip_vcr: true
properties:
deploymentType: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
apiProxyType: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
nodeConfig: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 30
delete_minutes: 30
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
resource "google_project" "project" {
provider = google-beta

project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "<%= ctx[:test_env_vars]['org_id'] %>"
billing_account = "<%= ctx[:test_env_vars]['billing_account'] %>"
}

resource "google_project_service" "apigee" {
provider = google-beta

project = google_project.project.project_id
service = "apigee.googleapis.com"
}

resource "google_project_service" "compute" {
provider = google-beta

project = google_project.project.project_id
service = "compute.googleapis.com"
}

resource "google_project_service" "servicenetworking" {
provider = google-beta

project = google_project.project.project_id
service = "servicenetworking.googleapis.com"
}

resource "google_project_service" "kms" {
provider = google-beta

project = google_project.project.project_id
service = "cloudkms.googleapis.com"
}

resource "google_compute_network" "apigee_network" {
provider = google-beta

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

resource "google_compute_global_address" "apigee_range" {
provider = google-beta

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" {
provider = google-beta

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_kms_key_ring" "apigee_keyring" {
provider = google-beta

name = "apigee-keyring"
location = "us-central1"
project = google_project.project.project_id
depends_on = [google_project_service.kms]
}

resource "google_kms_crypto_key" "apigee_key" {
provider = google-beta

name = "apigee-key"
key_ring = google_kms_key_ring.apigee_keyring.id
}

resource "google_project_service_identity" "apigee_sa" {
provider = google-beta

project = google_project.project.project_id
service = google_project_service.apigee.service
}

resource "google_kms_crypto_key_iam_binding" "apigee_sa_keyuser" {
provider = google-beta

crypto_key_id = google_kms_crypto_key.apigee_key.id
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"

members = [
"serviceAccount:${google_project_service_identity.apigee_sa.email}",
]
}

resource "google_apigee_organization" "apigee_org" {
provider = google-beta

analytics_region = "us-central1"
project_id = google_project.project.project_id
authorized_network = google_compute_network.apigee_network.id
billing_type = "PAYG"
runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id

depends_on = [
google_service_networking_connection.apigee_vpc_connection,
google_project_service.apigee,
google_kms_crypto_key_iam_binding.apigee_sa_keyuser,
]
}

resource "google_apigee_environment" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta

org_id = google_apigee_organization.apigee_org.id
name = "tf-test%{random_suffix}"
description = "Apigee Environment"
display_name = "tf-test%{random_suffix}"
node_config {
min_node_count = "3"
max_node_count = "5"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccApigeeEnvironment_apigeeEnvironmentNodeconfigTestExampleUpdate(t *testing.T) {
skipIfVcr(t)
t.Parallel()

context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"billing_account": getTestBillingAccountFromEnv(t),
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckApigeeEnvironmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccApigeeEnvironment_apigeeEnvironmentNodeconfigTestExample(context),
},
{
ResourceName: "google_apigee_environment.apigee_environment",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"org_id"},
},
{
Config: testAccApigeeEnvironment_apigeeEnvironmentNodeconfigTestExampleUpdate(context),
},
{
ResourceName: "google_apigee_environment.apigee_environment",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"org_id"},
},
},
})
}

func testAccApigeeEnvironment_apigeeEnvironmentNodeconfigTestExampleUpdate(context map[string]interface{}) string {
return Nprintf(`
resource "google_project" "project" {
provider = google-beta

project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}

resource "google_project_service" "apigee" {
provider = google-beta

project = google_project.project.project_id
service = "apigee.googleapis.com"
}

resource "google_project_service" "compute" {
provider = google-beta

project = google_project.project.project_id
service = "compute.googleapis.com"
}

resource "google_project_service" "servicenetworking" {
provider = google-beta

project = google_project.project.project_id
service = "servicenetworking.googleapis.com"
}

resource "google_project_service" "kms" {
provider = google-beta

project = google_project.project.project_id
service = "cloudkms.googleapis.com"
}

resource "google_compute_network" "apigee_network" {
provider = google-beta

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

resource "google_compute_global_address" "apigee_range" {
provider = google-beta

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" {
provider = google-beta

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_kms_key_ring" "apigee_keyring" {
provider = google-beta

name = "apigee-keyring"
location = "us-central1"
project = google_project.project.project_id
depends_on = [google_project_service.kms]
}

resource "google_kms_crypto_key" "apigee_key" {
provider = google-beta

name = "apigee-key"
key_ring = google_kms_key_ring.apigee_keyring.id
}

resource "google_project_service_identity" "apigee_sa" {
provider = google-beta

project = google_project.project.project_id
service = google_project_service.apigee.service
}

resource "google_kms_crypto_key_iam_binding" "apigee_sa_keyuser" {
provider = google-beta

crypto_key_id = google_kms_crypto_key.apigee_key.id
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"

members = [
"serviceAccount:${google_project_service_identity.apigee_sa.email}",
]
}

resource "google_apigee_organization" "apigee_org" {
provider = google-beta

analytics_region = "us-central1"
project_id = google_project.project.project_id
authorized_network = google_compute_network.apigee_network.id
billing_type = "PAYG"
runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id

depends_on = [
google_service_networking_connection.apigee_vpc_connection,
google_project_service.apigee,
google_kms_crypto_key_iam_binding.apigee_sa_keyuser,
]
}

resource "google_apigee_environment" "apigee_environment" {
provider = google-beta

org_id = google_apigee_organization.apigee_org.id
name = "tf-test%{random_suffix}"
description = "Apigee Environment"
display_name = "tf-test%{random_suffix}"
node_config {
min_node_count = "4"
max_node_count = "5"
}
}
`, context)
}

<% end -%>

0 comments on commit 262496e

Please sign in to comment.