From 79c630b2545b3577932970e54a217d9f4e402154 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Mon, 4 Apr 2022 18:41:12 +0000 Subject: [PATCH] Add deploymentType and apiProxyType to ApigeeEnvironment (#5884) Signed-off-by: Modular Magician --- .changelog/5884.txt | 3 + google/resource_apigee_environment.go | 69 +++++++++++++ ...ource_apigee_environment_generated_test.go | 97 +++++++++++++++++++ .../docs/r/apigee_environment.html.markdown | 17 ++++ 4 files changed, 186 insertions(+) create mode 100644 .changelog/5884.txt diff --git a/.changelog/5884.txt b/.changelog/5884.txt new file mode 100644 index 00000000000..56fa42ab1e4 --- /dev/null +++ b/.changelog/5884.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +Add deploymentType and apiProxyType to ApigeeEnvironment. +``` diff --git a/google/resource_apigee_environment.go b/google/resource_apigee_environment.go index 10acc18d928..7f7f4cc9250 100644 --- a/google/resource_apigee_environment.go +++ b/google/resource_apigee_environment.go @@ -53,6 +53,29 @@ func resourceApigeeEnvironment() *schema.Resource { ForceNew: true, Description: `The Apigee Organization associated with the Apigee environment, in the format 'organizations/{{org_name}}'.`, + }, + "api_proxy_type": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + ValidateFunc: validateEnum([]string{"API_PROXY_TYPE_UNSPECIFIED", "PROGRAMMABLE", "CONFIGURABLE", ""}), + Description: `Optional. API Proxy type supported by the environment. The type can be set when creating +the Environment and cannot be changed. Possible values: ["API_PROXY_TYPE_UNSPECIFIED", "PROGRAMMABLE", "CONFIGURABLE"]`, + }, + "deployment_type": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + ValidateFunc: validateEnum([]string{"DEPLOYMENT_TYPE_UNSPECIFIED", "PROXY", "ARCHIVE", ""}), + Description: `Optional. Deployment type supported by the environment. The deployment type can be +set when creating the environment and cannot be changed. When you enable archive +deployment, you will be prevented from performing a subset of actions within the +environment, including: +Managing the deployment of API proxy or shared flow revisions; +Creating, updating, or deleting resource files; +Creating, updating, or deleting target servers. Possible values: ["DEPLOYMENT_TYPE_UNSPECIFIED", "PROXY", "ARCHIVE"]`, }, "description": { Type: schema.TypeString, @@ -97,6 +120,18 @@ func resourceApigeeEnvironmentCreate(d *schema.ResourceData, meta interface{}) e } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { obj["description"] = descriptionProp } + deploymentTypeProp, err := expandApigeeEnvironmentDeploymentType(d.Get("deployment_type"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("deployment_type"); !isEmptyValue(reflect.ValueOf(deploymentTypeProp)) && (ok || !reflect.DeepEqual(v, deploymentTypeProp)) { + obj["deploymentType"] = deploymentTypeProp + } + apiProxyTypeProp, err := expandApigeeEnvironmentApiProxyType(d.Get("api_proxy_type"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("api_proxy_type"); !isEmptyValue(reflect.ValueOf(apiProxyTypeProp)) && (ok || !reflect.DeepEqual(v, apiProxyTypeProp)) { + obj["apiProxyType"] = apiProxyTypeProp + } url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/environments") if err != nil { @@ -184,6 +219,12 @@ func resourceApigeeEnvironmentRead(d *schema.ResourceData, meta interface{}) err if err := d.Set("description", flattenApigeeEnvironmentDescription(res["description"], d, config)); err != nil { return fmt.Errorf("Error reading Environment: %s", err) } + if err := d.Set("deployment_type", flattenApigeeEnvironmentDeploymentType(res["deploymentType"], d, config)); err != nil { + return fmt.Errorf("Error reading Environment: %s", err) + } + if err := d.Set("api_proxy_type", flattenApigeeEnvironmentApiProxyType(res["apiProxyType"], d, config)); err != nil { + return fmt.Errorf("Error reading Environment: %s", err) + } return nil } @@ -216,6 +257,18 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { obj["description"] = descriptionProp } + deploymentTypeProp, err := expandApigeeEnvironmentDeploymentType(d.Get("deployment_type"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("deployment_type"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, deploymentTypeProp)) { + obj["deploymentType"] = deploymentTypeProp + } + apiProxyTypeProp, err := expandApigeeEnvironmentApiProxyType(d.Get("api_proxy_type"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("api_proxy_type"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, apiProxyTypeProp)) { + obj["apiProxyType"] = apiProxyTypeProp + } url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/environments/{{name}}") if err != nil { @@ -344,6 +397,14 @@ func flattenApigeeEnvironmentDescription(v interface{}, d *schema.ResourceData, return v } +func flattenApigeeEnvironmentDeploymentType(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenApigeeEnvironmentApiProxyType(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + func expandApigeeEnvironmentName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } @@ -355,3 +416,11 @@ func expandApigeeEnvironmentDisplayName(v interface{}, d TerraformResourceData, func expandApigeeEnvironmentDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } + +func expandApigeeEnvironmentDeploymentType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandApigeeEnvironmentApiProxyType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google/resource_apigee_environment_generated_test.go b/google/resource_apigee_environment_generated_test.go index bd3b90ecb03..d626a6444bb 100644 --- a/google/resource_apigee_environment_generated_test.go +++ b/google/resource_apigee_environment_generated_test.go @@ -118,6 +118,103 @@ resource "google_apigee_environment" "apigee_environment" { `, context) } +func TestAccApigeeEnvironment_apigeeEnvironmentBasicDeploymentApiproxyTypeTestExample(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: testAccProviders, + 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 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 testAccCheckApigeeEnvironmentDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { for name, rs := range s.RootModule().Resources { diff --git a/website/docs/r/apigee_environment.html.markdown b/website/docs/r/apigee_environment.html.markdown index d8882b91fe8..5998edd16c2 100644 --- a/website/docs/r/apigee_environment.html.markdown +++ b/website/docs/r/apigee_environment.html.markdown @@ -96,6 +96,23 @@ The following arguments are supported: (Optional) Description of the environment. +* `deployment_type` - + (Optional) + Optional. Deployment type supported by the environment. The deployment type can be + set when creating the environment and cannot be changed. When you enable archive + deployment, you will be prevented from performing a subset of actions within the + environment, including: + Managing the deployment of API proxy or shared flow revisions; + Creating, updating, or deleting resource files; + Creating, updating, or deleting target servers. + Possible values are `DEPLOYMENT_TYPE_UNSPECIFIED`, `PROXY`, and `ARCHIVE`. + +* `api_proxy_type` - + (Optional) + Optional. API Proxy type supported by the environment. The type can be set when creating + the Environment and cannot be changed. + Possible values are `API_PROXY_TYPE_UNSPECIFIED`, `PROGRAMMABLE`, and `CONFIGURABLE`. + ## Attributes Reference