diff --git a/google-beta/resource_compute_address.go b/google-beta/resource_compute_address.go index 3cc8a856677..c99caecc5d7 100644 --- a/google-beta/resource_compute_address.go +++ b/google-beta/resource_compute_address.go @@ -79,6 +79,13 @@ func resourceComputeAddress() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"PREMIUM", "STANDARD", ""}, false), }, + "purpose": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"GCE_ENDPOINT", ""}, false), + }, "region": { Type: schema.TypeString, Computed: true, @@ -150,6 +157,12 @@ func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) erro } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { obj["name"] = nameProp } + purposeProp, err := expandComputeAddressPurpose(d.Get("purpose"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("purpose"); !isEmptyValue(reflect.ValueOf(purposeProp)) && (ok || !reflect.DeepEqual(v, purposeProp)) { + obj["purpose"] = purposeProp + } networkTierProp, err := expandComputeAddressNetworkTier(d.Get("network_tier"), d, config) if err != nil { return err @@ -301,6 +314,9 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error if err := d.Set("name", flattenComputeAddressName(res["name"], d)); err != nil { return fmt.Errorf("Error reading Address: %s", err) } + if err := d.Set("purpose", flattenComputeAddressPurpose(res["purpose"], d)); err != nil { + return fmt.Errorf("Error reading Address: %s", err) + } if err := d.Set("network_tier", flattenComputeAddressNetworkTier(res["networkTier"], d)); err != nil { return fmt.Errorf("Error reading Address: %s", err) } @@ -466,6 +482,10 @@ func flattenComputeAddressName(v interface{}, d *schema.ResourceData) interface{ return v } +func flattenComputeAddressPurpose(v interface{}, d *schema.ResourceData) interface{} { + return v +} + func flattenComputeAddressNetworkTier(v interface{}, d *schema.ResourceData) interface{} { return v } @@ -512,6 +532,10 @@ func expandComputeAddressName(v interface{}, d TerraformResourceData, config *Co return v, nil } +func expandComputeAddressPurpose(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandComputeAddressNetworkTier(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/google-beta/resource_compute_address_generated_test.go b/google-beta/resource_compute_address_generated_test.go index 3ec47b14f71..b94aece3917 100644 --- a/google-beta/resource_compute_address_generated_test.go +++ b/google-beta/resource_compute_address_generated_test.go @@ -103,6 +103,40 @@ resource "google_compute_address" "internal_with_subnet_and_address" { `, context) } +func TestAccComputeAddress_addressWithGceEndpointExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeAddressDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeAddress_addressWithGceEndpointExample(context), + }, + { + ResourceName: "google_compute_address.internal_with_gce_endpoint", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeAddress_addressWithGceEndpointExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_address" "internal_with_gce_endpoint" { + name = "my-internal-address-%{random_suffix}" + address_type = "INTERNAL" + purpose = "GCE_ENDPOINT" +} +`, context) +} + func TestAccComputeAddress_instanceWithIpExample(t *testing.T) { t.Parallel() diff --git a/website/docs/r/compute_address.html.markdown b/website/docs/r/compute_address.html.markdown index d264f15e838..c54629a259b 100644 --- a/website/docs/r/compute_address.html.markdown +++ b/website/docs/r/compute_address.html.markdown @@ -84,6 +84,21 @@ resource "google_compute_address" "internal_with_subnet_and_address" { region = "us-central1" } ``` +
+ + Open in Cloud Shell + +
+## Example Usage - Address With Gce Endpoint + + +```hcl +resource "google_compute_address" "internal_with_gce_endpoint" { + name = "my-internal-address-" + address_type = "INTERNAL" + purpose = "GCE_ENDPOINT" +} +```
Open in Cloud Shell @@ -156,6 +171,12 @@ The following arguments are supported: (Optional) An optional description of this resource. +* `purpose` - + (Optional) + The purpose of this resource, which can be one of the following values: + - GCE_ENDPOINT for addresses that are used by VM instances, alias IP ranges, internal load balancers, and similar resources. + This should only be set when using an Internal address. + * `network_tier` - (Optional) The networking tier used for configuring this address. This field can