mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +00:00
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:
parent
25c6a00ca4
commit
3b7f6d67da
30
google/import_compute_backend_service_test.go
Normal file
30
google/import_compute_backend_service_test.go
Normal 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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -17,6 +17,9 @@ func resourceComputeBackendService() *schema.Resource {
|
||||||
Read: resourceComputeBackendServiceRead,
|
Read: resourceComputeBackendServiceRead,
|
||||||
Update: resourceComputeBackendServiceUpdate,
|
Update: resourceComputeBackendServiceUpdate,
|
||||||
Delete: resourceComputeBackendServiceDelete,
|
Delete: resourceComputeBackendServiceDelete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &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)))
|
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("description", service.Description)
|
||||||
d.Set("enable_cdn", service.EnableCDN)
|
d.Set("enable_cdn", service.EnableCDN)
|
||||||
d.Set("port_name", service.PortName)
|
d.Set("port_name", service.PortName)
|
||||||
|
|
|
@ -8,7 +8,7 @@ description: |-
|
||||||
|
|
||||||
# google\_compute\_backend\_service
|
# 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)
|
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).
|
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
|
## Example Usage
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
resource "google_compute_backend_service" "foobar" {
|
resource "google_compute_backend_service" "website" {
|
||||||
name = "blablah"
|
name = "my_backend"
|
||||||
description = "Hello World 1234"
|
description = "Our company website"
|
||||||
port_name = "http"
|
port_name = "http"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
timeout_sec = 10
|
timeout_sec = 10
|
||||||
enable_cdn = false
|
enable_cdn = false
|
||||||
|
|
||||||
backend {
|
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}"]
|
health_checks = ["${google_compute_http_health_check.default.self_link}"]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_instance_group_manager" "foo" {
|
resource "google_compute_instance_group_manager" "webservers" {
|
||||||
name = "terraform-test"
|
name = "my_webservers"
|
||||||
instance_template = "${google_compute_instance_template.foobar.self_link}"
|
instance_template = "${google_compute_instance_template.webserver.self_link}"
|
||||||
base_instance_name = "foobar"
|
base_instance_name = "webserver"
|
||||||
zone = "us-central1-f"
|
zone = "us-central1-f"
|
||||||
target_size = 1
|
target_size = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_instance_template" "foobar" {
|
resource "google_compute_instance_template" "webserver" {
|
||||||
name = "terraform-test"
|
name = "standard_webserver"
|
||||||
machine_type = "n1-standard-1"
|
machine_type = "n1-standard-1"
|
||||||
|
|
||||||
network_interface {
|
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
|
* `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`.
|
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`.
|
but still work to finish started ones). Defaults to `0`.
|
||||||
|
|
||||||
The `backend` block supports:
|
The `backend` block supports:
|
||||||
|
@ -133,3 +133,11 @@ exported:
|
||||||
* `fingerprint` - The fingerprint of the backend service.
|
* `fingerprint` - The fingerprint of the backend service.
|
||||||
|
|
||||||
* `self_link` - The URI of the created resource.
|
* `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
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user