Skip to content

Commit

Permalink
Network profile and RDMA v1 support (#12589) (#21027)
Browse files Browse the repository at this point in the history
[upstream:fc8e41c5c943a485b66f5de967ff40d36019457a]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 23, 2025
1 parent 2bcc0bb commit 6710afa
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .changelog/12589.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `network_profile` field to `google_compute_network` resource.
```
8 changes: 8 additions & 0 deletions google/services/compute/data_source_google_compute_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func DataSourceGoogleComputeNetwork() *schema.Resource {
Computed: true,
},

"network_profile": {
Type: schema.TypeString,
Optional: true,
},

"self_link": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -92,6 +97,9 @@ func dataSourceGoogleComputeNetworkRead(d *schema.ResourceData, meta interface{}
if err := d.Set("internal_ipv6_range", network.InternalIpv6Range); err != nil {
return fmt.Errorf("Error setting internal_ipv6_range: %s", err)
}
if err := d.Set("network_profile", network.NetworkProfile); err != nil {
return fmt.Errorf("Error setting network_profile: %s", err)
}
if err := d.Set("self_link", network.SelfLink); err != nil {
return fmt.Errorf("Error setting self_link: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions google/services/compute/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ func ResourceComputeInstance() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"GVNIC", "VIRTIO_NET", "IDPF"}, false),
Description: `The type of vNIC to be used on this interface. Possible values:GVNIC, VIRTIO_NET, IDPF`,
ValidateFunc: validation.StringInSlice([]string{"GVNIC", "VIRTIO_NET", "IDPF", "MRDMA", "IRDMA"}, false),
Description: `The type of vNIC to be used on this interface. Possible values:GVNIC, VIRTIO_NET, IDPF, MRDMA, and IRDMA`,
},
"access_config": {
Type: schema.TypeList,
Expand Down
4 changes: 2 additions & 2 deletions google/services/compute/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ Google Cloud KMS.`,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"GVNIC", "VIRTIO_NET"}, false),
Description: `The type of vNIC to be used on this interface. Possible values:GVNIC, VIRTIO_NET`,
ValidateFunc: validation.StringInSlice([]string{"GVNIC", "VIRTIO_NET", "MRDMA", "IRDMA"}, false),
Description: `The type of vNIC to be used on this interface. Possible values:GVNIC, VIRTIO_NET, MRDMA, and IRDMA`,
},
"access_config": {
Type: schema.TypeList,
Expand Down
27 changes: 27 additions & 0 deletions google/services/compute/resource_compute_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ with varying MTUs.`,
Description: `Set the order that Firewall Rules and Firewall Policies are evaluated. Default value: "AFTER_CLASSIC_FIREWALL" Possible values: ["BEFORE_CLASSIC_FIREWALL", "AFTER_CLASSIC_FIREWALL"]`,
Default: "AFTER_CLASSIC_FIREWALL",
},
"network_profile": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `A full or partial URL of the network profile to apply to this network.
This field can be set only at resource creation time. For example, the
following are valid URLs:
* https://www.googleapis.com/compute/v1/projects/{projectId}/global/networkProfiles/{network_profile_name}
* projects/{projectId}/global/networkProfiles/{network_profile_name}`,
},
"bgp_always_compare_med": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -252,6 +262,12 @@ func resourceComputeNetworkCreate(d *schema.ResourceData, meta interface{}) erro
} else if v, ok := d.GetOkExists("network_firewall_policy_enforcement_order"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkFirewallPolicyEnforcementOrderProp)) && (ok || !reflect.DeepEqual(v, networkFirewallPolicyEnforcementOrderProp)) {
obj["networkFirewallPolicyEnforcementOrder"] = networkFirewallPolicyEnforcementOrderProp
}
networkProfileProp, err := expandComputeNetworkNetworkProfile(d.Get("network_profile"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("network_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkProfileProp)) && (ok || !reflect.DeepEqual(v, networkProfileProp)) {
obj["networkProfile"] = networkProfileProp
}

obj, err = resourceComputeNetworkEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -451,6 +467,9 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("network_firewall_policy_enforcement_order", flattenComputeNetworkNetworkFirewallPolicyEnforcementOrder(res["networkFirewallPolicyEnforcementOrder"], d, config)); err != nil {
return fmt.Errorf("Error reading Network: %s", err)
}
if err := d.Set("network_profile", flattenComputeNetworkNetworkProfile(res["networkProfile"], d, config)); err != nil {
return fmt.Errorf("Error reading Network: %s", err)
}
if err := d.Set("self_link", tpgresource.ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading Network: %s", err)
}
Expand Down Expand Up @@ -706,6 +725,10 @@ func flattenComputeNetworkNetworkFirewallPolicyEnforcementOrder(v interface{}, d
return v
}

func flattenComputeNetworkNetworkProfile(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandComputeNetworkDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -783,6 +806,10 @@ func expandComputeNetworkNetworkFirewallPolicyEnforcementOrder(v interface{}, d
return v, nil
}

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

func resourceComputeNetworkEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
delete(obj, "numeric_id") // Field doesn't exist in the API
return obj, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fields:
- field: 'network_firewall_policy_enforcement_order'
- field: 'network_id'
api_field: 'id'
- field: 'network_profile'
- field: 'numeric_id'
- field: 'routing_config.bgp_always_compare_med'
- field: 'routing_config.bgp_best_path_selection_mode'
Expand Down
69 changes: 69 additions & 0 deletions google/services/compute/resource_compute_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
"regexp"
"testing"

Expand Down Expand Up @@ -210,6 +211,34 @@ func TestAccComputeNetwork_bgpInterRegionCostAndUpdate(t *testing.T) {
})
}

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

var network compute.Network
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-network-profile-%s", suffixName)
projectId := envvar.GetTestProjectFromEnv()

profileURL := fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networkProfiles/europe-west1-b-vpc-roce", projectId)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNetwork_network_profile(networkName, profileURL),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.acc_network_network_profile", &network),
testAccCheckComputeNetworkHasNetworkProfile(
t, "google_compute_network.acc_network_network_profile", &network, profileURL),
),
},
},
})
}

func TestAccComputeNetwork_numericId(t *testing.T) {
t.Parallel()
suffixName := acctest.RandString(t, 10)
Expand Down Expand Up @@ -523,6 +552,35 @@ func testAccCheckComputeNetworkHasRoutingMode(t *testing.T, n string, network *c
}
}

func testAccCheckComputeNetworkHasNetworkProfile(t *testing.T, n string, network *compute.Network, networkProfile string) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := acctest.GoogleProviderConfig(t)

rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.Attributes["network_profile"] == "" {
return fmt.Errorf("Network profile not found on resource")
}

found, err := config.NewComputeClient(config.UserAgent).Networks.Get(
config.Project, network.Name).Do()
if err != nil {
return err
}

foundNetworkProfile := found.NetworkProfile

if tpgresource.CompareSelfLinkOrResourceName("", foundNetworkProfile, networkProfile, nil) != true {
return fmt.Errorf("Expected Network Profile always compare med %s to match actual Network Profile always compare med %s", networkProfile, foundNetworkProfile)
}

return nil
}
}

func testAccCheckComputeNetworkHasNetworkFirewallPolicyEnforcementOrder(t *testing.T, n string, network *compute.Network, order string) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := acctest.GoogleProviderConfig(t)
Expand Down Expand Up @@ -620,6 +678,17 @@ resource "google_compute_network" "acc_network_bgp_inter_region_cost" {
`, networkName, bgpInterRegionCost)
}

