Skip to content

Commit

Permalink
Add deploymentType and apiProxyType to ApigeeEnvironment (#5884) (#4177)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Apr 4, 2022
1 parent 5d8435c commit 6197971
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/5884.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
Add deploymentType and apiProxyType to ApigeeEnvironment.
```
69 changes: 69 additions & 0 deletions google-beta/resource_apigee_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
97 changes: 97 additions & 0 deletions google-beta/resource_apigee_environment_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions website/docs/r/apigee_environment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6197971

Please sign in to comment.