Skip to content

Commit

Permalink
Revert "Updated datatype for mtu" (#4643) (#8829)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Apr 2, 2021
1 parent 36ededf commit 3c8c43e
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .changelog/4643.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: reverted datatype change for `mtu` in `google_compute_interconnect_attachment` as it was incompatible with existing state representation
```
17 changes: 4 additions & 13 deletions google/resource_compute_interconnect_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ traffic will traverse through. Required if type is DEDICATED, must not
be set if type is PARTNER.`,
},
"mtu": {
Type: schema.TypeInt,
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: `Maximum Transmission Unit (MTU), in bytes, of packets passing through
Expand Down Expand Up @@ -645,20 +645,11 @@ func flattenComputeInterconnectAttachmentDescription(v interface{}, d *schema.Re
}

func flattenComputeInterconnectAttachmentMtu(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
// Handles int given in float64 format
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
return fmt.Sprintf("%d", int(floatVal))
}

return v // let terraform core handle it otherwise
return v
}

func flattenComputeInterconnectAttachmentBandwidth(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down
110 changes: 110 additions & 0 deletions google/resource_compute_interconnect_attachment_generated_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// ----------------------------------------------------------------------------
//
// *** 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"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccComputeInterconnectAttachment_interconnectAttachmentBasicExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
},
CheckDestroy: testAccCheckComputeInterconnectAttachmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInterconnectAttachment_interconnectAttachmentBasicExample(context),
},
{
ResourceName: "google_compute_interconnect_attachment.on_prem",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"router", "candidate_subnets", "region"},
},
},
})
}

func testAccComputeInterconnectAttachment_interconnectAttachmentBasicExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_interconnect_attachment" "on_prem" {
name = "tf-test-on-prem-attachment%{random_suffix}"
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
type = "PARTNER"
router = google_compute_router.foobar.id
mtu = 1500
}
resource "google_compute_router" "foobar" {
name = "router%{random_suffix}"
network = google_compute_network.foobar.name
bgp {
asn = 16550
}
}
resource "google_compute_network" "foobar" {
name = "network%{random_suffix}"
auto_create_subnetworks = false
}
`, context)
}

func testAccCheckComputeInterconnectAttachmentDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_interconnect_attachment" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := googleProviderConfig(t)

url, err := replaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/interconnectAttachments/{{name}}")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil)
if err == nil {
return fmt.Errorf("ComputeInterconnectAttachment still exists at %s", url)
}
}

return nil
}
}
22 changes: 18 additions & 4 deletions website/docs/r/compute_interconnect_attachment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,34 @@ information, see Creating VLAN Attachments.



<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgit.luolix.top%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">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Interconnect Attachment Basic


```hcl
resource "google_compute_interconnect_attachment" "on_prem" {
name = "on-prem-attachment"
interconnect = "my-interconnect-id"
router = google_compute_router.foobar.id
mtu = 1500
name = "on-prem-attachment"
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
type = "PARTNER"
router = google_compute_router.foobar.id
mtu = 1500
}
resource "google_compute_router" "foobar" {
name = "router"
network = google_compute_network.foobar.name
bgp {
asn = 16550
}
}
resource "google_compute_network" "foobar" {
name = "network"
auto_create_subnetworks = false
}
```

Expand Down

0 comments on commit 3c8c43e

Please sign in to comment.