Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifact Registry Repository Data Source Added #6590

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package google

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceArtifactRegistryRepository() *schema.Resource {
// Generate datasource schema from resource
dsSchema := datasourceSchemaFromResourceSchema(resourceArtifactRegistryRepository().Schema)

// Set 'Required' schema elements
addRequiredFieldsToSchema(dsSchema, "repository_id", "location")

// Set 'Optional' schema elements
addOptionalFieldsToSchema(dsSchema, "project")

return &schema.Resource{
Read: dataSourceArtifactRegistryRepositoryRead,
Schema: dsSchema,
}
}

func dataSourceArtifactRegistryRepositoryRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

project, err := getProject(d, config)
if err != nil {
return err
}

location, err := getLocation(d, config)
if err != nil {
return err
}

repository_id := d.Get("repository_id").(string)
d.SetId(fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository_id))

err = resourceArtifactRegistryRepositoryRead(d, meta)
if err != nil {
return err
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package google

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceGoogleArtifactRegistryRepositoryConfig(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}
funcDataName := "data.google_artifact_registry_repository.my-repo"

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckArtifactRegistryRepositoryDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleArtifactRegistryRepositoryConfig(context),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState(funcDataName,
"google_artifact_registry_repository.my-repo"),
),
},
},
})
}

func testAccDataSourceGoogleArtifactRegistryRepositoryConfig(context map[string]interface{}) string {
return Nprintf(`
resource "google_artifact_registry_repository" "my-repo" {
location = "us-central1"
repository_id = "tf-test-my-repository%{random_suffix}"
description = "example docker repository%{random_suffix}"
format = "DOCKER"
}

data "google_artifact_registry_repository" "my-repo" {
location = "us-central1"
repository_id = google_artifact_registry_repository.my-repo.repository_id
}
`, context)
}
1 change: 1 addition & 0 deletions mmv1/third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func Provider() *schema.Provider {
"google_access_approval_organization_service_account": dataSourceAccessApprovalOrganizationServiceAccount(),
"google_access_approval_project_service_account": dataSourceAccessApprovalProjectServiceAccount(),
"google_active_folder": dataSourceGoogleActiveFolder(),
"google_artifact_registry_repository": dataSourceArtifactRegistryRepository(),
"google_app_engine_default_service_account": dataSourceGoogleAppEngineDefaultServiceAccount(),
"google_billing_account": dataSourceGoogleBillingAccount(),
"google_bigquery_default_service_account": dataSourceGoogleBigqueryDefaultServiceAccount(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
subcategory: "Artifact Registry Repository"
page_title: "Google: google_artifact_registry_repository"
description: |-
Get information about a Google Artifact Registry Repository.
---

# google\_artifact\_registry\_repository

Get information about a Google Artifact Registry Repository. For more information see
the [official documentation](https://cloud.google.com/artifact-registry/docs/)
and [API](https://cloud.google.com/artifact-registry/docs/apis).

## Example Usage

```hcl
data "google_artifact_registry_repository" "my-repo" {
location = "us-central1"
repository_id = "my-repository"
}
```

## Argument Reference

The following arguments are supported:

* `repository_id` - (Required) The last part of the repository name.

* `location` - (Required) The location of the artifact registry repository. eg us-central1

- - -

* `project` - (Optional) The project in which the resource belongs. If it
is not provided, the provider project is used.

## Attributes Reference

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.