Skip to content

Commit

Permalink
Add edgenetwork InterconnectAttachment resource. (#12586) (#3282)
Browse files Browse the repository at this point in the history
[upstream:6d54b5142d999bfee3a7570636c4cd322f54733b]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 8, 2025
1 parent ee1aa50 commit 6357a41
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/hcl/v2 v2.20.1
github.com/hashicorp/terraform-json v0.22.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20250108192828-ba672eaaf37a
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20250108211636-a3aa1b8fb4d8
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 h1:qHprzXy/As0rxedphECBEQAh
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0/go.mod h1:H+8tjs9TjV2w57QFVSMBQacf8k/E1XwLXGCARgViC6A=
github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c=
github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20250108192828-ba672eaaf37a h1:YU6g+V6toQiuN0O/HUaSkOc24ieYd4Sn2KfFi63doOs=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20250108192828-ba672eaaf37a/go.mod h1:3oxffi8u7i0pihgQGidFrcv1eysjxO4kfEw/Zc7/YDU=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20250108211636-a3aa1b8fb4d8 h1:XmhKIjHK+NekGZoVPHHTaKVP4TjgeExF8fou24gbTCk=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20250108211636-a3aa1b8fb4d8/go.mod h1:3oxffi8u7i0pihgQGidFrcv1eysjxO4kfEw/Zc7/YDU=
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// 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 edgenetwork

import (
"fmt"
"reflect"

"github.com/GoogleCloudPlatform/terraform-google-conversion/v5/tfplan2cai/converters/google/resources/cai"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

const EdgenetworkInterconnectAttachmentAssetType string = "edgenetwork.googleapis.com/InterconnectAttachment"

func ResourceConverterEdgenetworkInterconnectAttachment() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: EdgenetworkInterconnectAttachmentAssetType,
Convert: GetEdgenetworkInterconnectAttachmentCaiObject,
}
}

func GetEdgenetworkInterconnectAttachmentCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) {
name, err := cai.AssetName(d, config, "//edgenetwork.googleapis.com/projects/{{project}}/locations/{{location}}/zones/{{zone}}/interconnectAttachments/{{interconnect_attachment_id}}")
if err != nil {
return []cai.Asset{}, err
}
if obj, err := GetEdgenetworkInterconnectAttachmentApiObject(d, config); err == nil {
return []cai.Asset{{
Name: name,
Type: EdgenetworkInterconnectAttachmentAssetType,
Resource: &cai.AssetResource{
Version: "v1",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/edgenetwork/v1/rest",
DiscoveryName: "InterconnectAttachment",
Data: obj,
},
}}, nil
} else {
return []cai.Asset{}, err
}
}

func GetEdgenetworkInterconnectAttachmentApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
descriptionProp, err := expandEdgenetworkInterconnectAttachmentDescription(d.Get("description"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
interconnectProp, err := expandEdgenetworkInterconnectAttachmentInterconnect(d.Get("interconnect"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("interconnect"); !tpgresource.IsEmptyValue(reflect.ValueOf(interconnectProp)) && (ok || !reflect.DeepEqual(v, interconnectProp)) {
obj["interconnect"] = interconnectProp
}
networkProp, err := expandEdgenetworkInterconnectAttachmentNetwork(d.Get("network"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("network"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) {
obj["network"] = networkProp
}
vlanIdProp, err := expandEdgenetworkInterconnectAttachmentVlanId(d.Get("vlan_id"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("vlan_id"); !tpgresource.IsEmptyValue(reflect.ValueOf(vlanIdProp)) && (ok || !reflect.DeepEqual(v, vlanIdProp)) {
obj["vlanId"] = vlanIdProp
}
mtuProp, err := expandEdgenetworkInterconnectAttachmentMtu(d.Get("mtu"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("mtu"); !tpgresource.IsEmptyValue(reflect.ValueOf(mtuProp)) && (ok || !reflect.DeepEqual(v, mtuProp)) {
obj["mtu"] = mtuProp
}
labelsProp, err := expandEdgenetworkInterconnectAttachmentEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}

return obj, nil
}

func expandEdgenetworkInterconnectAttachmentDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandEdgenetworkInterconnectAttachmentInterconnect(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandEdgenetworkInterconnectAttachmentNetwork(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
f, err := tpgresource.ParseZonalFieldValue("networks", v.(string), "project", "zone", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for network: %s", err)
}
return f.RelativeLink(), nil
}

func expandEdgenetworkInterconnectAttachmentVlanId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandEdgenetworkInterconnectAttachmentMtu(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandEdgenetworkInterconnectAttachmentEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

0 comments on commit 6357a41

Please sign in to comment.