WIP: Add interconnect attachments. (#1569)

Fixes #1140.
This commit is contained in:
The Magician 2018-09-21 13:27:57 -07:00 committed by Nathan McKinley
parent c6ceb36ec7
commit 06c2f8451f
3 changed files with 547 additions and 23 deletions

View File

@ -17,27 +17,28 @@ package google
import "github.com/hashicorp/terraform/helper/schema"
var GeneratedComputeResourcesMap = map[string]*schema.Resource{
"google_compute_address": resourceComputeAddress(),
"google_compute_autoscaler": resourceComputeAutoscaler(),
"google_compute_backend_bucket": resourceComputeBackendBucket(),
"google_compute_disk": resourceComputeDisk(),
"google_compute_firewall": resourceComputeFirewall(),
"google_compute_forwarding_rule": resourceComputeForwardingRule(),
"google_compute_global_address": resourceComputeGlobalAddress(),
"google_compute_http_health_check": resourceComputeHttpHealthCheck(),
"google_compute_https_health_check": resourceComputeHttpsHealthCheck(),
"google_compute_health_check": resourceComputeHealthCheck(),
"google_compute_region_autoscaler": resourceComputeRegionAutoscaler(),
"google_compute_region_disk": resourceComputeRegionDisk(),
"google_compute_route": resourceComputeRoute(),
"google_compute_router": resourceComputeRouter(),
"google_compute_ssl_certificate": resourceComputeSslCertificate(),
"google_compute_ssl_policy": resourceComputeSslPolicy(),
"google_compute_subnetwork": resourceComputeSubnetwork(),
"google_compute_target_http_proxy": resourceComputeTargetHttpProxy(),
"google_compute_target_https_proxy": resourceComputeTargetHttpsProxy(),
"google_compute_target_ssl_proxy": resourceComputeTargetSslProxy(),
"google_compute_target_tcp_proxy": resourceComputeTargetTcpProxy(),
"google_compute_vpn_gateway": resourceComputeVpnGateway(),
"google_compute_vpn_tunnel": resourceComputeVpnTunnel(),
"google_compute_address": resourceComputeAddress(),
"google_compute_autoscaler": resourceComputeAutoscaler(),
"google_compute_backend_bucket": resourceComputeBackendBucket(),
"google_compute_disk": resourceComputeDisk(),
"google_compute_firewall": resourceComputeFirewall(),
"google_compute_forwarding_rule": resourceComputeForwardingRule(),
"google_compute_global_address": resourceComputeGlobalAddress(),
"google_compute_http_health_check": resourceComputeHttpHealthCheck(),
"google_compute_https_health_check": resourceComputeHttpsHealthCheck(),
"google_compute_health_check": resourceComputeHealthCheck(),
"google_compute_interconnect_attachment": resourceComputeInterconnectAttachment(),
"google_compute_region_autoscaler": resourceComputeRegionAutoscaler(),
"google_compute_region_disk": resourceComputeRegionDisk(),
"google_compute_route": resourceComputeRoute(),
"google_compute_router": resourceComputeRouter(),
"google_compute_ssl_certificate": resourceComputeSslCertificate(),
"google_compute_ssl_policy": resourceComputeSslPolicy(),
"google_compute_subnetwork": resourceComputeSubnetwork(),
"google_compute_target_http_proxy": resourceComputeTargetHttpProxy(),
"google_compute_target_https_proxy": resourceComputeTargetHttpsProxy(),
"google_compute_target_ssl_proxy": resourceComputeTargetSslProxy(),
"google_compute_target_tcp_proxy": resourceComputeTargetTcpProxy(),
"google_compute_vpn_gateway": resourceComputeVpnGateway(),
"google_compute_vpn_tunnel": resourceComputeVpnTunnel(),
}

View File

@ -0,0 +1,391 @@
// ----------------------------------------------------------------------------
//
// *** 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"
"reflect"
"strconv"
"time"
"github.com/hashicorp/terraform/helper/schema"
compute "google.golang.org/api/compute/v1"
)
func resourceComputeInterconnectAttachment() *schema.Resource {
return &schema.Resource{
Create: resourceComputeInterconnectAttachmentCreate,
Read: resourceComputeInterconnectAttachmentRead,
Delete: resourceComputeInterconnectAttachmentDelete,
Importer: &schema.ResourceImporter{
State: resourceComputeInterconnectAttachmentImport,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(240 * time.Second),
Delete: schema.DefaultTimeout(240 * time.Second),
},
Schema: map[string]*schema.Schema{
"interconnect": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateRegexp(`^[a-z]([-a-z0-9]*[a-z0-9])?$`),
},
"router": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"region": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"cloud_router_ip_address": {
Type: schema.TypeString,
Computed: true,
},
"creation_timestamp": {
Type: schema.TypeString,
Computed: true,
},
"customer_router_ip_address": {
Type: schema.TypeString,
Computed: true,
},
"google_reference_id": {
Type: schema.TypeString,
Computed: true,
},
"private_interconnect_info": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tag8021q": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"self_link": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func resourceComputeInterconnectAttachmentCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
obj := make(map[string]interface{})
interconnectProp, err := expandComputeInterconnectAttachmentInterconnect(d.Get("interconnect"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("interconnect"); !isEmptyValue(reflect.ValueOf(interconnectProp)) && (ok || !reflect.DeepEqual(v, interconnectProp)) {
obj["interconnect"] = interconnectProp
}
descriptionProp, err := expandComputeInterconnectAttachmentDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
routerProp, err := expandComputeInterconnectAttachmentRouter(d.Get("router"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("router"); !isEmptyValue(reflect.ValueOf(routerProp)) && (ok || !reflect.DeepEqual(v, routerProp)) {
obj["router"] = routerProp
}
nameProp, err := expandComputeInterconnectAttachmentName(d.Get("name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
regionProp, err := expandComputeInterconnectAttachmentRegion(d.Get("region"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("region"); !isEmptyValue(reflect.ValueOf(regionProp)) && (ok || !reflect.DeepEqual(v, regionProp)) {
obj["region"] = regionProp
}
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/interconnectAttachments")
if err != nil {
return err
}
log.Printf("[DEBUG] Creating new InterconnectAttachment: %#v", obj)
res, err := sendRequest(config, "POST", url, obj)
if err != nil {
return fmt.Errorf("Error creating InterconnectAttachment: %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)
project, err := getProject(d, config)
if err != nil {
return err
}
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}
waitErr := computeOperationWaitTime(
config.clientCompute, op, project, "Creating InterconnectAttachment",
int(d.Timeout(schema.TimeoutCreate).Minutes()))
if waitErr != nil {
// The resource didn't actually create
d.SetId("")
return fmt.Errorf("Error waiting to create InterconnectAttachment: %s", waitErr)
}
log.Printf("[DEBUG] Finished creating InterconnectAttachment %q: %#v", d.Id(), res)
return resourceComputeInterconnectAttachmentRead(d, meta)
}
func resourceComputeInterconnectAttachmentRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/interconnectAttachments/{{name}}")
if err != nil {
return err
}
res, err := sendRequest(config, "GET", url, nil)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("ComputeInterconnectAttachment %q", d.Id()))
}
if err := d.Set("cloud_router_ip_address", flattenComputeInterconnectAttachmentCloudRouterIpAddress(res["cloudRouterIpAddress"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("customer_router_ip_address", flattenComputeInterconnectAttachmentCustomerRouterIpAddress(res["customerRouterIpAddress"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("interconnect", flattenComputeInterconnectAttachmentInterconnect(res["interconnect"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("description", flattenComputeInterconnectAttachmentDescription(res["description"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("private_interconnect_info", flattenComputeInterconnectAttachmentPrivateInterconnectInfo(res["privateInterconnectInfo"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("google_reference_id", flattenComputeInterconnectAttachmentGoogleReferenceId(res["googleReferenceId"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("router", flattenComputeInterconnectAttachmentRouter(res["router"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("creation_timestamp", flattenComputeInterconnectAttachmentCreationTimestamp(res["creationTimestamp"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("name", flattenComputeInterconnectAttachmentName(res["name"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("region", flattenComputeInterconnectAttachmentRegion(res["region"])); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
project, err := getProject(d, config)
if err != nil {
return err
}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
return nil
}
func resourceComputeInterconnectAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/interconnectAttachments/{{name}}")
if err != nil {
return err
}
var obj map[string]interface{}
log.Printf("[DEBUG] Deleting InterconnectAttachment %q", d.Id())
res, err := sendRequest(config, "DELETE", url, obj)
if err != nil {
return handleNotFoundError(err, d, "InterconnectAttachment")
}
project, err := getProject(d, config)
if err != nil {
return err
}
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}
err = computeOperationWaitTime(
config.clientCompute, op, project, "Deleting InterconnectAttachment",
int(d.Timeout(schema.TimeoutDelete).Minutes()))
if err != nil {
return err
}
log.Printf("[DEBUG] Finished deleting InterconnectAttachment %q: %#v", d.Id(), res)
return nil
}
func resourceComputeInterconnectAttachmentImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
parseImportId([]string{"projects/(?P<project>[^/]+)/regions/(?P<region>[^/]+)/interconnectAttachments/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<region>[^/]+)/(?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 flattenComputeInterconnectAttachmentCloudRouterIpAddress(v interface{}) interface{} {
return v
}
func flattenComputeInterconnectAttachmentCustomerRouterIpAddress(v interface{}) interface{} {
return v
}
func flattenComputeInterconnectAttachmentInterconnect(v interface{}) interface{} {
return v
}
func flattenComputeInterconnectAttachmentDescription(v interface{}) interface{} {
return v
}
func flattenComputeInterconnectAttachmentPrivateInterconnectInfo(v interface{}) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
transformed := make(map[string]interface{})
transformed["tag8021q"] =
flattenComputeInterconnectAttachmentPrivateInterconnectInfoTag8021q(original["tag8021q"])
return []interface{}{transformed}
}
func flattenComputeInterconnectAttachmentPrivateInterconnectInfoTag8021q(v interface{}) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
} // let terraform core handle it if we can't convert the string to an int.
}
return v
}
func flattenComputeInterconnectAttachmentGoogleReferenceId(v interface{}) interface{} {
return v
}
func flattenComputeInterconnectAttachmentRouter(v interface{}) interface{} {
if v == nil {
return v
}
return ConvertSelfLinkToV1(v.(string))
}
func flattenComputeInterconnectAttachmentCreationTimestamp(v interface{}) interface{} {
return v
}
func flattenComputeInterconnectAttachmentName(v interface{}) interface{} {
return v
}
func flattenComputeInterconnectAttachmentRegion(v interface{}) interface{} {
if v == nil {
return v
}
return ConvertSelfLinkToV1(v.(string))
}
func expandComputeInterconnectAttachmentInterconnect(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeInterconnectAttachmentDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeInterconnectAttachmentRouter(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseRegionalFieldValue("routers", v.(string), "project", "region", "zone", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for router: %s", err)
}
return f.RelativeLink(), nil
}
func expandComputeInterconnectAttachmentName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeInterconnectAttachmentRegion(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

@ -0,0 +1,132 @@
---
# ----------------------------------------------------------------------------
#
# *** 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_interconnect_attachment"
sidebar_current: "docs-google-compute-interconnect-attachment"
description: |-
Represents an InterconnectAttachment (VLAN attachment) resource.
---
# google\_compute\_interconnect\_attachment
Represents an InterconnectAttachment (VLAN attachment) resource. For more
information, see Creating VLAN Attachments.
## Example Usage
```hcl
resource "google_compute_router" "foobar" {
name = "my-router"
network = "${google_compute_network.foobar.name}"
}
resource "google_compute_interconnect_attachment" "default" {
name = "test-interconnect"
interconnect = "my-interconnect-id"
router = "${google_compute_router.foobar.self_link}"
}
```
## Argument Reference
The following arguments are supported:
* `interconnect` -
(Required)
URL of the underlying Interconnect object that this attachment's traffic will
traverse through.
* `router` -
(Required)
URL of the cloud router to be used for dynamic routing. This router must be in
the same region as this InterconnectAttachment. The InterconnectAttachment will
automatically connect the Interconnect to the network & region within which the
Cloud Router is configured.
* `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.
- - -
* `description` -
(Optional)
An optional description of this resource.
* `region` -
(Optional)
Region where the regional interconnect attachment resides.
* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
## Attributes Reference
In addition to the arguments listed above, the following computed attributes are exported:
* `cloud_router_ip_address` -
IPv4 address + prefix length to be configured on Cloud Router
Interface for this interconnect attachment.
* `customer_router_ip_address` -
IPv4 address + prefix length to be configured on the customer
router subinterface for this interconnect attachment.
* `private_interconnect_info` -
Information specific to an InterconnectAttachment. This property
is populated if the interconnect that this is attached to is of type DEDICATED. Structure is documented below.
* `google_reference_id` -
Google reference ID, to be used when raising support tickets with
Google or otherwise to debug backend connectivity issues.
* `creation_timestamp` -
Creation timestamp in RFC3339 text format.
* `self_link` - The URI of the created resource.
The `private_interconnect_info` block contains:
* `tag8021q` -
802.1q encapsulation tag to be used for traffic between
Google and the customer, going to and from this network and region.
## 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
InterconnectAttachment can be imported using any of these accepted formats:
```
$ terraform import google_compute_interconnect_attachment.default projects/{{project}}/regions/{{region}}/interconnectAttachments/{{name}}
$ terraform import google_compute_interconnect_attachment.default {{project}}/{{region}}/{{name}}
$ terraform import google_compute_interconnect_attachment.default {{name}}
```