Skip to content

Commit

Permalink
Allow for IPV6_ONLY stackType configurations (#12485)
Browse files Browse the repository at this point in the history
Co-authored-by: Zhenhua Li <[email protected]>
  • Loading branch information
karolgorc and zli82016 authored Jan 8, 2025
1 parent 2b00b9b commit c1ae9f3
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 7 deletions.
13 changes: 13 additions & 0 deletions mmv1/products/compute/Subnetwork.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ examples:
network_name: 'network-reserved-secondary-range'
primary_range_name: 'reserved-primary'
secondary_range_name: 'reserved-secondary'
- name: 'subnetwork_ipv6_only_internal'
primary_resource_id: 'subnetwork-ipv6-only'
exclude_docs: true
vars:
subnetwork_name: 'subnet-ipv6-only'
network_name: 'network-ipv6-only'
- name: 'subnetwork_ipv6_only_external'
primary_resource_id: 'subnetwork-ipv6-only'
exclude_docs: true
vars:
subnetwork_name: 'subnet-ipv6-only'
network_name: 'network-ipv6-only'
virtual_fields:
- name: 'send_secondary_ip_range_if_empty'
description: |
Expand Down Expand Up @@ -403,6 +415,7 @@ properties:
enum_values:
- 'IPV4_ONLY'
- 'IPV4_IPV6'
- 'IPV6_ONLY'
- name: 'ipv6AccessType'
type: Enum
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "google_compute_subnetwork" "subnetwork-ipv6-only" {
name = "{{index $.Vars "subnetwork_name"}}"
region = "us-central1"
network = google_compute_network.custom-test.id
stack_type = "IPV6_ONLY"
ipv6_access_type = "EXTERNAL"
}

resource "google_compute_network" "custom-test" {
name = "{{index $.Vars "network_name"}}"
auto_create_subnetworks = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "google_compute_subnetwork" "subnetwork-ipv6-only" {
name = "{{index $.Vars "subnetwork_name"}}"
region = "us-central1"
network = google_compute_network.custom-test.id
stack_type = "IPV6_ONLY"
ipv6_access_type = "INTERNAL"
}

resource "google_compute_network" "custom-test" {
name = "{{index $.Vars "network_name"}}"
auto_create_subnetworks = false
enable_ula_internal_ipv6 = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func ResourceComputeInstance() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"IPV4_ONLY", "IPV4_IPV6", ""}, false),
ValidateFunc: validation.StringInSlice([]string{"IPV4_ONLY", "IPV4_IPV6", "IPV6_ONLY", ""}, false),
Description: `The stack type for this network interface to identify whether the IPv6 feature is enabled or not. If not specified, IPV4_ONLY will be used.`,
},

Expand All @@ -548,7 +548,7 @@ func ResourceComputeInstance() *schema.Resource {

"ipv6_access_config": {
Type: schema.TypeList,
Optional: true,
Optional: true,
Description: `An array of IPv6 access configurations for this interface. Currently, only one IPv6 access config, DIRECT_IPV6, is supported. If there is no ipv6AccessConfig specified, then this instance will have no external IPv6 Internet access.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ Google Cloud KMS.`,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"IPV4_ONLY", "IPV4_IPV6", ""}, false),
ValidateFunc: validation.StringInSlice([]string{"IPV4_ONLY", "IPV4_IPV6", "IPV6_ONLY", ""}, false),
Description: `The stack type for this network interface to identify whether the IPv6 feature is enabled or not. If not specified, IPV4_ONLY will be used.`,
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4278,6 +4278,27 @@ func TestAccComputeInstance_NicStackTypeUpdate(t *testing.T) {
})
}

func TestAccComputeInstance_NicStackType_IPV6(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"instance_name": fmt.Sprintf("tf-test-compute-instance-%s", acctest.RandString(t, 10)),
"suffix": acctest.RandString(t, 10),
"env_region": envvar.GetTestRegionFromEnv(),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstance_nicStackTypeUpdate_ipv6(context),
},
},
})
}


func testAccCheckComputeInstanceDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
config := acctest.GoogleProviderConfig(t)
Expand Down Expand Up @@ -11368,3 +11389,47 @@ resource "google_compute_instance" "foobar" {
}
`, context)
}

func testAccComputeInstance_nicStackTypeUpdate_ipv6(context map[string]interface{}) string {
return acctest.Nprintf(`
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}

resource "google_compute_network" "inst-test-network" {
name = "tf-test-network-%{suffix}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "inst-test-subnetwork" {
name = "tf-test-compute-subnet-%{suffix}"
region = "%{env_region}"
ipv6_access_type = "EXTERNAL"
stack_type = "IPV6_ONLY"
network = google_compute_network.inst-test-network.id
}

resource "google_compute_instance" "foobar" {
name = "%{instance_name}"
machine_type = "e2-medium"
zone = "%{env_region}-a"

boot_disk {
initialize_params {
image = data.google_compute_image.my_image.self_link
}
}

network_interface {
network = google_compute_network.inst-test-network.id
subnetwork = google_compute_subnetwork.inst-test-subnetwork.id
stack_type = "IPV6_ONLY"

ipv6_access_config {
network_tier = "PREMIUM"
}
}
}
`, context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ Google Cloud KMS.`,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"IPV4_ONLY", "IPV4_IPV6", ""}, false),
ValidateFunc: validation.StringInSlice([]string{"IPV4_ONLY", "IPV4_IPV6","IPV6_ONLY", ""}, false),
Description: `The stack type for this network interface to identify whether the IPv6 feature is enabled or not. If not specified, IPV4_ONLY will be used.`,
},

Expand All @@ -538,6 +538,7 @@ Google Cloud KMS.`,
"ipv6_access_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
ForceNew: true,
Description: `An array of IPv6 access configurations for this interface. Currently, only one IPv6 access config, DIRECT_IPV6, is supported. If there is no ipv6AccessConfig specified, then this instance will have no external IPv6 Internet access.`,
Elem: &schema.Resource{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ is desired, you will need to modify your state file manually using

* `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}`.

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

* `ipv6_access_config` - (Optional) An array of IPv6 access configurations for this interface.
Currently, only one IPv6 access config, DIRECT_IPV6, is supported. If there is no ipv6AccessConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ The following arguments are supported:

* `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.

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

* `ipv6_access_config` - (Optional) An array of IPv6 access configurations for this interface.
Currently, only one IPv6 access config, DIRECT_IPV6, is supported. If there is no ipv6AccessConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ The following arguments are supported:

* `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.

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

* `ipv6_access_config` - (Optional) An array of IPv6 access configurations for this interface.
Currently, only one IPv6 access config, DIRECT_IPV6, is supported. If there is no ipv6AccessConfig
Expand Down

0 comments on commit c1ae9f3

Please sign in to comment.