Skip to content

Commit

Permalink
Add import support to google_compute_target_tcp_proxy (hashicorp#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosbo authored Oct 5, 2017
1 parent 01817c5 commit b5f2b8f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
30 changes: 30 additions & 0 deletions google/import_compute_target_tcp_proxy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package google

import (
"fmt"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"testing"
)

func TestAccComputeTargetTcpProxy_import(t *testing.T) {
target := fmt.Sprintf("ttcp-test-%s", acctest.RandString(10))
backend := fmt.Sprintf("ttcp-test-%s", acctest.RandString(10))
hc := fmt.Sprintf("ttcp-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeTargetTcpProxyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeTargetTcpProxy_basic1(target, backend, hc),
},
resource.TestStep{
ResourceName: "google_compute_target_tcp_proxy.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
10 changes: 10 additions & 0 deletions google/resource_compute_target_tcp_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func resourceComputeTargetTcpProxy() *schema.Resource {
Delete: resourceComputeTargetTcpProxyDelete,
Update: resourceComputeTargetTcpProxyUpdate,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Expand All @@ -27,11 +31,13 @@ func resourceComputeTargetTcpProxy() *schema.Resource {
Type: schema.TypeString,
Required: true,
},

"proxy_header": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "NONE",
},

"description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -137,6 +143,10 @@ func resourceComputeTargetTcpProxyRead(d *schema.ResourceData, meta interface{})
return handleNotFoundError(err, d, fmt.Sprintf("Target TCP Proxy %q", d.Get("name").(string)))
}

d.Set("name", proxy.Name)
d.Set("backend_service", proxy.Service)
d.Set("proxy_header", proxy.ProxyHeader)
d.Set("description", proxy.Description)
d.Set("self_link", proxy.SelfLink)
d.Set("proxy_id", strconv.FormatUint(proxy.Id, 10))

Expand Down
12 changes: 10 additions & 2 deletions website/docs/r/compute_target_tcp_proxy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ The following arguments are supported:

* `backend_service` - (Required) The URL of a Backend Service resource to receive the matched traffic.

- - -

* `proxy_header` - (Optional) Type of proxy header to append before sending
data to the backend, either NONE or PROXY_V1 (default NONE).

- - -

* `description` - (Optional) A description of this resource. Changing this
forces a new resource to be created.

Expand All @@ -70,3 +70,11 @@ exported:
* `proxy_id` - A unique ID assigned by GCE.

* `self_link` - The URI of the created resource.

## Import

TCP proxy can be imported using the `name`, e.g.

```
$ terraform import google_compute_target_tcp_proxy.default test
```

0 comments on commit b5f2b8f

Please sign in to comment.