Skip to content

Commit

Permalink
Add fields to InterconnectAttachment to allow for PARTNER interconnec…
Browse files Browse the repository at this point in the history
…ts (#2959)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and nat-henderson committed Feb 2, 2019
1 parent b58053f commit fdeac73
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 11 deletions.
92 changes: 86 additions & 6 deletions google/resource_compute_interconnect_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"google.golang.org/api/compute/v1"
)

Expand All @@ -41,12 +42,6 @@ func resourceComputeInterconnectAttachment() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"interconnect": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"name": {
Type: schema.TypeString,
Required: true,
Expand All @@ -72,13 +67,31 @@ func resourceComputeInterconnectAttachment() *schema.Resource {
Optional: true,
ForceNew: true,
},
"edge_availability_domain": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"interconnect": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"region": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"DEDICATED", "PARTNER", "PARTNER_PROVIDER", ""}, false),
},
"vlan_tag8021q": {
Type: schema.TypeInt,
Optional: true,
Expand All @@ -100,6 +113,14 @@ func resourceComputeInterconnectAttachment() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"pairing_key": {
Type: schema.TypeString,
Computed: true,
},
"partner_asn": {
Type: schema.TypeString,
Computed: true,
},
"private_interconnect_info": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -113,6 +134,10 @@ func resourceComputeInterconnectAttachment() *schema.Resource {
},
},
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -143,6 +168,18 @@ func resourceComputeInterconnectAttachmentCreate(d *schema.ResourceData, meta in
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
edgeAvailabilityDomainProp, err := expandComputeInterconnectAttachmentEdgeAvailabilityDomain(d.Get("edge_availability_domain"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("edge_availability_domain"); !isEmptyValue(reflect.ValueOf(edgeAvailabilityDomainProp)) && (ok || !reflect.DeepEqual(v, edgeAvailabilityDomainProp)) {
obj["edgeAvailabilityDomain"] = edgeAvailabilityDomainProp
}
typeProp, err := expandComputeInterconnectAttachmentType(d.Get("type"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("type"); !isEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) {
obj["type"] = typeProp
}
routerProp, err := expandComputeInterconnectAttachmentRouter(d.Get("router"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -250,9 +287,24 @@ func resourceComputeInterconnectAttachmentRead(d *schema.ResourceData, meta inte
if err := d.Set("description", flattenComputeInterconnectAttachmentDescription(res["description"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("edge_availability_domain", flattenComputeInterconnectAttachmentEdgeAvailabilityDomain(res["edgeAvailabilityDomain"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("pairing_key", flattenComputeInterconnectAttachmentPairingKey(res["pairingKey"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("partner_asn", flattenComputeInterconnectAttachmentPartnerAsn(res["partnerAsn"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("private_interconnect_info", flattenComputeInterconnectAttachmentPrivateInterconnectInfo(res["privateInterconnectInfo"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("type", flattenComputeInterconnectAttachmentType(res["type"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("state", flattenComputeInterconnectAttachmentState(res["state"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("google_reference_id", flattenComputeInterconnectAttachmentGoogleReferenceId(res["googleReferenceId"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
Expand Down Expand Up @@ -350,6 +402,18 @@ func flattenComputeInterconnectAttachmentDescription(v interface{}, d *schema.Re
return v
}

func flattenComputeInterconnectAttachmentEdgeAvailabilityDomain(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeInterconnectAttachmentPairingKey(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeInterconnectAttachmentPartnerAsn(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeInterconnectAttachmentPrivateInterconnectInfo(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return nil
Expand All @@ -373,6 +437,14 @@ func flattenComputeInterconnectAttachmentPrivateInterconnectInfoTag8021q(v inter
return v
}

func flattenComputeInterconnectAttachmentType(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeInterconnectAttachmentState(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeInterconnectAttachmentGoogleReferenceId(v interface{}, d *schema.ResourceData) interface{} {
return v
}
Expand Down Expand Up @@ -421,6 +493,14 @@ func expandComputeInterconnectAttachmentDescription(v interface{}, d *schema.Res
return v, nil
}

func expandComputeInterconnectAttachmentEdgeAvailabilityDomain(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeInterconnectAttachmentType(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 {
Expand Down
38 changes: 33 additions & 5 deletions website/docs/r/compute_interconnect_attachment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ resource "google_compute_router" "foobar" {
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
Expand All @@ -72,10 +67,30 @@ The following arguments are supported:
- - -


* `interconnect` -
(Optional)
URL of the underlying Interconnect object that this attachment's
traffic will traverse through. Required if type is DEDICATED, must not
be set if type is PARTNER.

* `description` -
(Optional)
An optional description of this resource.

* `edge_availability_domain` -
(Optional)
Desired availability domain for the attachment. Only available for type
PARTNER, at creation time. For improved reliability, customers should
configure a pair of attachments with one per availability domain. The
selected availability domain will be provided to the Partner via the
pairing key so that the provisioned circuit will lie in the specified
domain. If not specified, the value will default to AVAILABILITY_DOMAIN_ANY.

* `type` -
(Optional)
The type of InterconnectAttachment you wish to create. Defaults to
DEDICATED.

* `candidate_subnets` -
(Optional)
Up to 16 candidate prefixes that can be used to restrict the allocation
Expand Down Expand Up @@ -110,10 +125,23 @@ In addition to the arguments listed above, the following computed attributes are
IPv4 address + prefix length to be configured on the customer
router subinterface for this interconnect attachment.

* `pairing_key` -
[Output only for type PARTNER. Not present for DEDICATED]. The opaque
identifier of an PARTNER attachment used to initiate provisioning with
a selected partner. Of the form "XXXXX/region/domain"

* `partner_asn` -
[Output only for type PARTNER. Not present for DEDICATED]. Optional
BGP ASN for the router that should be supplied by a layer 3 Partner if
they configured BGP on behalf of the customer.

* `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.

* `state` -
[Output Only] The current state of this attachment's functionality.

* `google_reference_id` -
Google reference ID, to be used when raising support tickets with
Google or otherwise to debug backend connectivity issues.
Expand Down

0 comments on commit fdeac73

Please sign in to comment.