-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
8b4ac50
commit a0b3309
Showing
5 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-datasource | ||
`google_artifact_registry_repository` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |