Skip to content

Commit

Permalink
artifactregistry: updated repository docs and import format (#12346)
Browse files Browse the repository at this point in the history
[upstream:d2c973ed3542bc879b0db34ef649e0307e29b05f]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician committed Dec 9, 2024
1 parent fa20579 commit c8da214
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .changelog/12346.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,16 @@ Please refer to the field 'effective_labels' for all of the labels present on th
Elem: &schema.Schema{Type: schema.TypeString},
},
"location": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: `The name of the location this repository is located in.`,
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: `The name of the repository's location. In addition to specific regions,
special values for multi-region locations are 'asia', 'europe', and 'us'.
See [here](https://cloud.google.com/artifact-registry/docs/repositories/repo-locations),
or use the
[google_artifact_registry_locations](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/artifact_registry_locations)
data source for possible values.`,
},
"maven_config": {
Type: schema.TypeList,
Expand Down Expand Up @@ -1144,7 +1149,6 @@ func resourceArtifactRegistryRepositoryImport(d *schema.ResourceData, meta inter
"^projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/repositories/(?P<repository_id>[^/]+)$",
"^(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<repository_id>[^/]+)$",
"^(?P<location>[^/]+)/(?P<repository_id>[^/]+)$",
"^(?P<repository_id>[^/]+)$",
}, d, config); err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,42 @@ resource "google_artifact_registry_repository" "my-repo" {
`, context)
}

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

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckArtifactRegistryRepositoryDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccArtifactRegistryRepository_artifactRegistryRepositoryMultiRegionExample(context),
},
{
ResourceName: "google_artifact_registry_repository.my-repo",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "location", "repository_id", "terraform_labels"},
},
},
})
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ data "google_artifact_registry_repository_iam_policy" "policy" {
The following arguments are supported:

* `repository` - (Required) Used to find the parent resource to bind the IAM policy to
* `location` - (Optional) The name of the location this repository is located in.
Used to find the parent resource to bind the IAM policy to. If not specified,
* `location` - (Optional) The name of the repository's location. In addition to specific regions,
special values for multi-region locations are `asia`, `europe`, and `us`.
See [here](https://cloud.google.com/artifact-registry/docs/repositories/repo-locations),
or use the
[google_artifact_registry_locations](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/artifact_registry_locations)
data source for possible values. Used to find the parent resource to bind the IAM policy to. If not specified,
the value will be parsed from the identifier of the parent resource. If no location is provided in the parent identifier and no
location is specified, it is taken from the provider configuration.

Expand Down
41 changes: 30 additions & 11 deletions website/docs/r/artifact_registry_repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ resource "google_artifact_registry_repository" "my-repo" {
format = "DOCKER"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=artifact_registry_repository_multi_region&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Artifact Registry Repository Multi Region


```hcl
resource "google_artifact_registry_repository" "my-repo" {
repository_id = "my-repository"
description = "example docker repository"
location = "us"
format = "DOCKER"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=artifact_registry_repository_docker&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand Down Expand Up @@ -630,26 +646,22 @@ resource "google_artifact_registry_repository" "my-repo" {
The following arguments are supported:


* `repository_id` -
(Required)
The last part of the repository name, for example:
"repo1"

* `format` -
(Required)
The format of packages that are stored in the repository. Supported formats
can be found [here](https://cloud.google.com/artifact-registry/docs/supported-formats).
You can only create alpha formats if you are a member of the
[alpha user group](https://cloud.google.com/artifact-registry/docs/supported-formats#alpha-access).

* `repository_id` -
(Required)
The last part of the repository name, for example:
"repo1"


- - -


* `location` -
(Optional)
The name of the location this repository is located in.

* `description` -
(Optional)
The user-provided description of the repository.
Expand Down Expand Up @@ -713,6 +725,15 @@ The following arguments are supported:
If true, the cleanup pipeline is prevented from deleting versions in this
repository.

* `location` -
(Optional)
The name of the repository's location. In addition to specific regions,
special values for multi-region locations are `asia`, `europe`, and `us`.
See [here](https://cloud.google.com/artifact-registry/docs/repositories/repo-locations),
or use the
[google_artifact_registry_locations](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/artifact_registry_locations)
data source for possible values.

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

Expand Down Expand Up @@ -1059,7 +1080,6 @@ Repository can be imported using any of these accepted formats:
* `projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}`
* `{{project}}/{{location}}/{{repository_id}}`
* `{{location}}/{{repository_id}}`
* `{{repository_id}}`


In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Repository using one of the formats above. For example:
Expand All @@ -1077,7 +1097,6 @@ When using the [`terraform import` command](https://developer.hashicorp.com/terr
$ terraform import google_artifact_registry_repository.default projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}
$ terraform import google_artifact_registry_repository.default {{project}}/{{location}}/{{repository_id}}
$ terraform import google_artifact_registry_repository.default {{location}}/{{repository_id}}
$ terraform import google_artifact_registry_repository.default {{repository_id}}
```

## User Project Overrides
Expand Down
8 changes: 6 additions & 2 deletions website/docs/r/artifact_registry_repository_iam.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ resource "google_artifact_registry_repository_iam_member" "member" {
The following arguments are supported:

* `repository` - (Required) Used to find the parent resource to bind the IAM policy to
* `location` - (Optional) The name of the location this repository is located in.
Used to find the parent resource to bind the IAM policy to. If not specified,
* `location` - (Optional) The name of the repository's location. In addition to specific regions,
special values for multi-region locations are `asia`, `europe`, and `us`.
See [here](https://cloud.google.com/artifact-registry/docs/repositories/repo-locations),
or use the
[google_artifact_registry_locations](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/artifact_registry_locations)
data source for possible values. Used to find the parent resource to bind the IAM policy to. If not specified,
the value will be parsed from the identifier of the parent resource. If no location is provided in the parent identifier and no
location is specified, it is taken from the provider configuration.

Expand Down

0 comments on commit c8da214

Please sign in to comment.