-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for nodeConfig in ApigeeEnvironment (#6349)
- Loading branch information
Showing
4 changed files
with
347 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
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
127 changes: 127 additions & 0 deletions
127
mmv1/templates/terraform/examples/apigee_environment_nodeconfig_test.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,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" | ||
} | ||
} |
180 changes: 180 additions & 0 deletions
180
mmv1/third_party/terraform/resources/resource_apigee_environment_nodeconfig_test.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,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 -%> |