Skip to content

Commit

Permalink
Add compute_backend_service import support (#40)
Browse files Browse the repository at this point in the history
* Add compute_backend_service import support

* Fixed the nit

* Made example names a bit more intuitive

* Use underscores wherever possible instead of dashes
  • Loading branch information
selmanj authored and catsby committed Jun 14, 2017
1 parent 25c6a00 commit 3b7f6d6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
30 changes: 30 additions & 0 deletions google/import_compute_backend_service_test.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
})
}
4 changes: 4 additions & 0 deletions google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 21 additions & 13 deletions website/docs/r/compute_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
```

0 comments on commit 3b7f6d6

Please sign in to comment.