|
| 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/artifactregistry/data_source_artifact_registry_repositories_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 | +package artifactregistry_test |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 23 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 24 | + "github.com/hashicorp/terraform-provider-google/google/envvar" |
| 25 | +) |
| 26 | + |
| 27 | +func TestAccDataSourceArtifactRegistryRepositories_basic(t *testing.T) { |
| 28 | + t.Parallel() |
| 29 | + |
| 30 | + context := map[string]interface{}{ |
| 31 | + "location": envvar.GetTestRegionFromEnv(), |
| 32 | + "random_suffix": acctest.RandString(t, 8), |
| 33 | + } |
| 34 | + |
| 35 | + acctest.VcrTest(t, resource.TestCase{ |
| 36 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 37 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 38 | + Steps: []resource.TestStep{ |
| 39 | + { |
| 40 | + Config: testAccDataSourceArtifactRegistryRepositoriesConfig(context), |
| 41 | + Check: resource.ComposeTestCheckFunc( |
| 42 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.all", "project"), |
| 43 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.all", "repositories.0.id"), |
| 44 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.all", "repositories.1.id"), |
| 45 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.all", "repositories.2.id"), |
| 46 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.all", "repositories.0.repository_id"), |
| 47 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.all", "repositories.0.format"), |
| 48 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.all", "repositories.0.create_time"), |
| 49 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.all", "repositories.0.update_time"), |
| 50 | + ), |
| 51 | + }, |
| 52 | + { |
| 53 | + Config: testAccDataSourceArtifactRegistryRepositoriesConfigWithFilter(context), |
| 54 | + Check: resource.ComposeTestCheckFunc( |
| 55 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.filtered", "repositories.0.id"), |
| 56 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.filtered", "repositories.0.repository_id"), |
| 57 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.filtered", "repositories.0.format"), |
| 58 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.filtered", "repositories.0.create_time"), |
| 59 | + resource.TestCheckResourceAttrSet("data.google_artifact_registry_repositories.filtered", "repositories.0.update_time"), |
| 60 | + ), |
| 61 | + }, |
| 62 | + }, |
| 63 | + }) |
| 64 | +} |
| 65 | + |
| 66 | +func testAccDataSourceArtifactRegistryRepositoriesConfig(context map[string]interface{}) string { |
| 67 | + return acctest.Nprintf(` |
| 68 | +resource "google_artifact_registry_repository" "repo1" { |
| 69 | + location = "%{location}" |
| 70 | + repository_id = "tf-test-repo1%{random_suffix}" |
| 71 | + format = "DOCKER" |
| 72 | + description = "repo1 desc" |
| 73 | +} |
| 74 | +
|
| 75 | +resource "google_artifact_registry_repository" "repo2" { |
| 76 | + location = "%{location}" |
| 77 | + repository_id = "tf-test-repo2%{random_suffix}" |
| 78 | + format = "DOCKER" |
| 79 | + description = "repo2 desc" |
| 80 | +} |
| 81 | +
|
| 82 | +resource "google_artifact_registry_repository" "repo3" { |
| 83 | + location = "%{location}" |
| 84 | + repository_id = "tf-test-repo3%{random_suffix}" |
| 85 | + format = "DOCKER" |
| 86 | + description = "repo3 desc" |
| 87 | +} |
| 88 | +
|
| 89 | +data "google_artifact_registry_repositories" "all" { |
| 90 | + location = "%{location}" |
| 91 | +
|
| 92 | + depends_on = [ |
| 93 | + google_artifact_registry_repository.repo1, |
| 94 | + google_artifact_registry_repository.repo2, |
| 95 | + google_artifact_registry_repository.repo3, |
| 96 | + ] |
| 97 | +} |
| 98 | +`, context) |
| 99 | +} |
| 100 | + |
| 101 | +func testAccDataSourceArtifactRegistryRepositoriesConfigWithFilter(context map[string]interface{}) string { |
| 102 | + return acctest.Nprintf(` |
| 103 | +resource "google_artifact_registry_repository" "repo1" { |
| 104 | + location = "%{location}" |
| 105 | + repository_id = "tf-test-repo1%{random_suffix}" |
| 106 | + format = "DOCKER" |
| 107 | + description = "repo1 desc" |
| 108 | +} |
| 109 | +
|
| 110 | +resource "google_artifact_registry_repository" "repo2" { |
| 111 | + location = "%{location}" |
| 112 | + repository_id = "tf-test-repo2%{random_suffix}" |
| 113 | + format = "DOCKER" |
| 114 | + description = "repo2 desc" |
| 115 | +} |
| 116 | +
|
| 117 | +resource "google_artifact_registry_repository" "repo3" { |
| 118 | + location = "%{location}" |
| 119 | + repository_id = "tf-test-repo3%{random_suffix}" |
| 120 | + format = "DOCKER" |
| 121 | + description = "repo3 desc" |
| 122 | +} |
| 123 | +
|
| 124 | +resource "google_artifact_registry_repository" "repo4" { |
| 125 | + location = "%{location}" |
| 126 | + repository_id = "tf-acc-repo4%{random_suffix}" |
| 127 | + format = "DOCKER" |
| 128 | + description = "acc desc" |
| 129 | +} |
| 130 | +
|
| 131 | +data "google_artifact_registry_repositories" "filtered" { |
| 132 | + location = "%{location}" |
| 133 | + name_filter = "*acc*" |
| 134 | +
|
| 135 | + depends_on = [ |
| 136 | + google_artifact_registry_repository.repo1, |
| 137 | + google_artifact_registry_repository.repo2, |
| 138 | + google_artifact_registry_repository.repo3, |
| 139 | + google_artifact_registry_repository.repo4, |
| 140 | + ] |
| 141 | +} |
| 142 | +`, context) |
| 143 | +} |
0 commit comments