-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Network and Subnet resources for edgenetwork (#8905) (#1457)
* 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
1 parent
30b7542
commit cc0190f
Showing
4 changed files
with
230 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
tfplan2cai/converters/google/resources/services/edgenetwork/edgenetwork_network.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
131 changes: 131 additions & 0 deletions
131
tfplan2cai/converters/google/resources/services/edgenetwork/edgenetwork_subnet.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |