Autogenerate the Address resource. (#1634)

This commit is contained in:
The Magician 2018-06-11 17:31:33 -07:00 committed by Dana Hoffman
parent 7e914c8f4f
commit 50f00fa6dc
15 changed files with 413 additions and 255 deletions

View File

@ -17,6 +17,7 @@ package google
import "github.com/hashicorp/terraform/helper/schema"
var GeneratedComputeResourcesMap = map[string]*schema.Resource{
"google_compute_address": resourceComputeAddress(),
"google_compute_backend_bucket": resourceComputeBackendBucket(),
"google_compute_disk": resourceComputeDisk(),
"google_compute_global_address": resourceComputeGlobalAddress(),

View File

@ -1,16 +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"
computeBeta "google.golang.org/api/compute/v0.beta"
)
const (
addressTypeExternal = "EXTERNAL"
addressTypeInternal = "INTERNAL"
compute "google.golang.org/api/compute/v1"
)
func resourceComputeAddress() *schema.Resource {
@ -18,66 +29,80 @@ func resourceComputeAddress() *schema.Resource {
Create: resourceComputeAddressCreate,
Read: resourceComputeAddressRead,
Delete: resourceComputeAddressDelete,
Importer: &schema.ResourceImporter{
State: resourceComputeAddressImportState,
State: resourceComputeAddressImport,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(240 * time.Second),
Delete: schema.DefaultTimeout(240 * time.Second),
},
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateRegexp(`^(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)$`),
},
"address_type": &schema.Schema{
"address": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: addressTypeExternal,
ValidateFunc: validation.StringInSlice(
[]string{addressTypeInternal, addressTypeExternal}, false),
},
"subnetwork": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
DiffSuppressFunc: linkDiffSuppress,
},
// address will be computed unless it is specified explicitly.
// address may only be specified for the INTERNAL address_type.
"address": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Optional: true,
ForceNew: true,
},
"network_tier": &schema.Schema{
"address_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"INTERNAL", "EXTERNAL", ""}, false),
Default: "EXTERNAL",
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"network_tier": {
Type: schema.TypeString,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"PREMIUM", "STANDARD"}, false),
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"PREMIUM", "STANDARD", ""}, false),
},
"project": &schema.Schema{
"subnetwork": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"region": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"creation_timestamp": {
Type: schema.TypeString,
Computed: true,
},
"users": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"region": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"self_link": &schema.Schema{
"self_link": {
Type: schema.TypeString,
Computed: true,
},
@ -88,41 +113,85 @@ func resourceComputeAddress() *schema.Resource {
func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
region, err := getRegion(d, config)
if err != nil {
return err
}
project, err := getProject(d, config)
if err != nil {
return err
}
// Build the address parameter
address := &computeBeta.Address{
Name: d.Get("name").(string),
AddressType: d.Get("address_type").(string),
Subnetwork: d.Get("subnetwork").(string),
Address: d.Get("address").(string),
NetworkTier: d.Get("network_tier").(string),
}
op, err := config.clientComputeBeta.Addresses.Insert(project, region, address).Do()
if err != nil {
return fmt.Errorf("Error creating address: %s", err)
}
// It probably maybe worked, so store the ID now
d.SetId(computeAddressId{
Project: project,
Region: region,
Name: address.Name,
}.canonicalId())
err = computeSharedOperationWait(config.clientCompute, op, project, "Creating Address")
addressProp, err := expandComputeAddressAddress(d.Get("address"), d, config)
if err != nil {
return err
}
addressTypeProp, err := expandComputeAddressAddressType(d.Get("address_type"), d, config)
if err != nil {
return err
}
descriptionProp, err := expandComputeAddressDescription(d.Get("description"), d, config)
if err != nil {
return err
}
nameProp, err := expandComputeAddressName(d.Get("name"), d, config)
if err != nil {
return err
}
networkTierProp, err := expandComputeAddressNetworkTier(d.Get("network_tier"), d, config)
if err != nil {
return err
}
subnetworkProp, err := expandComputeAddressSubnetwork(d.Get("subnetwork"), d, config)
if err != nil {
return err
}
regionProp, err := expandComputeAddressRegion(d.Get("region"), d, config)
if err != nil {
return err
}
obj := map[string]interface{}{
"address": addressProp,
"addressType": addressTypeProp,
"description": descriptionProp,
"name": nameProp,
"networkTier": networkTierProp,
"subnetwork": subnetworkProp,
"region": regionProp,
}
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/addresses")
if err != nil {
return err
}
log.Printf("[DEBUG] Creating new Address: %#v", obj)
res, err := Post(config, url, obj)
if err != nil {
return fmt.Errorf("Error creating Address: %s", err)
}
// Store the ID now
id, err := replaceVars(d, config, "{{project}}/{{region}}/{{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 Address",
int(d.Timeout(schema.TimeoutCreate).Minutes()))
if waitErr != nil {
// The resource didn't actually create
d.SetId("")
return fmt.Errorf("Error waiting to create Address: %s", waitErr)
}
log.Printf("[DEBUG] Finished creating Address %q: %#v", d.Id(), res)
return resourceComputeAddressRead(d, meta)
}
@ -130,29 +199,54 @@ func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) erro
func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
addressId, err := parseComputeAddressId(d.Id(), config)
project, err := getProject(d, config)
if err != nil {
return err
}
addr, err := config.clientComputeBeta.Addresses.Get(
addressId.Project, addressId.Region, addressId.Name).Do()
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/addresses/{{name}}")
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("Address %q", d.Get("name").(string)))
return err
}
d.Set("address_type", addr.AddressType)
// The API returns an empty AddressType for EXTERNAL address.
if addr.AddressType == "" {
d.Set("address_type", addressTypeExternal)
res, err := Get(config, url)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("ComputeAddress %q", d.Id()))
}
if err := d.Set("address", flattenComputeAddressAddress(res["address"])); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("address_type", flattenComputeAddressAddressType(res["addressType"])); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("creation_timestamp", flattenComputeAddressCreationTimestamp(res["creationTimestamp"])); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("description", flattenComputeAddressDescription(res["description"])); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("name", flattenComputeAddressName(res["name"])); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("network_tier", flattenComputeAddressNetworkTier(res["networkTier"])); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("subnetwork", flattenComputeAddressSubnetwork(res["subnetwork"])); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("users", flattenComputeAddressUsers(res["users"])); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("region", flattenComputeAddressRegion(res["region"])); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
d.Set("subnetwork", ConvertSelfLinkToV1(addr.Subnetwork))
d.Set("address", addr.Address)
d.Set("self_link", ConvertSelfLinkToV1(addr.SelfLink))
d.Set("name", addr.Name)
d.Set("network_tier", addr.NetworkTier)
d.Set("project", addressId.Project)
d.Set("region", GetResourceNameFromSelfLink(addr.Region))
return nil
}
@ -160,36 +254,125 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error
func resourceComputeAddressDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
addressId, err := parseComputeAddressId(d.Id(), config)
project, err := getProject(d, config)
if err != nil {
return err
}
// Delete the address
op, err := config.clientComputeBeta.Addresses.Delete(
addressId.Project, addressId.Region, addressId.Name).Do()
if err != nil {
return fmt.Errorf("Error deleting address: %s", err)
}
err = computeSharedOperationWait(config.clientCompute, op, addressId.Project, "Deleting Address")
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/addresses/{{name}}")
if err != nil {
return err
}
d.SetId("")
log.Printf("[DEBUG] Deleting Address %q", d.Id())
res, err := Delete(config, url)
if err != nil {
return handleNotFoundError(err, d, "Address")
}
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}
err = computeOperationWaitTime(
config.clientCompute, op, project, "Deleting Address",
int(d.Timeout(schema.TimeoutDelete).Minutes()))
if err != nil {
return err
}
log.Printf("[DEBUG] Finished deleting Address %q: %#v", d.Id(), res)
return nil
}
func resourceComputeAddressImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
func resourceComputeAddressImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
parseImportId([]string{"projects/(?P<project>[^/]+)/regions/(?P<region>[^/]+)/addresses/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
addressId, err := parseComputeAddressId(d.Id(), config)
// Replace import id for the resource id
id, err := replaceVars(d, config, "{{project}}/{{region}}/{{name}}")
if err != nil {
return nil, err
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(addressId.canonicalId())
d.SetId(id)
return []*schema.ResourceData{d}, nil
}
func flattenComputeAddressAddress(v interface{}) interface{} {
return v
}
func flattenComputeAddressAddressType(v interface{}) interface{} {
if v == nil || v.(string) == "" {
return "EXTERNAL"
}
return v
}
func flattenComputeAddressCreationTimestamp(v interface{}) interface{} {
return v
}
func flattenComputeAddressDescription(v interface{}) interface{} {
return v
}
func flattenComputeAddressName(v interface{}) interface{} {
return v
}
func flattenComputeAddressNetworkTier(v interface{}) interface{} {
return v
}
func flattenComputeAddressSubnetwork(v interface{}) interface{} {
return v
}
func flattenComputeAddressUsers(v interface{}) interface{} {
return v
}
func flattenComputeAddressRegion(v interface{}) interface{} {
return v
}
func expandComputeAddressAddress(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeAddressAddressType(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeAddressDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeAddressName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeAddressNetworkTier(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeAddressSubnetwork(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseRegionalFieldValue("subnetworks", v.(string), "project", "region", "zone", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for subnetwork: %s", err)
}
return f.RelativeLink(), nil
}
func expandComputeAddressRegion(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("regions", v.(string), "project", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for region: %s", err)
}
return f.RelativeLink(), nil
}

View File

@ -7,15 +7,11 @@ import (
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
computeBeta "google.golang.org/api/compute/v0.beta"
"google.golang.org/api/compute/v1"
)
func TestAccComputeAddress_basic(t *testing.T) {
t.Parallel()
var addr compute.Address
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@ -23,10 +19,6 @@ func TestAccComputeAddress_basic(t *testing.T) {
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeAddress_basic(acctest.RandString(10)),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeAddressExists(
"google_compute_address.foobar", &addr),
),
},
resource.TestStep{
ResourceName: "google_compute_address.foobar",
@ -58,8 +50,6 @@ func TestAccComputeAddress_networkTier(t *testing.T) {
}
func TestAccComputeAddress_internal(t *testing.T) {
var addr computeBeta.Address
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@ -67,15 +57,6 @@ func TestAccComputeAddress_internal(t *testing.T) {
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeAddress_internal(acctest.RandString(10)),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBetaAddressExists("google_compute_address.internal", &addr),
testAccCheckComputeBetaAddressExists("google_compute_address.internal_with_subnet", &addr),
testAccCheckComputeBetaAddressExists("google_compute_address.internal_with_subnet_and_address", &addr),
resource.TestCheckResourceAttr("google_compute_address.internal", "address_type", "INTERNAL"),
resource.TestCheckResourceAttr("google_compute_address.internal_with_subnet", "address_type", "INTERNAL"),
resource.TestCheckResourceAttr("google_compute_address.internal_with_subnet_and_address", "address_type", "INTERNAL"),
resource.TestCheckResourceAttr("google_compute_address.internal_with_subnet_and_address", "address", "10.0.42.42"),
),
},
resource.TestStep{
ResourceName: "google_compute_address.internal",
@ -106,7 +87,7 @@ func testAccCheckComputeAddressDestroy(s *terraform.State) error {
continue
}
addressId, err := parseComputeAddressId(rs.Primary.ID, nil)
addressId, err := parseComputeAddressId(rs.Primary.ID, config)
_, err = config.clientCompute.Addresses.Get(
config.Project, addressId.Region, addressId.Name).Do()
@ -118,68 +99,6 @@ func testAccCheckComputeAddressDestroy(s *terraform.State) error {
return nil
}
func testAccCheckComputeAddressExists(n string, addr *compute.Address) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
addressId, err := parseComputeAddressId(rs.Primary.ID, nil)
found, err := config.clientCompute.Addresses.Get(
config.Project, addressId.Region, addressId.Name).Do()
if err != nil {
return err
}
if found.Name != addressId.Name {
return fmt.Errorf("Addr not found")
}
*addr = *found
return nil
}
}
func testAccCheckComputeBetaAddressExists(n string, addr *computeBeta.Address) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
addressId, err := parseComputeAddressId(rs.Primary.ID, nil)
found, err := config.clientComputeBeta.Addresses.Get(
config.Project, addressId.Region, addressId.Name).Do()
if err != nil {
return err
}
if found.Name != addressId.Name {
return fmt.Errorf("Addr not found")
}
*addr = *found
return nil
}
}
func testAccComputeAddress_basic(i string) string {
return fmt.Sprintf(`
resource "google_compute_address" "foobar" {

View File

@ -181,7 +181,7 @@ func resourceComputeBackendBucketRead(d *schema.ResourceData, meta interface{})
if err := d.Set("name", flattenComputeBackendBucketName(res["name"])); err != nil {
return fmt.Errorf("Error reading BackendBucket: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading BackendBucket: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -611,7 +611,7 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("source_snapshot_id", flattenComputeDiskSourceSnapshotId(res["sourceSnapshotId"])); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -178,7 +178,7 @@ func resourceComputeGlobalAddressRead(d *schema.ResourceData, meta interface{})
if err := d.Set("ip_version", flattenComputeGlobalAddressIpVersion(res["ipVersion"])); err != nil {
return fmt.Errorf("Error reading GlobalAddress: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading GlobalAddress: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -247,7 +247,7 @@ func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{}
if err := d.Set("unhealthy_threshold", flattenComputeHttpHealthCheckUnhealthyThreshold(res["unhealthyThreshold"])); err != nil {
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -247,7 +247,7 @@ func resourceComputeHttpsHealthCheckRead(d *schema.ResourceData, meta interface{
if err := d.Set("unhealthy_threshold", flattenComputeHttpsHealthCheckUnhealthyThreshold(res["unhealthyThreshold"])); err != nil {
return fmt.Errorf("Error reading HttpsHealthCheck: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading HttpsHealthCheck: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -242,7 +242,7 @@ func resourceComputeSslPolicyRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("fingerprint", flattenComputeSslPolicyFingerprint(res["fingerprint"])); err != nil {
return fmt.Errorf("Error reading SslPolicy: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading SslPolicy: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -178,7 +178,7 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{}
if err := d.Set("url_map", flattenComputeTargetHttpProxyUrlMap(res["urlMap"])); err != nil {
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -207,7 +207,7 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
if err := d.Set("ssl_policy", flattenComputeTargetHttpsProxySslPolicy(res["sslPolicy"])); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -223,7 +223,7 @@ func resourceComputeTargetSslProxyRead(d *schema.ResourceData, meta interface{})
if err := d.Set("ssl_policy", flattenComputeTargetSslProxySslPolicy(res["sslPolicy"])); err != nil {
return fmt.Errorf("Error reading TargetSslProxy: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading TargetSslProxy: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -193,7 +193,7 @@ func resourceComputeTargetTcpProxyRead(d *schema.ResourceData, meta interface{})
if err := d.Set("backend_service", flattenComputeTargetTcpProxyBackendService(res["service"])); err != nil {
return fmt.Errorf("Error reading TargetTcpProxy: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading TargetTcpProxy: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -184,7 +184,7 @@ func resourceComputeVpnGatewayRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("region", flattenComputeVpnGatewayRegion(res["region"])); err != nil {
return fmt.Errorf("Error reading VpnGateway: %s", err)
}
if err := d.Set("self_link", res["selfLink"]); err != nil {
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading VpnGateway: %s", err)
}
if err := d.Set("project", project); err != nil {

View File

@ -1,26 +1,72 @@
---
# ----------------------------------------------------------------------------
#
# *** 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_address"
sidebar_current: "docs-google-compute-address"
description: |-
Creates a static IP address resource for Google Compute Engine.
Represents an Address resource.
---
# google\_compute\_address
Creates a static IP address resource for Google Compute Engine. For more information see
the official documentation for
[external](https://cloud.google.com/compute/docs/instances-and-network) and
[internal](https://cloud.google.com/compute/docs/ip-addresses/reserve-static-internal-ip-address)
static IP reservations, as well as the
[API](https://cloud.google.com/compute/docs/reference/beta/addresses/insert).
Represents an Address resource.
Each virtual machine instance has an ephemeral internal IP address and,
optionally, an external IP address. To communicate between instances on
the same network, you can use an instance's internal IP address. To
communicate with the Internet and instances outside of the same network,
you must specify the instance's external IP address.
Internal IP addresses are ephemeral and only belong to an instance for
the lifetime of the instance; if the instance is deleted and recreated,
the instance is assigned a new internal IP address, either by Compute
Engine or by you. External IP addresses can be either ephemeral or
static.
To get more information about Address, see:
* [API documentation](https://cloud.google.com/compute/docs/reference/beta/addresses)
* How-to Guides
* [Reserving a Static External IP Address](https://cloud.google.com/compute/docs/instances-and-network)
* [Reserving a Static Internal IP Address](https://cloud.google.com/compute/docs/ip-addresses/reserve-static-internal-ip-address)
## Example Usage
```hcl
resource "google_compute_address" "default" {
name = "test-address"
name = "my-address"
}
```
```hcl
resource "google_compute_network" "default" {
name = "my-network"
}
resource "google_compute_subnetwork" "default" {
name = "my-subnet"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = "${google_compute_network.default.self_link}"
}
resource "google_compute_address" "internal_with_subnet_and_address" {
name = "my-internal-address"
subnetwork = "${google_compute_subnetwork.default.self_link}"
address_type = "INTERNAL"
address = "10.0.42.42"
region = "us-central1"
}
```
@ -28,67 +74,76 @@ resource "google_compute_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. 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.
* `address` -
(Optional)
The static external IP address represented by this resource. Only
IPv4 is supported. An address may only be specified for INTERNAL
address types. The IP address must be inside the specified subnetwork,
if any.
* `address_type` -
(Optional)
The type of address to reserve, either INTERNAL or EXTERNAL.
If unspecified, defaults to EXTERNAL.
* `description` -
(Optional)
An optional description of this resource.
* `network_tier` -
(Optional)
The networking tier used for configuring this address. This field can
take the following values: PREMIUM or STANDARD. If this field is not
specified, it is assumed to be PREMIUM.
* `subnetwork` -
(Optional)
The URL of the subnetwork in which to reserve the address. If an IP
address is specified, it must be within the subnetwork's IP range.
This field can only be used with INTERNAL type with
GCE_ENDPOINT/DNS_RESOLVER purposes.
* `region` -
(Optional)
The Region in which the created address should reside.
If it is not provided, the provider region is used.
* `project` (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
* `region` - (Optional) The Region in which the created address should reside.
If it is not provided, the provider region is used.
* `address_type` - (Optional) The Address Type that should be configured.
Specify INTERNAL to reserve an internal static IP address EXTERNAL to
specify an external static IP address. Defaults to EXTERNAL if omitted.
* `subnetwork` - (Optional) The self link URI of the subnetwork in which to
create the address. A subnetwork may only be specified for INTERNAL
address types.
* `address` - (Optional) The IP address to reserve. An address may only be
specified for INTERNAL address types. The IP address must be inside the
specified subnetwork, if any.
* `network_tier` - (Optional) The [networking tier][network-tier] used for configuring
this address. This field can take the following values: PREMIUM or STANDARD.
If this field is not specified, it is assumed to be PREMIUM.
## Attributes Reference
In addition to the arguments listed above, the following computed attributes are
exported:
In addition to the arguments listed above, the following computed attributes are exported:
* `creation_timestamp` -
Creation timestamp in RFC3339 text format.
* `users` -
The URLs of the resources that are using this address.
* `self_link` - The URI of the created resource.
* `address` - The IP of the created resource.
* `address`: The IP 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
Addresses can be imported using the `project`, `region` and `name`, e.g.
Address can be imported using any of these accepted formats:
```
$ terraform import google_compute_address.default gcp-project/us-central1/test-address
$ terraform import google_compute_address.default projects/{{project}}/regions/{{region}}/addresses/{{name}}
$ terraform import google_compute_address.default {{project}}/{{region}}/{{name}}
$ terraform import google_compute_address.default {{name}}
```
If `project` is omitted, the default project set for the provider is used:
```
$ terraform import google_compute_address.default us-central1/test-address
```
If `project` and `region` are omitted, the default project and region set for the provider are used.
```
$ terraform import google_compute_address.default test-address
```
Alternatively, addresses can be imported using a full or partial `self_link`.
```
$ terraform import google_compute_address.default https://www.googleapis.com/compute/v1/projects/gcp-project/regions/us-central1/addresses/test-address
$ terraform import google_compute_address.default projects/gcp-project/regions/us-central1/addresses/test-address
```
[network-tier]: https://cloud.google.com/network-tiers/docs/overview