Skip to content

Commit 02fc80c

Browse files
Promoted Instance NetworkAttachment field to V1; (#13067)
1 parent 05fd518 commit 02fc80c

6 files changed

+18
-40
lines changed

mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.tmpl

-16
Original file line numberDiff line numberDiff line change
@@ -520,15 +520,13 @@ func flattenNetworkInterfaces(d *schema.ResourceData, config *transport_tpg.Conf
520520
internalIP = iface.NetworkIP
521521
}
522522

523-
{{ if ne $.TargetVersionName `ga` -}}
524523
if iface.NetworkAttachment != "" {
525524
networkAttachment, err := tpgresource.GetRelativePath(iface.NetworkAttachment)
526525
if err != nil {
527526
return nil, "", "", "", err
528527
}
529528
flattened[i]["network_attachment"] = networkAttachment
530529
}
531-
{{- end }}
532530

533531
{{ if ne $.TargetVersionName `ga` -}}
534532
// the security_policy for a network_interface is found in one of its accessConfigs.
@@ -595,8 +593,6 @@ func expandNetworkInterfaces(d tpgresource.TerraformResourceData, config *transp
595593
for i, raw := range configs {
596594
data := raw.(map[string]interface{})
597595

598-
599-
{{ if ne $.TargetVersionName `ga` -}}
600596
var networkAttachment = ""
601597
network := data["network"].(string)
602598
subnetwork := data["subnetwork"].(string)
@@ -608,16 +604,6 @@ func expandNetworkInterfaces(d tpgresource.TerraformResourceData, config *transp
608604
return nil, fmt.Errorf("exactly one of network, subnetwork, or network_attachment must be provided")
609605
}
610606

611-
{{- else }}
612-
613-
network := data["network"].(string)
614-
subnetwork := data["subnetwork"].(string)
615-
if network == "" && subnetwork == "" {
616-
return nil, fmt.Errorf("exactly one of network or subnetwork must be provided")
617-
}
618-
619-
{{ end }}
620-
621607
nf, err := tpgresource.ParseNetworkFieldValue(network, d, config)
622608
if err != nil {
623609
return nil, fmt.Errorf("cannot determine self_link for network %q: %s", network, err)
@@ -632,9 +618,7 @@ func expandNetworkInterfaces(d tpgresource.TerraformResourceData, config *transp
632618
ifaces[i] = &compute.NetworkInterface{
633619
NetworkIP: data["network_ip"].(string),
634620
Network: nf.RelativeLink(),
635-
{{- if ne $.TargetVersionName "ga" }}
636621
NetworkAttachment: networkAttachment,
637-
{{- end }}
638622
Subnetwork: sf.RelativeLink(),
639623
AccessConfigs: expandAccessConfigs(data["access_config"].([]interface{})),
640624
AliasIpRanges: expandAliasIpRanges(data["alias_ip_range"].([]interface{})),

mmv1/third_party/terraform/services/compute/data_source_google_compute_instance_test.go.tmpl

+3-10
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ data "google_compute_instance" "baz" {
136136
}
137137
`, instanceName)
138138
}
139-
{{- if ne $.TargetVersionName "ga" }}
139+
140140
func TestAccDataSourceComputeInstance_networkAttachmentUsageExample(t *testing.T) {
141141
t.Parallel()
142142

143143
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
144144

145145
acctest.VcrTest(t, resource.TestCase{
146146
PreCheck: func() { acctest.AccTestPreCheck(t) },
147-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
147+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
148148
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
149149
Steps: []resource.TestStep{
150150
{
@@ -158,7 +158,6 @@ func TestAccDataSourceComputeInstance_networkAttachmentUsageExample(t *testing.T
158158
func testAccDataSourceComputeInstance_networkAttachmentUsageConfig(instanceName string) string {
159159
return fmt.Sprintf(`
160160
resource "google_compute_instance" "foo" {
161-
provider = google-beta
162161
name = "%s"
163162
machine_type = "n1-standard-1" // can't be e2 because of local-ssd
164163
zone = "us-central1-a"
@@ -198,36 +197,30 @@ resource "google_compute_instance" "foo" {
198197
}
199198

200199
data "google_compute_instance" "bar" {
201-
provider = google-beta
202200
name = google_compute_instance.foo.name
203201
zone = "us-central1-a"
204202
}
205203

206204
data "google_compute_instance" "baz" {
207-
provider = google-beta
208205
self_link = google_compute_instance.foo.self_link
209206
}
210207
resource "google_compute_network" "net_att_default" {
211-
provider = google-beta
212208
name = "%s"
213209
auto_create_subnetworks = false
214210
}
215211

216212
resource "google_compute_subnetwork" "subnet_att_default" {
217-
provider = google-beta
218213
name = "%s"
219214
region = "us-central1"
220215
network = google_compute_network.net_att_default.id
221216
ip_cidr_range = "10.0.0.0/16"
222217
}
223218

224219
resource "google_compute_network_attachment" "net_attar_default" {
225-
provider = google-beta
226220
name = "%s"
227221
region = "us-central1"
228222
subnetworks = [google_compute_subnetwork.subnet_att_default.id]
229223
connection_preference = "ACCEPT_AUTOMATIC"
230224
}
231225
`, instanceName, instanceName, instanceName, instanceName)
232-
}
233-
{{- end }}
226+
}

mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl

-2
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ func ResourceComputeInstance() *schema.Resource {
434434
Description: `The name or self_link of the subnetwork attached to this interface.`,
435435
},
436436

437-
{{ if ne $.TargetVersionName `ga` -}}
438437
"network_attachment": {
439438
Type: schema.TypeString,
440439
Optional: true,
@@ -443,7 +442,6 @@ func ResourceComputeInstance() *schema.Resource {
443442
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
444443
Description: `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}.`,
445444
},
446-
{{- end }}
447445

448446
"subnetwork_project": {
449447
Type: schema.TypeString,

mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl

+13-10
Original file line numberDiff line numberDiff line change
@@ -4413,20 +4413,27 @@ func testAccCheckComputeInstanceUpdateMachineType(t *testing.T, n string) resour
44134413
}
44144414
}
44154415

4416-
{{ if ne $.TargetVersionName `ga` -}}
44174416
func TestAccComputeInstance_NetworkAttachment(t *testing.T) {
44184417
t.Parallel()
44194418
suffix := fmt.Sprintf("%s", acctest.RandString(t, 10))
4419+
envRegion := envvar.GetTestRegionFromEnv()
44204420
var instance compute.Instance
44214421

4422+
{{ if eq $.TargetVersionName `ga` }}
4423+
providerVersion := "v1"
4424+
{{- else }}
4425+
providerVersion := "beta"
4426+
{{- end }}
4427+
44224428
testNetworkAttachmentName := fmt.Sprintf("tf-test-network-attachment-%s", suffix)
44234429

44244430
// Need to have the full network attachment name in the format project/{project_id}/regions/{region_id}/networkAttachments/{testNetworkAttachmentName}
4425-
fullFormNetworkAttachmentName := fmt.Sprintf("projects/%s/regions/%s/networkAttachments/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), testNetworkAttachmentName)
4431+
fullFormNetworkAttachmentName := fmt.Sprintf("projects/%s/regions/%s/networkAttachments/%s", envvar.GetTestProjectFromEnv(), envRegion, testNetworkAttachmentName)
44264432

44274433
context := map[string]interface{}{
44284434
"suffix": (acctest.RandString(t, 10)),
44294435
"network_attachment_name": testNetworkAttachmentName,
4436+
"region": envRegion,
44304437
}
44314438

44324439
acctest.VcrTest(t, resource.TestCase{
@@ -4439,7 +4446,7 @@ func TestAccComputeInstance_NetworkAttachment(t *testing.T) {
44394446
Check: resource.ComposeTestCheckFunc(
44404447
testAccCheckComputeInstanceExists(
44414448
t, "google_compute_instance.foobar", &instance),
4442-
testAccCheckComputeInstanceHasNetworkAttachment(&instance, fmt.Sprintf("https://www.googleapis.com/compute/beta/%s", fullFormNetworkAttachmentName)),
4449+
testAccCheckComputeInstanceHasNetworkAttachment(&instance, fmt.Sprintf("https://www.googleapis.com/compute/%s/%s", providerVersion, fullFormNetworkAttachmentName)),
44434450
),
44444451
},
44454452
},
@@ -4475,7 +4482,6 @@ func TestAccComputeInstance_NetworkAttachmentUpdate(t *testing.T) {
44754482
},
44764483
})
44774484
}
4478-
{{- end }}
44794485

44804486
func TestAccComputeInstance_NicStackTypeUpdate(t *testing.T) {
44814487
t.Parallel()
@@ -5203,7 +5209,6 @@ func testAccCheckComputeInstanceHasMinCpuPlatform(instance *compute.Instance, mi
52035209
}
52045210
}
52055211

5206-
{{ if ne $.TargetVersionName `ga` -}}
52075212
func testAccCheckComputeInstanceHasNetworkAttachment(instance *compute.Instance, networkAttachmentName string) resource.TestCheckFunc {
52085213
return func(s *terraform.State) error {
52095214
for _, networkInterface := range instance.NetworkInterfaces {
@@ -5214,7 +5219,6 @@ func testAccCheckComputeInstanceHasNetworkAttachment(instance *compute.Instance,
52145219
return fmt.Errorf("Network Attachment %s, was not found in the instance template", networkAttachmentName)
52155220
}
52165221
}
5217-
{{- end }}
52185222

52195223
func testAccCheckComputeInstanceHasMachineType(instance *compute.Instance, machineType string) resource.TestCheckFunc {
52205224
return func(s *terraform.State) error {
@@ -11228,7 +11232,6 @@ resource "google_compute_instance" "foobar" {
1122811232

1122911233
{{ end }}
1123011234

11231-
{{ if ne $.TargetVersionName `ga` -}}
1123211235
func testAccComputeInstance_networkAttachment(context map[string]interface{}) string {
1123311236
return acctest.Nprintf(`
1123411237
data "google_compute_image" "my_image" {
@@ -11262,6 +11265,7 @@ resource "google_compute_network_attachment" "test_network_attachment" {
1126211265
resource "google_compute_instance" "foobar" {
1126311266
name = "tf-test-instance-%{suffix}"
1126411267
machine_type = "e2-medium"
11268+
zone = "%{region}-a"
1126511269

1126611270
boot_disk {
1126711271
initialize_params {
@@ -11273,7 +11277,7 @@ resource "google_compute_instance" "foobar" {
1127311277
network = "default"
1127411278
}
1127511279

11276-
network_interface{
11280+
network_interface {
1127711281
network_attachment = google_compute_network_attachment.test_network_attachment.self_link
1127811282
}
1127911283

@@ -11353,7 +11357,7 @@ resource "google_compute_instance" "foobar" {
1135311357
network = "default"
1135411358
}
1135511359

11356-
network_interface{
11360+
network_interface {
1135711361
network_attachment = %s
1135811362
}
1135911363

@@ -11363,7 +11367,6 @@ resource "google_compute_instance" "foobar" {
1136311367
}
1136411368
`, suffix, suffix, suffix, region, suffix, region, suffix, region, suffix, region, suffix, region, networkAttachment)
1136511369
}
11366-
{{- end }}
1136711370

1136811371
func testAccComputeInstance_nicStackTypeUpdate(suffix, region, stack_type, instance string) string {
1136911372
return fmt.Sprintf(`

mmv1/third_party/terraform/website/docs/d/compute_instance.html.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ The following arguments are supported:
165165

166166
* `alias_ip_range` - An array of alias IP ranges for this network interface. Structure [documented below](#nested_alias_ip_range).
167167

168-
* `network_attachment` - [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) The URL of the network attachment to this interface.
168+
* `network_attachment` - The URL of the network attachment to this interface.
169169

170170
<a name="nested_access_config"></a>The `access_config` block supports:
171171

mmv1/third_party/terraform/website/docs/r/compute_instance.html.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ is desired, you will need to modify your state file manually using
399399

400400
* `nic_type` - (Optional) The type of vNIC to be used on this interface. Possible values: GVNIC, VIRTIO_NET, IDPF, MRDMA, IRDMA.
401401

402-
* `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}`.
402+
* `network_attachment` - (Optional) 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}`.
403403

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

0 commit comments

Comments
 (0)