Add vlan tag and subnet candidates to Interconnect Attachments. (#2882)

Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
The Magician 2019-01-22 13:05:11 -08:00 committed by Nathan McKinley
parent d30a7c4af0
commit f2649bcbdb
2 changed files with 67 additions and 0 deletions

View File

@ -59,6 +59,14 @@ func resourceComputeInterconnectAttachment() *schema.Resource {
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"candidate_subnets": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"description": {
Type: schema.TypeString,
Optional: true,
@ -71,6 +79,11 @@ func resourceComputeInterconnectAttachment() *schema.Resource {
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"vlan_tag8021q": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"cloud_router_ip_address": {
Type: schema.TypeString,
Computed: true,
@ -142,6 +155,18 @@ func resourceComputeInterconnectAttachmentCreate(d *schema.ResourceData, meta in
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
candidateSubnetsProp, err := expandComputeInterconnectAttachmentCandidateSubnets(d.Get("candidate_subnets"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("candidate_subnets"); !isEmptyValue(reflect.ValueOf(candidateSubnetsProp)) && (ok || !reflect.DeepEqual(v, candidateSubnetsProp)) {
obj["candidateSubnets"] = candidateSubnetsProp
}
vlanTag8021qProp, err := expandComputeInterconnectAttachmentVlanTag8021q(d.Get("vlan_tag8021q"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("vlan_tag8021q"); !isEmptyValue(reflect.ValueOf(vlanTag8021qProp)) && (ok || !reflect.DeepEqual(v, vlanTag8021qProp)) {
obj["vlanTag8021q"] = vlanTag8021qProp
}
regionProp, err := expandComputeInterconnectAttachmentRegion(d.Get("region"), d, config)
if err != nil {
return err
@ -240,6 +265,12 @@ func resourceComputeInterconnectAttachmentRead(d *schema.ResourceData, meta inte
if err := d.Set("name", flattenComputeInterconnectAttachmentName(res["name"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("candidate_subnets", flattenComputeInterconnectAttachmentCandidateSubnets(res["candidateSubnets"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("vlan_tag8021q", flattenComputeInterconnectAttachmentVlanTag8021q(res["vlanTag8021q"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
if err := d.Set("region", flattenComputeInterconnectAttachmentRegion(res["region"], d)); err != nil {
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
}
@ -361,6 +392,20 @@ func flattenComputeInterconnectAttachmentName(v interface{}, d *schema.ResourceD
return v
}
func flattenComputeInterconnectAttachmentCandidateSubnets(v interface{}, d *schema.ResourceData) interface{} {
return v
}
func flattenComputeInterconnectAttachmentVlanTag8021q(v interface{}, d *schema.ResourceData) 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 flattenComputeInterconnectAttachmentRegion(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return v
@ -388,6 +433,14 @@ func expandComputeInterconnectAttachmentName(v interface{}, d *schema.ResourceDa
return v, nil
}
func expandComputeInterconnectAttachmentCandidateSubnets(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeInterconnectAttachmentVlanTag8021q(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 {

View File

@ -76,6 +76,20 @@ The following arguments are supported:
(Optional)
An optional description of this resource.
* `candidate_subnets` -
(Optional)
Up to 16 candidate prefixes that can be used to restrict the allocation
of cloudRouterIpAddress and customerRouterIpAddress for this attachment.
All prefixes must be within link-local address space (169.254.0.0/16)
and must be /29 or shorter (/28, /27, etc). Google will attempt to select
an unused /29 from the supplied candidate prefix(es). The request will
fail if all possible /29s are in use on Google's edge. If not supplied,
Google will randomly select an unused /29 from all of link-local space.
* `vlan_tag8021q` -
(Optional)
The IEEE 802.1Q VLAN tag for this attachment, in the range 2-4094.
* `region` -
(Optional)
Region where the regional interconnect attachment resides.