Skip to content

Commit a0b3309

Browse files
Artifact Registry Repository Data Source Added (#6590) (#12637)
* Artifact Registry Data Source Added * Artifact Registry Resource Location Changes Updated Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 8b4ac50 commit a0b3309

5 files changed

+136
-0
lines changed

.changelog/6590.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-datasource
2+
`google_artifact_registry_repository`
3+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
)
8+
9+
func dataSourceArtifactRegistryRepository() *schema.Resource {
10+
// Generate datasource schema from resource
11+
dsSchema := datasourceSchemaFromResourceSchema(resourceArtifactRegistryRepository().Schema)
12+
13+
// Set 'Required' schema elements
14+
addRequiredFieldsToSchema(dsSchema, "repository_id", "location")
15+
16+
// Set 'Optional' schema elements
17+
addOptionalFieldsToSchema(dsSchema, "project")
18+
19+
return &schema.Resource{
20+
Read: dataSourceArtifactRegistryRepositoryRead,
21+
Schema: dsSchema,
22+
}
23+
}
24+
25+
func dataSourceArtifactRegistryRepositoryRead(d *schema.ResourceData, meta interface{}) error {
26+
config := meta.(*Config)
27+
28+
project, err := getProject(d, config)
29+
if err != nil {
30+
return err
31+
}
32+
33+
location, err := getLocation(d, config)
34+
if err != nil {
35+
return err
36+
}
37+
38+
repository_id := d.Get("repository_id").(string)
39+
d.SetId(fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository_id))
40+
41+
err = resourceArtifactRegistryRepositoryRead(d, meta)
42+
if err != nil {
43+
return err
44+
}
45+
46+
return nil
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package google
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccDataSourceGoogleArtifactRegistryRepositoryConfig(t *testing.T) {
10+
t.Parallel()
11+
12+
context := map[string]interface{}{
13+
"random_suffix": randString(t, 10),
14+
}
15+
funcDataName := "data.google_artifact_registry_repository.my-repo"
16+
17+
vcrTest(t, resource.TestCase{
18+
PreCheck: func() { testAccPreCheck(t) },
19+
Providers: testAccProviders,
20+
CheckDestroy: testAccCheckArtifactRegistryRepositoryDestroyProducer(t),
21+
Steps: []resource.TestStep{
22+
{
23+
Config: testAccDataSourceGoogleArtifactRegistryRepositoryConfig(context),
24+
Check: resource.ComposeTestCheckFunc(
25+
checkDataSourceStateMatchesResourceState(funcDataName,
26+
"google_artifact_registry_repository.my-repo"),
27+
),
28+
},
29+
},
30+
})
31+
}
32+
33+
func testAccDataSourceGoogleArtifactRegistryRepositoryConfig(context map[string]interface{}) string {
34+
return Nprintf(`
35+
resource "google_artifact_registry_repository" "my-repo" {
36+
location = "us-central1"
37+
repository_id = "tf-test-my-repository%{random_suffix}"
38+
description = "example docker repository%{random_suffix}"
39+
format = "DOCKER"
40+
}
41+
42+
data "google_artifact_registry_repository" "my-repo" {
43+
location = "us-central1"
44+
repository_id = google_artifact_registry_repository.my-repo.repository_id
45+
}
46+
`, context)
47+
}

google/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ func Provider() *schema.Provider {
773773
"google_access_approval_organization_service_account": dataSourceAccessApprovalOrganizationServiceAccount(),
774774
"google_access_approval_project_service_account": dataSourceAccessApprovalProjectServiceAccount(),
775775
"google_active_folder": dataSourceGoogleActiveFolder(),
776+
"google_artifact_registry_repository": dataSourceArtifactRegistryRepository(),
776777
"google_app_engine_default_service_account": dataSourceGoogleAppEngineDefaultServiceAccount(),
777778
"google_billing_account": dataSourceGoogleBillingAccount(),
778779
"google_bigquery_default_service_account": dataSourceGoogleBigqueryDefaultServiceAccount(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
subcategory: "Artifact Registry Repository"
3+
page_title: "Google: google_artifact_registry_repository"
4+
description: |-
5+
Get information about a Google Artifact Registry Repository.
6+
---
7+
8+
# google\_artifact\_registry\_repository
9+
10+
Get information about a Google Artifact Registry Repository. For more information see
11+
the [official documentation](https://cloud.google.com/artifact-registry/docs/)
12+
and [API](https://cloud.google.com/artifact-registry/docs/apis).
13+
14+
## Example Usage
15+
16+
```hcl
17+
data "google_artifact_registry_repository" "my-repo" {
18+
location = "us-central1"
19+
repository_id = "my-repository"
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `repository_id` - (Required) The last part of the repository name.
28+
29+
* `location` - (Required) The location of the artifact registry repository. eg us-central1
30+
31+
- - -
32+
33+
* `project` - (Optional) The project in which the resource belongs. If it
34+
is not provided, the provider project is used.
35+
36+
## Attributes Reference
37+
38+
See [google_artifact_registry_repository](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/artifact_registry_repository#argument-reference) resource for details of the available attributes.

0 commit comments

Comments
 (0)