Skip to content

Commit bdd9119

Browse files
modular-magicianScottSuarez
authored andcommitted
Revert "Updated datatype for mtu" (#4643) (#3112)
Signed-off-by: Modular Magician <[email protected]>
1 parent d6067d1 commit bdd9119

File tree

4 files changed

+135
-17
lines changed

4 files changed

+135
-17
lines changed

.changelog/4643.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: reverted datatype change for `mtu` in `google_compute_interconnect_attachment` as it was incompatible with existing state representation
3+
```

google-beta/resource_compute_interconnect_attachment.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ traffic will traverse through. Required if type is DEDICATED, must not
145145
be set if type is PARTNER.`,
146146
},
147147
"mtu": {
148-
Type: schema.TypeInt,
148+
Type: schema.TypeString,
149149
Computed: true,
150150
Optional: true,
151151
Description: `Maximum Transmission Unit (MTU), in bytes, of packets passing through
@@ -645,20 +645,11 @@ func flattenComputeInterconnectAttachmentDescription(v interface{}, d *schema.Re
645645
}
646646

647647
func flattenComputeInterconnectAttachmentMtu(v interface{}, d *schema.ResourceData, config *Config) interface{} {
648-
// Handles the string fixed64 format
649-
if strVal, ok := v.(string); ok {
650-
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
651-
return intVal
652-
}
653-
}
654-
655-
// number values are represented as float64
648+
// Handles int given in float64 format
656649
if floatVal, ok := v.(float64); ok {
657-
intVal := int(floatVal)
658-
return intVal
650+
return fmt.Sprintf("%d", int(floatVal))
659651
}
660-
661-
return v // let terraform core handle it otherwise
652+
return v
662653
}
663654

664655
func flattenComputeInterconnectAttachmentBandwidth(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package google
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
"testing"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
23+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
24+
)
25+
26+
func TestAccComputeInterconnectAttachment_interconnectAttachmentBasicExample(t *testing.T) {
27+
t.Parallel()
28+
29+
context := map[string]interface{}{
30+
"random_suffix": randString(t, 10),
31+
}
32+
33+
vcrTest(t, resource.TestCase{
34+
PreCheck: func() { testAccPreCheck(t) },
35+
Providers: testAccProviders,
36+
ExternalProviders: map[string]resource.ExternalProvider{
37+
"random": {},
38+
},
39+
CheckDestroy: testAccCheckComputeInterconnectAttachmentDestroyProducer(t),
40+
Steps: []resource.TestStep{
41+
{
42+
Config: testAccComputeInterconnectAttachment_interconnectAttachmentBasicExample(context),
43+
},
44+
{
45+
ResourceName: "google_compute_interconnect_attachment.on_prem",
46+
ImportState: true,
47+
ImportStateVerify: true,
48+
ImportStateVerifyIgnore: []string{"router", "candidate_subnets", "region"},
49+
},
50+
},
51+
})
52+
}
53+
54+
func testAccComputeInterconnectAttachment_interconnectAttachmentBasicExample(context map[string]interface{}) string {
55+
return Nprintf(`
56+
resource "google_compute_interconnect_attachment" "on_prem" {
57+
name = "tf-test-on-prem-attachment%{random_suffix}"
58+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
59+
type = "PARTNER"
60+
router = google_compute_router.foobar.id
61+
mtu = 1500
62+
}
63+
64+
resource "google_compute_router" "foobar" {
65+
name = "router%{random_suffix}"
66+
network = google_compute_network.foobar.name
67+
bgp {
68+
asn = 16550
69+
}
70+
}
71+
72+
resource "google_compute_network" "foobar" {
73+
name = "network%{random_suffix}"
74+
auto_create_subnetworks = false
75+
}
76+
`, context)
77+
}
78+
79+
func testAccCheckComputeInterconnectAttachmentDestroyProducer(t *testing.T) func(s *terraform.State) error {
80+
return func(s *terraform.State) error {
81+
for name, rs := range s.RootModule().Resources {
82+
if rs.Type != "google_compute_interconnect_attachment" {
83+
continue
84+
}
85+
if strings.HasPrefix(name, "data.") {
86+
continue
87+
}
88+
89+
config := googleProviderConfig(t)
90+
91+
url, err := replaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/interconnectAttachments/{{name}}")
92+
if err != nil {
93+
return err
94+
}
95+
96+
billingProject := ""
97+
98+
if config.BillingProject != "" {
99+
billingProject = config.BillingProject
100+
}
101+
102+
_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil)
103+
if err == nil {
104+
return fmt.Errorf("ComputeInterconnectAttachment still exists at %s", url)
105+
}
106+
}
107+
108+
return nil
109+
}
110+
}

website/docs/r/compute_interconnect_attachment.html.markdown

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,34 @@ information, see Creating VLAN Attachments.
2727

2828

2929

30+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
31+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=interconnect_attachment_basic&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
32+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
33+
</a>
34+
</div>
3035
## Example Usage - Interconnect Attachment Basic
3136

3237

3338
```hcl
3439
resource "google_compute_interconnect_attachment" "on_prem" {
35-
name = "on-prem-attachment"
36-
interconnect = "my-interconnect-id"
37-
router = google_compute_router.foobar.id
38-
mtu = 1500
40+
name = "on-prem-attachment"
41+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
42+
type = "PARTNER"
43+
router = google_compute_router.foobar.id
44+
mtu = 1500
3945
}
4046
4147
resource "google_compute_router" "foobar" {
4248
name = "router"
4349
network = google_compute_network.foobar.name
50+
bgp {
51+
asn = 16550
52+
}
53+
}
54+
55+
resource "google_compute_network" "foobar" {
56+
name = "network"
57+
auto_create_subnetworks = false
4458
}
4559
```
4660

0 commit comments

Comments
 (0)