Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import support to google_compute_target_tcp_proxy #534

Merged
merged 1 commit into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```