Skip to content

Commit cf2e5c2

Browse files
Add network_attachment on gce instance data source (#9856) (#6891)
* addition of network attachament field on GCE instance data source * remove of unnecessary part of code that add network_attachemtn [upstream:c011b040df99388289bb7819db455e5559678acf] Signed-off-by: Modular Magician <[email protected]>
1 parent e609934 commit cf2e5c2

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

.changelog/9856.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
docs: added `network_attachment` to `google_compute_instance` data source (beta)
3+
```

google-beta/services/compute/data_source_google_compute_instance_test.go

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ resource "google_compute_instance" "foo" {
108108
}
109109
110110
network_interface {
111-
network = "default"
112-
111+
network = "default"
113112
access_config {
114113
// Ephemeral IP
115114
}
@@ -139,3 +138,96 @@ data "google_compute_instance" "baz" {
139138
}
140139
`, instanceName)
141140
}
141+
func TestAccDataSourceComputeInstance_networkAttachmentUsageExample(t *testing.T) {
142+
t.Parallel()
143+
144+
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
145+
146+
acctest.VcrTest(t, resource.TestCase{
147+
PreCheck: func() { acctest.AccTestPreCheck(t) },
148+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
149+
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
150+
Steps: []resource.TestStep{
151+
{
152+
Config: testAccDataSourceComputeInstance_networkAttachmentUsageConfig(instanceName),
153+
Check: resource.TestCheckResourceAttrSet("data.google_compute_instance.bar", "network_interface.1.network_attachment"),
154+
},
155+
},
156+
})
157+
}
158+
159+
func testAccDataSourceComputeInstance_networkAttachmentUsageConfig(instanceName string) string {
160+
return fmt.Sprintf(`
161+
resource "google_compute_instance" "foo" {
162+
provider = google-beta
163+
name = "%s"
164+
machine_type = "n1-standard-1" // can't be e2 because of local-ssd
165+
zone = "us-central1-a"
166+
can_ip_forward = false
167+
tags = ["foo", "bar"]
168+
169+
boot_disk {
170+
initialize_params {
171+
image = "debian-8-jessie-v20160803"
172+
}
173+
}
174+
175+
scratch_disk {
176+
interface = "SCSI"
177+
}
178+
179+
network_interface {
180+
network = "default"
181+
182+
access_config {
183+
// Ephemeral IP
184+
}
185+
}
186+
187+
network_interface {
188+
network_attachment = google_compute_network_attachment.net_attar_default.self_link
189+
}
190+
191+
192+
193+
labels = {
194+
my_key = "my_value"
195+
my_other_key = "my_other_value"
196+
}
197+
198+
enable_display = true
199+
}
200+
201+
data "google_compute_instance" "bar" {
202+
provider = google-beta
203+
name = google_compute_instance.foo.name
204+
zone = "us-central1-a"
205+
}
206+
207+
data "google_compute_instance" "baz" {
208+
provider = google-beta
209+
self_link = google_compute_instance.foo.self_link
210+
}
211+
resource "google_compute_network" "net_att_default" {
212+
provider = google-beta
213+
name = "basic-network-att"
214+
auto_create_subnetworks = false
215+
}
216+
217+
resource "google_compute_subnetwork" "subnet_att_default" {
218+
provider = google-beta
219+
name = "basic-subnetwork-att"
220+
region = "us-central1"
221+
network = google_compute_network.net_att_default.id
222+
ip_cidr_range = "10.0.0.0/16"
223+
}
224+
225+
resource "google_compute_network_attachment" "net_attar_default" {
226+
provider = google-beta
227+
name = "basic-attachment"
228+
region = "us-central1"
229+
subnetworks = [google_compute_subnetwork.subnet_att_default.id]
230+
connection_preference = "ACCEPT_AUTOMATIC"
231+
}
232+
`, instanceName)
233+
}

website/docs/d/compute_instance.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ The following arguments are supported:
159159

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

162+
* `network_attachment` - [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) The URL of the network attachment to this interface.
163+
162164
<a name="nested_access_config"></a>The `access_config` block supports:
163165

164166
* `nat_ip` - The IP address that is be 1:1 mapped to the instance's

0 commit comments

Comments
 (0)