mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-01 16:21:06 +00:00
Release generated GlobalAddress (#1379)
This commit is contained in:
parent
949b33ab20
commit
df568b188c
@ -1,13 +1,27 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This file is automatically generated by Magic Modules and manual
|
||||
// changes will be clobbered when the file is regenerated.
|
||||
//
|
||||
// Please read more about how to change this file in
|
||||
// .github/CONTRIBUTING.md.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
package google
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/helper/validation"
|
||||
|
||||
"google.golang.org/api/compute/v1"
|
||||
compute "google.golang.org/api/compute/v1"
|
||||
)
|
||||
|
||||
func resourceComputeGlobalAddress() *schema.Resource {
|
||||
@ -15,37 +29,48 @@ func resourceComputeGlobalAddress() *schema.Resource {
|
||||
Create: resourceComputeGlobalAddressCreate,
|
||||
Read: resourceComputeGlobalAddressRead,
|
||||
Delete: resourceComputeGlobalAddressDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
State: resourceComputeGlobalAddressImport,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: schema.DefaultTimeout(240 * time.Second),
|
||||
Delete: schema.DefaultTimeout(240 * time.Second),
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"ip_version": &schema.Schema{
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"ip_version": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"IPV4", "IPV6", ""}, false),
|
||||
},
|
||||
|
||||
"project": &schema.Schema{
|
||||
"address": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"creation_timestamp": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"project": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"address": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"self_link": &schema.Schema{
|
||||
"self_link": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
@ -61,24 +86,58 @@ func resourceComputeGlobalAddressCreate(d *schema.ResourceData, meta interface{}
|
||||
return err
|
||||
}
|
||||
|
||||
// Build the address parameter
|
||||
addr := &compute.Address{
|
||||
Name: d.Get("name").(string),
|
||||
IpVersion: d.Get("ip_version").(string),
|
||||
}
|
||||
|
||||
op, err := config.clientCompute.GlobalAddresses.Insert(project, addr).Do()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating address: %s", err)
|
||||
}
|
||||
|
||||
// It probably maybe worked, so store the ID now
|
||||
d.SetId(addr.Name)
|
||||
|
||||
err = computeSharedOperationWait(config.clientCompute, op, project, "Creating Global Address")
|
||||
descriptionProp, err := expandComputeGlobalAddressDescription(d.Get("description"), d, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nameProp, err := expandComputeGlobalAddressName(d.Get("name"), d, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ipVersionProp, err := expandComputeGlobalAddressIpVersion(d.Get("ip_version"), d, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
obj := map[string]interface{}{
|
||||
"description": descriptionProp,
|
||||
"name": nameProp,
|
||||
"ipVersion": ipVersionProp,
|
||||
}
|
||||
|
||||
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Creating new GlobalAddress: %#v", obj)
|
||||
res, err := Post(config, url, obj)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating GlobalAddress: %s", err)
|
||||
}
|
||||
|
||||
// Store the ID now
|
||||
id, err := replaceVars(d, config, "{{name}}")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error constructing id: %s", err)
|
||||
}
|
||||
d.SetId(id)
|
||||
|
||||
op := &compute.Operation{}
|
||||
err = Convert(res, op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
waitErr := computeOperationWaitTime(
|
||||
config.clientCompute, op, project, "Creating GlobalAddress",
|
||||
int(d.Timeout(schema.TimeoutCreate).Minutes()))
|
||||
|
||||
if waitErr != nil {
|
||||
// The resource didn't actually create
|
||||
d.SetId("")
|
||||
return waitErr
|
||||
}
|
||||
|
||||
return resourceComputeGlobalAddressRead(d, meta)
|
||||
}
|
||||
@ -91,16 +150,23 @@ func resourceComputeGlobalAddressRead(d *schema.ResourceData, meta interface{})
|
||||
return err
|
||||
}
|
||||
|
||||
addr, err := config.clientCompute.GlobalAddresses.Get(project, d.Id()).Do()
|
||||
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses/{{name}}")
|
||||
if err != nil {
|
||||
return handleNotFoundError(err, d, fmt.Sprintf("Global Address %q", d.Get("name").(string)))
|
||||
return err
|
||||
}
|
||||
|
||||
d.Set("name", addr.Name)
|
||||
d.Set("ip_version", addr.IpVersion)
|
||||
d.Set("address", addr.Address)
|
||||
res, err := Get(config, url)
|
||||
if err != nil {
|
||||
return handleNotFoundError(err, d, fmt.Sprintf("ComputeGlobalAddress %q", d.Id()))
|
||||
}
|
||||
|
||||
d.Set("address", flattenComputeGlobalAddressAddress(res["address"]))
|
||||
d.Set("creation_timestamp", flattenComputeGlobalAddressCreationTimestamp(res["creationTimestamp"]))
|
||||
d.Set("description", flattenComputeGlobalAddressDescription(res["description"]))
|
||||
d.Set("name", flattenComputeGlobalAddressName(res["name"]))
|
||||
d.Set("ip_version", flattenComputeGlobalAddressIpVersion(res["ipVersion"]))
|
||||
d.Set("self_link", res["selfLink"])
|
||||
d.Set("project", project)
|
||||
d.Set("self_link", ConvertSelfLinkToV1(addr.SelfLink))
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -113,18 +179,76 @@ func resourceComputeGlobalAddressDelete(d *schema.ResourceData, meta interface{}
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete the address
|
||||
log.Printf("[DEBUG] address delete request")
|
||||
op, err := config.clientCompute.GlobalAddresses.Delete(project, d.Id()).Do()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting address: %s", err)
|
||||
}
|
||||
|
||||
err = computeSharedOperationWait(config.clientCompute, op, project, "Deleting Global Address")
|
||||
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses/{{name}}")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Deleting GlobalAddress %q", d.Id())
|
||||
res, err := Delete(config, url)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting GlobalAddress %q: %s", d.Id(), err)
|
||||
}
|
||||
|
||||
op := &compute.Operation{}
|
||||
err = Convert(res, op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = computeOperationWaitTime(
|
||||
config.clientCompute, op, project, "Deleting GlobalAddress",
|
||||
int(d.Timeout(schema.TimeoutDelete).Minutes()))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceComputeGlobalAddressImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
||||
config := meta.(*Config)
|
||||
parseImportId([]string{"projects/(?P<project>[^/]+)/global/addresses/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
|
||||
|
||||
// Replace import id for the resource id
|
||||
id, err := replaceVars(d, config, "{{name}}")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error constructing id: %s", err)
|
||||
}
|
||||
d.SetId(id)
|
||||
|
||||
return []*schema.ResourceData{d}, nil
|
||||
}
|
||||
|
||||
func flattenComputeGlobalAddressAddress(v interface{}) interface{} {
|
||||
return v
|
||||
}
|
||||
|
||||
func flattenComputeGlobalAddressCreationTimestamp(v interface{}) interface{} {
|
||||
return v
|
||||
}
|
||||
|
||||
func flattenComputeGlobalAddressDescription(v interface{}) interface{} {
|
||||
return v
|
||||
}
|
||||
|
||||
func flattenComputeGlobalAddressName(v interface{}) interface{} {
|
||||
return v
|
||||
}
|
||||
|
||||
func flattenComputeGlobalAddressIpVersion(v interface{}) interface{} {
|
||||
return v
|
||||
}
|
||||
|
||||
func expandComputeGlobalAddressDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func expandComputeGlobalAddressName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func expandComputeGlobalAddressIpVersion(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
@ -144,6 +144,7 @@ func testAccComputeGlobalAddress_basic() string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_global_address" "foobar" {
|
||||
name = "address-test-%s"
|
||||
description = "Created for Terraform acceptance testing"
|
||||
}`, acctest.RandString(10))
|
||||
}
|
||||
|
||||
@ -151,6 +152,7 @@ func testAccComputeGlobalAddress_ipv6() string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_global_address" "foobar" {
|
||||
name = "address-test-%s"
|
||||
description = "Created for Terraform acceptance testing"
|
||||
ip_version = "IPV6"
|
||||
}`, acctest.RandString(10))
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/helper/validation"
|
||||
compute "google.golang.org/api/compute/v1"
|
||||
)
|
||||
|
||||
@ -67,9 +68,10 @@ func resourceComputeTargetSslProxy() *schema.Resource {
|
||||
ForceNew: true,
|
||||
},
|
||||
"proxy_header": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "NONE",
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false),
|
||||
Default: "NONE",
|
||||
},
|
||||
"creation_timestamp": {
|
||||
Type: schema.TypeString,
|
||||
|
@ -1,17 +1,37 @@
|
||||
<!--
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
*** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
This file is automatically generated by Magic Modules and manual
|
||||
changes will be clobbered when the file is regenerated.
|
||||
|
||||
Please read more about how to change this file in
|
||||
.github/CONTRIBUTING.md.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-->
|
||||
|
||||
---
|
||||
layout: "google"
|
||||
page_title: "Google: google_compute_global_address"
|
||||
sidebar_current: "docs-google-compute-global-address"
|
||||
description: |-
|
||||
Creates a static global IP address resource for a Google Compute Engine project.
|
||||
Represents a Global Address resource.
|
||||
---
|
||||
|
||||
# google\_compute\_global\_address
|
||||
|
||||
Creates a static IP address resource global to a Google Compute Engine project. For more information see
|
||||
[the official documentation](https://cloud.google.com/compute/docs/instances-and-network) and
|
||||
[API](https://cloud.google.com/compute/docs/reference/latest/globalAddresses).
|
||||
Represents a Global Address resource. Global addresses are used for
|
||||
HTTP(S) load balancing.
|
||||
|
||||
To get more information about GlobalAddress, see:
|
||||
|
||||
* [API documentation](https://cloud.google.com/compute/docs/reference/latest/globalAddresses)
|
||||
* How-to Guides
|
||||
* [Reserving a Static External IP Address](https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address)
|
||||
|
||||
## Example Usage
|
||||
|
||||
@ -25,29 +45,56 @@ resource "google_compute_global_address" "default" {
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - (Required) A unique name for the resource, required by GCE.
|
||||
Changing this forces a new resource to be created.
|
||||
* `name` -
|
||||
(Required)
|
||||
Name of the resource. Provided by the client when the resource is
|
||||
created. The name must be 1-63 characters long, and comply with
|
||||
RFC1035. Specifically, the name must be 1-63 characters long and
|
||||
match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means
|
||||
the first character must be a lowercase letter, and all following
|
||||
characters must be a dash, lowercase letter, or digit, except the last
|
||||
character, which cannot be a dash.
|
||||
|
||||
|
||||
- - -
|
||||
|
||||
* `project` - (Optional) The ID of the project in which the resource belongs. If it
|
||||
is not provided, the provider project is used.
|
||||
* `description` -
|
||||
(Optional)
|
||||
An optional description of this resource.
|
||||
Provide this property when you create the resource.
|
||||
* `ip_version` -
|
||||
(Optional)
|
||||
The IP Version that will be used by this address. Valid options are
|
||||
IPV4 or IPV6. The default value is IPV4.
|
||||
* `project` (Optional) The ID of the project in which the resource belongs.
|
||||
If it is not provided, the provider project is used.
|
||||
|
||||
* `ip_version` - (Optional) The IP Version that will be used by this address. One of `"IPV4"` or `"IPV6"`.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
In addition to the arguments listed above, the following computed attributes are
|
||||
exported:
|
||||
|
||||
* `address` - The assigned address.
|
||||
In addition to the arguments listed above, the following computed attributes are exported:
|
||||
|
||||
* `address` -
|
||||
The static external IP address represented by this resource.
|
||||
* `creation_timestamp` -
|
||||
Creation timestamp in RFC3339 text format.
|
||||
* `self_link` - The URI of the created resource.
|
||||
|
||||
|
||||
## Timeouts
|
||||
|
||||
This resource provides the following
|
||||
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:
|
||||
|
||||
- `create` - Default is 4 minutes.
|
||||
- `delete` - Default is 4 minutes.
|
||||
|
||||
## Import
|
||||
|
||||
Global addresses can be imported using the `name`, e.g.
|
||||
GlobalAddress can be imported using any of these accepted formats:
|
||||
|
||||
```
|
||||
$ terraform import google_compute_global_address.default global-appserver-ip
|
||||
$ terraform import google_compute_global_address.default projects/{{project}}/global/addresses/{{name}}
|
||||
$ terraform import google_compute_global_address.default {{project}}/{{name}}
|
||||
$ terraform import google_compute_global_address.default {{name}}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user