Skip to content

Commit

Permalink
Megan compute address purpose
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
megan07 authored and modular-magician committed Sep 4, 2019
1 parent ce80031 commit ab91163
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
24 changes: 24 additions & 0 deletions google-beta/resource_compute_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
34 changes: 34 additions & 0 deletions google-beta/resource_compute_address_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
21 changes: 21 additions & 0 deletions website/docs/r/compute_address.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ resource "google_compute_address" "internal_with_subnet_and_address" {
region = "us-central1"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=address_with_gce_endpoint&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## 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"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=instance_with_ip&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ab91163

Please sign in to comment.