Skip to content

Commit

Permalink
Add Network and Subnet resources for edgenetwork (#8905) (#1457)
Browse files Browse the repository at this point in the history
* Add Network and Subnet resources for edgenetwork

* Fix lint

* Added labels field to acceptance tests; Removed send_empty_value:false from vlan_id field in Subnet

* Skip edgenetwork acceptance tests

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 18, 2023
1 parent 30b7542 commit cc0190f
Show file tree
Hide file tree
Showing 4 changed files with 230 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.14.1
github.com/hashicorp/terraform-json v0.14.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20230918200954-5c58da1b365f
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20230918215714-f833445eb741
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfD
github.com/hashicorp/terraform-plugin-mux v0.8.0 h1:WCTP66mZ+iIaIrCNJnjPEYnVjawTshnDJu12BcXK1EI=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 h1:FtCLTiTcykdsURXPt/ku7fYXm3y19nbzbZcUxHx9RbI=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0/go.mod h1:80wf5oad1tW+oLnbXS4UTYmDCrl7BuN1Q+IA91X1a4Y=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20230918200954-5c58da1b365f h1:sljaK1yx7wW1dI+lU19FHRsKy1OJf/fxGUFM3EFkNpM=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20230918200954-5c58da1b365f/go.mod h1:PK7PrQnwlP2eFuSyQD0/txEh4sF50euI3EYbd3GkZik=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20230918215714-f833445eb741 h1:6kymeEku5csrS88+a0RnplfGXBO5NllSZH2J/szumBg=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20230918215714-f833445eb741/go.mod h1:PK7PrQnwlP2eFuSyQD0/txEh4sF50euI3EYbd3GkZik=
github.com/hashicorp/terraform-registry-address v0.1.0 h1:W6JkV9wbum+m516rCl5/NjKxCyTVaaUBbzYcMzBDO3U=
github.com/hashicorp/terraform-registry-address v0.1.0/go.mod h1:EnyO2jYO6j29DTHbJcm00E5nQTFeTtyZH3H5ycydQ5A=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// ----------------------------------------------------------------------------
//
// *** 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 (
"reflect"

"github.com/GoogleCloudPlatform/terraform-google-conversion/v2/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 EdgenetworkNetworkAssetType string = "edgenetwork.googleapis.com/Network"

func ResourceConverterEdgenetworkNetwork() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: EdgenetworkNetworkAssetType,
Convert: GetEdgenetworkNetworkCaiObject,
}
}

func GetEdgenetworkNetworkCaiObject(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}}/networks/{{network_id}}")
if err != nil {
return []cai.Asset{}, err
}
if obj, err := GetEdgenetworkNetworkApiObject(d, config); err == nil {
return []cai.Asset{{
Name: name,
Type: EdgenetworkNetworkAssetType,
Resource: &cai.AssetResource{
Version: "v1",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/edgenetwork/v1/rest",
DiscoveryName: "Network",
Data: obj,
},
}}, nil
} else {
return []cai.Asset{}, err
}
}

func GetEdgenetworkNetworkApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
labelsProp, err := expandEdgenetworkNetworkLabels(d.Get("labels"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
descriptionProp, err := expandEdgenetworkNetworkDescription(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
}
mtuProp, err := expandEdgenetworkNetworkMtu(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
}

return obj, nil
}

func expandEdgenetworkNetworkLabels(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
}

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

func expandEdgenetworkNetworkMtu(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
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/v2/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 EdgenetworkSubnetAssetType string = "edgenetwork.googleapis.com/Subnet"

func ResourceConverterEdgenetworkSubnet() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: EdgenetworkSubnetAssetType,
Convert: GetEdgenetworkSubnetCaiObject,
}
}

func GetEdgenetworkSubnetCaiObject(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}}/subnets/{{subnet_id}}")
if err != nil {
return []cai.Asset{}, err
}
if obj, err := GetEdgenetworkSubnetApiObject(d, config); err == nil {
return []cai.Asset{{
Name: name,
Type: EdgenetworkSubnetAssetType,
Resource: &cai.AssetResource{
Version: "v1",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/edgenetwork/v1/rest",
DiscoveryName: "Subnet",
Data: obj,
},
}}, nil
} else {
return []cai.Asset{}, err
}
}

func GetEdgenetworkSubnetApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
labelsProp, err := expandEdgenetworkSubnetLabels(d.Get("labels"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
descriptionProp, err := expandEdgenetworkSubnetDescription(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
}
networkProp, err := expandEdgenetworkSubnetNetwork(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
}
ipv4CidrProp, err := expandEdgenetworkSubnetIpv4Cidr(d.Get("ipv4_cidr"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("ipv4_cidr"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipv4CidrProp)) && (ok || !reflect.DeepEqual(v, ipv4CidrProp)) {
obj["ipv4Cidr"] = ipv4CidrProp
}
ipv6CidrProp, err := expandEdgenetworkSubnetIpv6Cidr(d.Get("ipv6_cidr"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("ipv6_cidr"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipv6CidrProp)) && (ok || !reflect.DeepEqual(v, ipv6CidrProp)) {
obj["ipv6Cidr"] = ipv6CidrProp
}
vlanIdProp, err := expandEdgenetworkSubnetVlanId(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
}

return obj, nil
}

func expandEdgenetworkSubnetLabels(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
}

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

func expandEdgenetworkSubnetNetwork(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 expandEdgenetworkSubnetIpv4Cidr(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

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

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

0 comments on commit cc0190f

Please sign in to comment.