|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | +// ---------------------------------------------------------------------------- |
| 4 | +// |
| 5 | +// *** AUTO GENERATED CODE *** Type: Handwritten *** |
| 6 | +// |
| 7 | +// ---------------------------------------------------------------------------- |
| 8 | +// |
| 9 | +// This code is generated by Magic Modules using the following: |
| 10 | +// |
| 11 | +// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/compute/data_source_google_compute_network_attachment_test.go |
| 12 | +// |
| 13 | +// DO NOT EDIT this file directly. Any changes made to this file will be |
| 14 | +// overwritten during the next generation cycle. |
| 15 | +// |
| 16 | +// ---------------------------------------------------------------------------- |
| 17 | +// Copyright (c) HashiCorp, Inc. |
| 18 | +// SPDX-License-Identifier: MPL-2.0 |
| 19 | +package compute_test |
| 20 | + |
| 21 | +import ( |
| 22 | + "fmt" |
| 23 | + "testing" |
| 24 | + |
| 25 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 26 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 27 | + "github.com/hashicorp/terraform-provider-google/google/envvar" |
| 28 | +) |
| 29 | + |
| 30 | +func TestAccDataSourceComputeNetworkAttachment_basic(t *testing.T) { |
| 31 | + t.Parallel() |
| 32 | + |
| 33 | + context := map[string]interface{}{ |
| 34 | + "random_suffix": acctest.RandString(t, 10), |
| 35 | + } |
| 36 | + |
| 37 | + acctest.VcrTest(t, resource.TestCase{ |
| 38 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 39 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 40 | + Steps: []resource.TestStep{ |
| 41 | + { |
| 42 | + Config: testAccComputeNetworkAttachment_basic(context), |
| 43 | + Check: resource.ComposeTestCheckFunc( |
| 44 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "name", fmt.Sprintf("tf-test-basic-network-attachment-%s", context["random_suffix"])), |
| 45 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "region", "us-central1"), |
| 46 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "description", "my basic network attachment"), |
| 47 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "connection_preference", "ACCEPT_AUTOMATIC"), |
| 48 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "subnetworks.#", "1"), |
| 49 | + ), |
| 50 | + }, |
| 51 | + }, |
| 52 | + }) |
| 53 | +} |
| 54 | + |
| 55 | +func TestAccDataSourceComputeNetworkAttachment_full(t *testing.T) { |
| 56 | + t.Parallel() |
| 57 | + |
| 58 | + context := map[string]interface{}{ |
| 59 | + "billing_account": envvar.GetTestBillingAccountFromEnv(t), |
| 60 | + "org_id": envvar.GetTestOrgFromEnv(t), |
| 61 | + "random_suffix": acctest.RandString(t, 10), |
| 62 | + } |
| 63 | + |
| 64 | + acctest.VcrTest(t, resource.TestCase{ |
| 65 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 66 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 67 | + Steps: []resource.TestStep{ |
| 68 | + { |
| 69 | + Config: testAccDataSourceComputeNetworkAttachment_full(context), |
| 70 | + Check: resource.ComposeTestCheckFunc( |
| 71 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "name", fmt.Sprintf("tf-test-basic-network-attachment-%s", context["random_suffix"])), |
| 72 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "region", "us-central1"), |
| 73 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "description", "basic network attachment description"), |
| 74 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "connection_preference", "ACCEPT_MANUAL"), |
| 75 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "subnetworks.#", "1"), |
| 76 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "subnetworks.0", fmt.Sprintf("tf-test-basic-subnetwork1-%s", context["random_suffix"])), |
| 77 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "producer_accept_lists.#", "2"), |
| 78 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "producer_accept_lists.0", fmt.Sprintf("tf-test-prj-accept1-%s", context["random_suffix"])), |
| 79 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "producer_accept_lists.1", fmt.Sprintf("tf-test-prj-accept2-%s", context["random_suffix"])), |
| 80 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "producer_reject_lists.#", "2"), |
| 81 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "producer_reject_lists.0", fmt.Sprintf("tf-test-prj-reject1-%s", context["random_suffix"])), |
| 82 | + resource.TestCheckResourceAttr("data.google_compute_network_attachment.default", "producer_reject_lists.1", fmt.Sprintf("tf-test-prj-reject2-%s", context["random_suffix"])), |
| 83 | + ), |
| 84 | + }, |
| 85 | + }, |
| 86 | + }) |
| 87 | +} |
| 88 | + |
| 89 | +func testAccComputeNetworkAttachment_basic(context map[string]interface{}) string { |
| 90 | + return acctest.Nprintf(` |
| 91 | +resource "google_compute_network" "default" { |
| 92 | + name = "tf-test-basic-network%{random_suffix}" |
| 93 | + auto_create_subnetworks = false |
| 94 | +} |
| 95 | +
|
| 96 | +resource "google_compute_subnetwork" "default" { |
| 97 | + name = "tf-test-basic-subnetwork%{random_suffix}" |
| 98 | + region = "us-central1" |
| 99 | +
|
| 100 | + network = google_compute_network.default.id |
| 101 | + ip_cidr_range = "10.0.0.0/16" |
| 102 | +} |
| 103 | +
|
| 104 | +resource "google_compute_network_attachment" "default" { |
| 105 | + name = "tf-test-basic-network-attachment-%{random_suffix}" |
| 106 | + region = "us-central1" |
| 107 | + description = "my basic network attachment" |
| 108 | +
|
| 109 | + subnetworks = [google_compute_subnetwork.default.id] |
| 110 | + connection_preference = "ACCEPT_AUTOMATIC" |
| 111 | +} |
| 112 | +
|
| 113 | +data "google_compute_network_attachment" "default" { |
| 114 | + name = google_compute_network_attachment.default.name |
| 115 | + region = google_compute_network_attachment.default.region |
| 116 | + project = google_compute_network_attachment.default.project |
| 117 | + depends_on = [ |
| 118 | + google_compute_network.default, |
| 119 | + google_compute_subnetwork.default, |
| 120 | + google_compute_network_attachment.default, |
| 121 | + ] |
| 122 | +} |
| 123 | +`, context) |
| 124 | +} |
| 125 | + |
| 126 | +func testAccDataSourceComputeNetworkAttachment_full(context map[string]interface{}) string { |
| 127 | + return acctest.Nprintf(` |
| 128 | +resource "google_compute_network_attachment" "default" { |
| 129 | + name = "tf-test-basic-network-attachment-%{random_suffix}" |
| 130 | + region = "us-central1" |
| 131 | + description = "basic network attachment description" |
| 132 | + connection_preference = "ACCEPT_MANUAL" |
| 133 | +
|
| 134 | + subnetworks = [ |
| 135 | + google_compute_subnetwork.net1.self_link |
| 136 | + ] |
| 137 | +
|
| 138 | + producer_accept_lists = [ |
| 139 | + google_project.accepted_producer_project1.project_id, |
| 140 | + google_project.accepted_producer_project2.project_id |
| 141 | + ] |
| 142 | +
|
| 143 | + producer_reject_lists = [ |
| 144 | + google_project.rejected_producer_project1.project_id, |
| 145 | + google_project.rejected_producer_project2.project_id |
| 146 | + ] |
| 147 | +} |
| 148 | +
|
| 149 | +resource "google_compute_network" "default" { |
| 150 | + name = "tf-test-basic-network-%{random_suffix}" |
| 151 | + auto_create_subnetworks = false |
| 152 | +} |
| 153 | +
|
| 154 | +resource "google_compute_subnetwork" "net1" { |
| 155 | + name = "tf-test-basic-subnetwork1-%{random_suffix}" |
| 156 | + region = "us-central1" |
| 157 | +
|
| 158 | + network = google_compute_network.default.id |
| 159 | + ip_cidr_range = "10.0.0.0/16" |
| 160 | +} |
| 161 | +
|
| 162 | +resource "google_compute_subnetwork" "net2" { |
| 163 | + name = "tf-test-basic-subnetwork2-%{random_suffix}" |
| 164 | + region = "us-central1" |
| 165 | +
|
| 166 | + network = google_compute_network.default.id |
| 167 | + ip_cidr_range = "10.1.0.0/16" |
| 168 | +} |
| 169 | +
|
| 170 | +resource "google_project" "rejected_producer_project1" { |
| 171 | + project_id = "tf-test-prj-reject1-%{random_suffix}" |
| 172 | + name = "tf-test-prj-reject1-%{random_suffix}" |
| 173 | + org_id = "%{org_id}" |
| 174 | + billing_account = "%{billing_account}" |
| 175 | + deletion_policy = "DELETE" |
| 176 | +} |
| 177 | +
|
| 178 | +resource "google_project" "rejected_producer_project2" { |
| 179 | + project_id = "tf-test-prj-reject2-%{random_suffix}" |
| 180 | + name = "tf-test-prj-reject2-%{random_suffix}" |
| 181 | + org_id = "%{org_id}" |
| 182 | + billing_account = "%{billing_account}" |
| 183 | + deletion_policy = "DELETE" |
| 184 | +} |
| 185 | +
|
| 186 | +resource "google_project" "accepted_producer_project1" { |
| 187 | + project_id = "tf-test-prj-accept1-%{random_suffix}" |
| 188 | + name = "tf-test-prj-accept1-%{random_suffix}" |
| 189 | + org_id = "%{org_id}" |
| 190 | + billing_account = "%{billing_account}" |
| 191 | + deletion_policy = "DELETE" |
| 192 | +} |
| 193 | +
|
| 194 | +resource "google_project" "accepted_producer_project2" { |
| 195 | + project_id = "tf-test-prj-accept2-%{random_suffix}" |
| 196 | + name = "tf-test-prj-accept2-%{random_suffix}" |
| 197 | + org_id = "%{org_id}" |
| 198 | + billing_account = "%{billing_account}" |
| 199 | + deletion_policy = "DELETE" |
| 200 | +} |
| 201 | +
|
| 202 | +data "google_compute_network_attachment" "default" { |
| 203 | + name = google_compute_network_attachment.default.name |
| 204 | + region = google_compute_network_attachment.default.region |
| 205 | + project = google_compute_network_attachment.default.project |
| 206 | + depends_on = [ |
| 207 | + google_compute_network_attachment.default, |
| 208 | + google_compute_network.default, |
| 209 | + google_compute_subnetwork.net1, |
| 210 | + google_compute_subnetwork.net2, |
| 211 | + google_project.accepted_producer_project1, |
| 212 | + google_project.accepted_producer_project2, |
| 213 | + google_project.rejected_producer_project1, |
| 214 | + google_project.rejected_producer_project2, |
| 215 | + ] |
| 216 | +} |
| 217 | +`, context) |
| 218 | +} |
0 commit comments