Skip to content

Commit c94cbde

Browse files
authored
Add import support to google_compute_target_tcp_proxy (#534)
1 parent f037809 commit c94cbde

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
"github.com/hashicorp/terraform/helper/acctest"
6+
"github.com/hashicorp/terraform/helper/resource"
7+
"testing"
8+
)
9+
10+
func TestAccComputeTargetTcpProxy_import(t *testing.T) {
11+
target := fmt.Sprintf("ttcp-test-%s", acctest.RandString(10))
12+
backend := fmt.Sprintf("ttcp-test-%s", acctest.RandString(10))
13+
hc := fmt.Sprintf("ttcp-test-%s", acctest.RandString(10))
14+
15+
resource.Test(t, resource.TestCase{
16+
PreCheck: func() { testAccPreCheck(t) },
17+
Providers: testAccProviders,
18+
CheckDestroy: testAccCheckComputeTargetTcpProxyDestroy,
19+
Steps: []resource.TestStep{
20+
resource.TestStep{
21+
Config: testAccComputeTargetTcpProxy_basic1(target, backend, hc),
22+
},
23+
resource.TestStep{
24+
ResourceName: "google_compute_target_tcp_proxy.foobar",
25+
ImportState: true,
26+
ImportStateVerify: true,
27+
},
28+
},
29+
})
30+
}

google/resource_compute_target_tcp_proxy.go

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ func resourceComputeTargetTcpProxy() *schema.Resource {
1616
Delete: resourceComputeTargetTcpProxyDelete,
1717
Update: resourceComputeTargetTcpProxyUpdate,
1818

19+
Importer: &schema.ResourceImporter{
20+
State: schema.ImportStatePassthrough,
21+
},
22+
1923
Schema: map[string]*schema.Schema{
2024
"name": &schema.Schema{
2125
Type: schema.TypeString,
@@ -27,11 +31,13 @@ func resourceComputeTargetTcpProxy() *schema.Resource {
2731
Type: schema.TypeString,
2832
Required: true,
2933
},
34+
3035
"proxy_header": &schema.Schema{
3136
Type: schema.TypeString,
3237
Optional: true,
3338
Default: "NONE",
3439
},
40+
3541
"description": &schema.Schema{
3642
Type: schema.TypeString,
3743
Optional: true,
@@ -137,6 +143,10 @@ func resourceComputeTargetTcpProxyRead(d *schema.ResourceData, meta interface{})
137143
return handleNotFoundError(err, d, fmt.Sprintf("Target TCP Proxy %q", d.Get("name").(string)))
138144
}
139145

146+
d.Set("name", proxy.Name)
147+
d.Set("backend_service", proxy.Service)
148+
d.Set("proxy_header", proxy.ProxyHeader)
149+
d.Set("description", proxy.Description)
140150
d.Set("self_link", proxy.SelfLink)
141151
d.Set("proxy_id", strconv.FormatUint(proxy.Id, 10))
142152

website/docs/r/compute_target_tcp_proxy.html.markdown

+10-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ The following arguments are supported:
5151

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

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

57-
- - -
58-
5959
* `description` - (Optional) A description of this resource. Changing this
6060
forces a new resource to be created.
6161

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

7272
* `self_link` - The URI of the created resource.
73+
74+
## Import
75+
76+
TCP proxy can be imported using the `name`, e.g.
77+
78+
```
79+
$ terraform import google_compute_target_tcp_proxy.default test
80+
```

0 commit comments

Comments
 (0)