Skip to content

Commit

Permalink
Artifact Registry Repository Data Source Added (#6590) (#12637)
Browse files Browse the repository at this point in the history
* Artifact Registry Data Source Added

* Artifact Registry Resource Location Changes Updated

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 23, 2022
1 parent 8b4ac50 commit a0b3309
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/6590.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
`google_artifact_registry_repository`
```
47 changes: 47 additions & 0 deletions google/data_source_artifact_registry_repository.go
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
}
47 changes: 47 additions & 0 deletions google/data_source_artifact_registry_repository_test.go
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 google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,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
38 changes: 38 additions & 0 deletions website/docs/d/artifact_registry_repository.html.markdown
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.

0 comments on commit a0b3309

Please sign in to comment.