Add import support to google_compute_target_tcp_proxy (#534)

This commit is contained in:
Vincent Roseberry 2017-10-05 14:29:53 -07:00 committed by GitHub
parent f03780986a
commit c94cbde1f6
3 changed files with 50 additions and 2 deletions

View File

@ -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,
},
},
})
}

View File

@ -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,
@ -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,
@ -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))

View File

@ -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.
@ -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
```