Skip to content

Commit

Permalink
megaport_aws_vxc, megaport_gcp_vxc: fix imports
Browse files Browse the repository at this point in the history
When importing a resource, we have no access to the config and cannot
properly setup the state with regard to the `product_uid` and
`connected_product_uid` attributes. This change leaves the `product_uid`
attribute empty if the value is unknown (which will happen when
importing any of these two resources). Additionally, it introduces a
DiffSuppressFunc which will force terraform to ignore changes to the attribute
if its value in the state is empty.

The result is that we have a clean plan after import, working around the
load balancing behaviour for cloud partner ports. However, it also means
that to modify the `product_uid` value of the B-End of a cloud VXC, the
resource will have to be tainted.

Signed-off-by: Dimitrios Karagiannis <[email protected]>
  • Loading branch information
alkar committed Feb 13, 2020
1 parent 77975d6 commit 4899cb1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
8 changes: 7 additions & 1 deletion megaport/resource_megaport_aws_vxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func resourceMegaportVxcAwsEndElem() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return old == ""
},
},
"connected_product_uid": {
Type: schema.TypeString,
Expand Down Expand Up @@ -157,7 +160,10 @@ func resourceMegaportAwsVxcRead(d *schema.ResourceData, m interface{}) error {
if err := d.Set("a_end", flattenVxcEnd(p.AEnd)); err != nil {
return err
}
puid := d.Get("b_end").([]interface{})[0].(map[string]interface{})["product_uid"].(string)
puid := ""
if v := d.Get("b_end").([]interface{}); len(v) > 0 {
puid = v[0].(map[string]interface{})["product_uid"].(string)
}
if err := d.Set("b_end", flattenVxcEndAws(puid, p)); err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion megaport/resource_megaport_gcp_vxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func resourceMegaportVxcGcpEndElem() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return old == ""
},
},
"connected_product_uid": {
Type: schema.TypeString,
Expand Down Expand Up @@ -100,7 +103,10 @@ func resourceMegaportGcpVxcRead(d *schema.ResourceData, m interface{}) error {
if err := d.Set("a_end", flattenVxcEnd(p.AEnd)); err != nil {
return err
}
puid := d.Get("b_end").([]interface{})[0].(map[string]interface{})["product_uid"].(string)
puid := ""
if v := d.Get("b_end").([]interface{}); len(v) > 0 {
puid = v[0].(map[string]interface{})["product_uid"].(string)
}
if err := d.Set("b_end", flattenVxcEndGcp(puid, p)); err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions website/docs/r/aws_vxc.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,18 @@ plan when the aforementioned situations occur.
In addition to all arguments above, the following attributes are exported:

* `id` - The unique product id of the port.

## Import

The AWS VXC can be imported using its product uid, like any other resource,
e.g.:

```
$ terraform import megaport_aws_vxc.foobar 1f33ea1d-ecc2-4fc3-a3a4-1e4774b04d76
```

!> **Warning:** When a AWS VXC is imported, any changes to the B End
`product_uid` attribute are ignored. To force an update, you will need to
`taint` the resource. After re-creating the resource, it will start to behave as
expected and will compute the full diff. This is to work around the load
balancing behaviour mentioned in the Note above.
15 changes: 15 additions & 0 deletions website/docs/r/gcp_vxc.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,18 @@ plan when the aforementioned situations occur.
In addition to all arguments above, the following attributes are exported:

* `id` - The unique product id of the port.

## Import

The GCP VXC can be imported using its product uid, like any other resource,
e.g.:

```
$ terraform import megaport_gcp_vxc.foobar 1f33ea1d-ecc2-4fc3-a3a4-1e4774b04d76
```

!> **Warning:** When a GCP VXC is imported, any changes to the B End
`product_uid` attribute are ignored. To force an update, you will need to
`taint` the resource. After re-creating the resource, it will start to behave as
expected and will compute the full diff. This is to work around the load
balancing behaviour mentioned in the Note above.

0 comments on commit 4899cb1

Please sign in to comment.