Skip to content

Commit

Permalink
Add support for configuring forward proxy in Apigee Environment. (#10…
Browse files Browse the repository at this point in the history
…457) (#7260)

[upstream:43c57add8f62100fe103d4ee3cc19200e550a8cc]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Apr 18, 2024
1 parent 8736281 commit a01d7e0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/10457.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
apigee: added `forward_proxy_uri` field to `google_apigee_environment`
```
32 changes: 32 additions & 0 deletions google-beta/services/apigee/resource_apigee_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ Creating, updating, or deleting target servers. Possible values: ["DEPLOYMENT_TY
ForceNew: true,
Description: `Display name of the environment.`,
},
"forward_proxy_uri": {
Type: schema.TypeString,
Optional: true,
Description: `Optional. URI of the forward proxy to be applied to the runtime instances in this environment. Must be in the format of {scheme}://{hostname}:{port}. Note that the scheme must be one of "http" or "https", and the port must be supplied.`,
},
"node_config": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -194,6 +199,12 @@ func resourceApigeeEnvironmentCreate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("type"); !tpgresource.IsEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) {
obj["type"] = typeProp
}
forwardProxyUriProp, err := expandApigeeEnvironmentForwardProxyUri(d.Get("forward_proxy_uri"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("forward_proxy_uri"); !tpgresource.IsEmptyValue(reflect.ValueOf(forwardProxyUriProp)) && (ok || !reflect.DeepEqual(v, forwardProxyUriProp)) {
obj["forwardProxyUri"] = forwardProxyUriProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/environments")
if err != nil {
Expand Down Expand Up @@ -312,6 +323,9 @@ func resourceApigeeEnvironmentRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("type", flattenApigeeEnvironmentType(res["type"], d, config)); err != nil {
return fmt.Errorf("Error reading Environment: %s", err)
}
if err := d.Set("forward_proxy_uri", flattenApigeeEnvironmentForwardProxyUri(res["forwardProxyUri"], d, config)); err != nil {
return fmt.Errorf("Error reading Environment: %s", err)
}

return nil
}
Expand All @@ -338,6 +352,12 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("type"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, typeProp)) {
obj["type"] = typeProp
}
forwardProxyUriProp, err := expandApigeeEnvironmentForwardProxyUri(d.Get("forward_proxy_uri"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("forward_proxy_uri"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, forwardProxyUriProp)) {
obj["forwardProxyUri"] = forwardProxyUriProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/environments/{{name}}")
if err != nil {
Expand All @@ -355,6 +375,10 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
if d.HasChange("type") {
updateMask = append(updateMask, "type")
}

if d.HasChange("forward_proxy_uri") {
updateMask = append(updateMask, "forwardProxyUri")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -546,6 +570,10 @@ func flattenApigeeEnvironmentType(v interface{}, d *schema.ResourceData, config
return v
}

func flattenApigeeEnvironmentForwardProxyUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandApigeeEnvironmentName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -614,3 +642,7 @@ func expandApigeeEnvironmentNodeConfigCurrentAggregateNodeCount(v interface{}, d
func expandApigeeEnvironmentType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandApigeeEnvironmentForwardProxyUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ resource "google_apigee_environment" "apigee_environment" {
`, context)
}

func TestAccApigeeEnvironment_apigeeEnvironmentTypeTestExample(t *testing.T) {
func TestAccApigeeEnvironment_apigeeEnvironmentPatchUpdateTestExample(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()

Expand All @@ -239,7 +239,7 @@ func TestAccApigeeEnvironment_apigeeEnvironmentTypeTestExample(t *testing.T) {
CheckDestroy: testAccCheckApigeeEnvironmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccApigeeEnvironment_apigeeEnvironmentTypeTestExample(context),
Config: testAccApigeeEnvironment_apigeeEnvironmentPatchUpdateTestExample(context),
},
{
ResourceName: "google_apigee_environment.apigee_environment",
Expand All @@ -251,7 +251,7 @@ func TestAccApigeeEnvironment_apigeeEnvironmentTypeTestExample(t *testing.T) {
})
}

func testAccApigeeEnvironment_apigeeEnvironmentTypeTestExample(context map[string]interface{}) string {
func testAccApigeeEnvironment_apigeeEnvironmentPatchUpdateTestExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_project" "project" {
provider = google-beta
Expand Down Expand Up @@ -374,6 +374,7 @@ resource "google_apigee_environment" "apigee_environment" {
description = "Apigee Environment"
display_name = "tf-test%{random_suffix}"
type = "COMPREHENSIVE"
forward_proxy_uri = "http://test:123"
}
`, context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
)

func TestAccApigeeEnvironment_apigeeEnvironmentTypeTestExampleUpdate(t *testing.T) {
func TestAccApigeeEnvironment_apigeeEnvironmentPatchUpdateTestExampleUpdate(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()

Expand All @@ -26,7 +26,7 @@ func TestAccApigeeEnvironment_apigeeEnvironmentTypeTestExampleUpdate(t *testing.
CheckDestroy: testAccCheckApigeeEnvironmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccApigeeEnvironment_apigeeEnvironmentTypeTestExample(context),
Config: testAccApigeeEnvironment_apigeeEnvironmentPatchUpdateTestExample(context),
},
{
ResourceName: "google_apigee_environment.apigee_environment",
Expand All @@ -35,7 +35,7 @@ func TestAccApigeeEnvironment_apigeeEnvironmentTypeTestExampleUpdate(t *testing.
ImportStateVerifyIgnore: []string{"org_id"},
},
{
Config: testAccApigeeEnvironment_apigeeEnvironmentTypeTestExampleUpdate(context),
Config: testAccApigeeEnvironment_apigeeEnvironmentPatchUpdateTestExampleUpdate(context),
},
{
ResourceName: "google_apigee_environment.apigee_environment",
Expand All @@ -47,7 +47,7 @@ func TestAccApigeeEnvironment_apigeeEnvironmentTypeTestExampleUpdate(t *testing.
})
}

func testAccApigeeEnvironment_apigeeEnvironmentTypeTestExampleUpdate(context map[string]interface{}) string {
func testAccApigeeEnvironment_apigeeEnvironmentPatchUpdateTestExampleUpdate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_project" "project" {
provider = google-beta
Expand Down Expand Up @@ -170,6 +170,7 @@ resource "google_apigee_environment" "apigee_environment" {
description = "Apigee Environment"
display_name = "tf-test%{random_suffix}"
type = "INTERMEDIATE"
forward_proxy_uri = "http://test:456"
}
`, context)
}
4 changes: 4 additions & 0 deletions website/docs/r/apigee_environment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ The following arguments are supported:
An Apigee org can support heterogeneous Environments.
Possible values are: `ENVIRONMENT_TYPE_UNSPECIFIED`, `BASE`, `INTERMEDIATE`, `COMPREHENSIVE`.

* `forward_proxy_uri` -
(Optional)
Optional. URI of the forward proxy to be applied to the runtime instances in this environment. Must be in the format of {scheme}://{hostname}:{port}. Note that the scheme must be one of "http" or "https", and the port must be supplied.


<a name="nested_node_config"></a>The `node_config` block supports:

Expand Down

0 comments on commit a01d7e0

Please sign in to comment.