From c94cbde1f64b608cd886786084d94504375b6b06 Mon Sep 17 00:00:00 2001 From: Vincent Roseberry Date: Thu, 5 Oct 2017 14:29:53 -0700 Subject: [PATCH] Add import support to google_compute_target_tcp_proxy (#534) --- .../import_compute_target_tcp_proxy_test.go | 30 +++++++++++++++++++ google/resource_compute_target_tcp_proxy.go | 10 +++++++ .../r/compute_target_tcp_proxy.html.markdown | 12 ++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 google/import_compute_target_tcp_proxy_test.go diff --git a/google/import_compute_target_tcp_proxy_test.go b/google/import_compute_target_tcp_proxy_test.go new file mode 100644 index 00000000..dea60058 --- /dev/null +++ b/google/import_compute_target_tcp_proxy_test.go @@ -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, + }, + }, + }) +} diff --git a/google/resource_compute_target_tcp_proxy.go b/google/resource_compute_target_tcp_proxy.go index 8be350e7..23ec1490 100644 --- a/google/resource_compute_target_tcp_proxy.go +++ b/google/resource_compute_target_tcp_proxy.go @@ -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)) diff --git a/website/docs/r/compute_target_tcp_proxy.html.markdown b/website/docs/r/compute_target_tcp_proxy.html.markdown index c3231064..a8aa91c5 100644 --- a/website/docs/r/compute_target_tcp_proxy.html.markdown +++ b/website/docs/r/compute_target_tcp_proxy.html.markdown @@ -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 +``` \ No newline at end of file