func testAccComputeNetwork_network_profile(networkName, networkProfile string) string {
return fmt.Sprintf(`
resource "google_compute_network" "acc_network_network_profile" {
name = "%s"
routing_mode = "REGIONAL"
network_profile = "%s"
auto_create_subnetworks = false
}
`, networkName, networkProfile)
}

func testAccComputeNetwork_deleteDefaultRoute(networkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "bar" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ Google Cloud KMS.`,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"GVNIC", "VIRTIO_NET"}, false),
Description: `The type of vNIC to be used on this interface. Possible values:GVNIC, VIRTIO_NET`,
ValidateFunc: validation.StringInSlice([]string{"GVNIC", "VIRTIO_NET", "MRDMA", "IRDMA"}, false),
Description: `The type of vNIC to be used on this interface. Possible values:GVNIC, VIRTIO_NET, MRDMA, and IRDMA`,
},
"access_config": {
Type: schema.TypeList,
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/compute_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ In addition to the arguments listed above, the following attributes are exported

* `internal_ipv6_range` - The ula internal ipv6 range assigned to this network.

* `network_profile` - [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) A full or partial URL of the network profile to apply to this network.
* `network_profile` - A full or partial URL of the network profile to apply to this network.

* `subnetworks_self_links` - the list of subnetworks which belong to the network

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ is desired, you will need to modify your state file manually using
array of alias IP ranges for this network interface. Can only be specified for network
interfaces on subnet-mode networks. Structure [documented below](#nested_alias_ip_range).

* `nic_type` - (Optional) The type of vNIC to be used on this interface. Possible values: GVNIC, VIRTIO_NET, IDPF. In the beta provider the additional values of MRDMA and IRDMA are supported.
* `nic_type` - (Optional) The type of vNIC to be used on this interface. Possible values: GVNIC, VIRTIO_NET, IDPF, MRDMA, IRDMA.

* `network_attachment` - (Optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) The URL of the network attachment that this interface should connect to in the following format: `projects/{projectNumber}/regions/{region_name}/networkAttachments/{network_attachment_name}`.

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/compute_instance_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ The following arguments are supported:
array of alias IP ranges for this network interface. Can only be specified for network
interfaces on subnet-mode networks. Structure [documented below](#nested_alias_ip_range).

* `nic_type` - (Optional) The type of vNIC to be used on this interface. Possible values: GVNIC, VIRTIO_NET. In the beta provider the additional values of MRDMA and IRDMA are supported.
* `nic_type` - (Optional) The type of vNIC to be used on this interface. Possible values: GVNIC, VIRTIO_NET, MRDMA, IRDMA.

* `stack_type` - (Optional) The stack type for this network interface to identify whether the IPv6 feature is enabled or not. Values are IPV4_IPV6, IPV6_ONLY or IPV4_ONLY. If not specified, IPV4_ONLY will be used.

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/compute_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ The following arguments are supported:
Possible values are: `BEFORE_CLASSIC_FIREWALL`, `AFTER_CLASSIC_FIREWALL`.

* `network_profile` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
(Optional)
A full or partial URL of the network profile to apply to this network.
This field can be set only at resource creation time. For example, the
following are valid URLs:
* https://www.googleapis.com/compute/beta/projects/{projectId}/global/networkProfiles/{network_profile_name}
* https://www.googleapis.com/compute/v1/projects/{projectId}/global/networkProfiles/{network_profile_name}
* projects/{projectId}/global/networkProfiles/{network_profile_name}

* `project` - (Optional) The ID of the project in which the resource belongs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ The following arguments are supported:
array of alias IP ranges for this network interface. Can only be specified for network
interfaces on subnet-mode networks. Structure [documented below](#nested_alias_ip_range).

* `nic_type` - (Optional) The type of vNIC to be used on this interface. Possible values: GVNIC, VIRTIO_NET. In the beta provider the additional values of MRDMA and IRDMA are supported.
* `nic_type` - (Optional) The type of vNIC to be used on this interface. Possible values: GVNIC, VIRTIO_NET, MRDMA, IRDMA.

* `stack_type` - (Optional) The stack type for this network interface to identify whether the IPv6 feature is enabled or not. Values are IPV4_IPV6, IPV6_ONLY or IPV4_ONLY. If not specified, IPV4_ONLY will be used.

Expand Down

0 comments on commit 6710afa

Please sign in to comment.