Add compute_backend_service import support (#40)

* Add compute_backend_service import support

* Fixed the nit

* Made example names a bit more intuitive

* Use underscores wherever possible instead of dashes
This commit is contained in:
Joe Selman 2017-06-14 14:13:52 -07:00 committed by Clint
parent 25c6a00ca4
commit 3b7f6d67da
3 changed files with 55 additions and 13 deletions

View File

@ -0,0 +1,30 @@
package google
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccComputeBackendService_importBasic(t *testing.T) {
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeBackendServiceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeBackendService_basic(serviceName, checkName),
},
resource.TestStep{
ResourceName: "google_compute_backend_service.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

View File

@ -17,6 +17,9 @@ func resourceComputeBackendService() *schema.Resource {
Read: resourceComputeBackendServiceRead,
Update: resourceComputeBackendServiceUpdate,
Delete: resourceComputeBackendServiceDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
@ -241,6 +244,7 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{})
return handleNotFoundError(err, d, fmt.Sprintf("Backend Service %q", d.Get("name").(string)))
}
d.Set("name", service.Name)
d.Set("description", service.Description)
d.Set("enable_cdn", service.EnableCDN)
d.Set("port_name", service.PortName)

View File

@ -8,7 +8,7 @@ description: |-
# google\_compute\_backend\_service
A Backend Service defines a group of virtual machines that will serve traffic for load balancing. For more information
A Backend Service defines a group of virtual machines that will serve traffic for load balancing. For more information
see [the official documentation](https://cloud.google.com/compute/docs/load-balancing/http/backend-service)
and the [API](https://cloud.google.com/compute/docs/reference/latest/backendServices).
@ -17,31 +17,31 @@ For internal load balancing, use a [google_compute_region_backend_service](/docs
## Example Usage
```hcl
resource "google_compute_backend_service" "foobar" {
name = "blablah"
description = "Hello World 1234"
resource "google_compute_backend_service" "website" {
name = "my_backend"
description = "Our company website"
port_name = "http"
protocol = "HTTP"
timeout_sec = 10
enable_cdn = false
backend {
group = "${google_compute_instance_group_manager.foo.instance_group}"
group = "${google_compute_instance_group_manager.webservers.instance_group}"
}
health_checks = ["${google_compute_http_health_check.default.self_link}"]
}
resource "google_compute_instance_group_manager" "foo" {
name = "terraform-test"
instance_template = "${google_compute_instance_template.foobar.self_link}"
base_instance_name = "foobar"
resource "google_compute_instance_group_manager" "webservers" {
name = "my_webservers"
instance_template = "${google_compute_instance_template.webserver.self_link}"
base_instance_name = "webserver"
zone = "us-central1-f"
target_size = 1
}
resource "google_compute_instance_template" "foobar" {
name = "terraform-test"
resource "google_compute_instance_template" "webserver" {
name = "standard_webserver"
machine_type = "n1-standard-1"
network_interface {
@ -95,8 +95,8 @@ The following arguments are supported:
* `timeout_sec` - (Optional) The number of secs to wait for a backend to respond
to a request before considering the request failed. Defaults to `30`.
* `connection_draining_timeout_sec` - (Optional) Time for which instance will be drained (not accept new connections,
* `connection_draining_timeout_sec` - (Optional) Time for which instance will be drained (not accept new connections,
but still work to finish started ones). Defaults to `0`.
The `backend` block supports:
@ -133,3 +133,11 @@ exported:
* `fingerprint` - The fingerprint of the backend service.
* `self_link` - The URI of the created resource.
## Import
Backend services can be imported using the `name`, e.g.
```
$ terraform import google_compute_backend_service.website my_backend
```