blob: c4e858ec62efc2e3c5719d44fa0ff2aeece2072d [file] [log] [blame]
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------
package apigee_test
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)
func TestAccApigeeEnvironment_apigeeEnvironmentBasicTestExample(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()
context := map[string]interface{}{
"org_id": envvar.GetTestOrgFromEnv(t),
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckApigeeEnvironmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccApigeeEnvironment_apigeeEnvironmentBasicTestExample(context),
},
{
ResourceName: "google_apigee_environment.apigee_environment",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"org_id"},
},
},
})
}
func testAccApigeeEnvironment_apigeeEnvironmentBasicTestExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_project" "project" {
project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}
resource "google_project_service" "apigee" {
project = google_project.project.project_id
service = "apigee.googleapis.com"
}
resource "google_project_service" "servicenetworking" {
project = google_project.project.project_id
service = "servicenetworking.googleapis.com"
depends_on = [google_project_service.apigee]
}
resource "google_project_service" "compute" {
project = google_project.project.project_id
service = "compute.googleapis.com"
depends_on = [google_project_service.servicenetworking]
}
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
depends_on = [
google_service_networking_connection.apigee_vpc_connection,
google_project_service.apigee,
]
}
resource "google_apigee_environment" "apigee_environment" {
org_id = google_apigee_organization.apigee_org.id
name = "tf-test%{random_suffix}"
description = "Apigee Environment"
display_name = "environment-1"
}
`, context)
}
func TestAccApigeeEnvironment_apigeeEnvironmentBasicDeploymentApiproxyTypeTestExample(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()
context := map[string]interface{}{
"org_id": envvar.GetTestOrgFromEnv(t),
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckApigeeEnvironmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccApigeeEnvironment_apigeeEnvironmentBasicDeploymentApiproxyTypeTestExample(context),
},
{
ResourceName: "google_apigee_environment.apigee_environment",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"org_id"},
},
},
})
}
func testAccApigeeEnvironment_apigeeEnvironmentBasicDeploymentApiproxyTypeTestExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_project" "project" {
project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}
resource "google_project_service" "apigee" {
project = google_project.project.project_id
service = "apigee.googleapis.com"
}
resource "google_project_service" "servicenetworking" {
project = google_project.project.project_id
service = "servicenetworking.googleapis.com"
depends_on = [google_project_service.apigee]
}
resource "google_project_service" "compute" {
project = google_project.project.project_id
service = "compute.googleapis.com"
depends_on = [google_project_service.servicenetworking]
}
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
depends_on = [
google_service_networking_connection.apigee_vpc_connection,
google_project_service.apigee,
]
}
resource "google_apigee_environment" "apigee_environment" {
org_id = google_apigee_organization.apigee_org.id
name = "tf-test%{random_suffix}"
description = "Apigee Environment"
display_name = "environment-1"
deployment_type = "PROXY"
api_proxy_type = "PROGRAMMABLE"
}
`, context)
}
func TestAccApigeeEnvironment_apigeeEnvironmentTypeTestExample(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()
context := map[string]interface{}{
"org_id": envvar.GetTestOrgFromEnv(t),
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckApigeeEnvironmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccApigeeEnvironment_apigeeEnvironmentTypeTestExample(context),
},
{
ResourceName: "google_apigee_environment.apigee_environment",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"org_id"},
},
},
})
}
func testAccApigeeEnvironment_apigeeEnvironmentTypeTestExample(context map[string]interface{}) string {
return acctest.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_member" "apigee_sa_keyuser" {
provider = google-beta
crypto_key_id = google_kms_crypto_key.apigee_key.id
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
member = "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_member.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}"
type = "COMPREHENSIVE"
}
`, context)
}
func testAccCheckApigeeEnvironmentDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_apigee_environment" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}
config := acctest.GoogleProviderConfig(t)
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{ApigeeBasePath}}{{org_id}}/environments/{{name}}")
if err != nil {
return err
}
billingProject := ""
if config.BillingProject != "" {
billingProject = config.BillingProject
}
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: config.UserAgent,
})
if err == nil {
return fmt.Errorf("ApigeeEnvironment still exists at %s", url)
}
}
return nil
}
}