Skip to content

Commit 410cabb

Browse files
artifactregistry: fix comments, more examples for common remote repositories (#12312) (#8713)
[upstream:e7cf93b18ad0eca820b889cd4dae4b88cb5a9ddc] Signed-off-by: Modular Magician <[email protected]>
1 parent ec6d242 commit 410cabb

File tree

4 files changed

+226
-13
lines changed

4 files changed

+226
-13
lines changed

Diff for: .changelog/12312.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

Diff for: google-beta/services/artifactregistry/resource_artifact_registry_repository.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,13 @@ snapshot versions.`,
350350
Elem: &schema.Resource{
351351
Schema: map[string]*schema.Schema{
352352
"uri": {
353-
Type: schema.TypeString,
354-
Required: true,
355-
ForceNew: true,
356-
Description: `Specific uri to the Artifact Registory repository, e.g. 'projects/UPSTREAM_PROJECT_ID/locations/REGION/repositories/UPSTREAM_REPOSITORY'`,
353+
Type: schema.TypeString,
354+
Required: true,
355+
ForceNew: true,
356+
Description: `One of:
357+
a. Artifact Registry Repository resource, e.g. 'projects/UPSTREAM_PROJECT_ID/locations/REGION/repositories/UPSTREAM_REPOSITORY'
358+
b. URI to the registry, e.g. '"https://registry-1.docker.io"'
359+
c. URI to Artifact Registry Repository, e.g. '"https://REGION-docker.pkg.dev/UPSTREAM_PROJECT_ID/UPSTREAM_REPOSITORY"'`,
357360
},
358361
},
359362
},
@@ -383,7 +386,7 @@ not be validated.`,
383386
Type: schema.TypeList,
384387
Optional: true,
385388
ForceNew: true,
386-
Description: `Settings for a remote repository with a custom uri.`,
389+
Description: `[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.`,
387390
MaxItems: 1,
388391
Elem: &schema.Resource{
389392
Schema: map[string]*schema.Schema{
@@ -422,7 +425,7 @@ not be validated.`,
422425
Type: schema.TypeList,
423426
Optional: true,
424427
ForceNew: true,
425-
Description: `Settings for a remote repository with a custom uri.`,
428+
Description: `[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.`,
426429
MaxItems: 1,
427430
Elem: &schema.Resource{
428431
Schema: map[string]*schema.Schema{
@@ -461,7 +464,7 @@ not be validated.`,
461464
Type: schema.TypeList,
462465
Optional: true,
463466
ForceNew: true,
464-
Description: `Settings for a remote repository with a custom uri.`,
467+
Description: `[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.`,
465468
MaxItems: 1,
466469
Elem: &schema.Resource{
467470
Schema: map[string]*schema.Schema{
@@ -500,7 +503,7 @@ not be validated.`,
500503
Type: schema.TypeList,
501504
Optional: true,
502505
ForceNew: true,
503-
Description: `Settings for a remote repository with a custom uri.`,
506+
Description: `[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.`,
504507
MaxItems: 1,
505508
Elem: &schema.Resource{
506509
Schema: map[string]*schema.Schema{

Diff for: google-beta/services/artifactregistry/resource_artifact_registry_repository_generated_test.go

+122
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,128 @@ resource "google_artifact_registry_repository" "my-repo" {
825825
`, context)
826826
}
827827

828+
func TestAccArtifactRegistryRepository_artifactRegistryRepositoryRemoteCommonRepositoryWithArtifactRegistryUriExample(t *testing.T) {
829+
t.Parallel()
830+
831+
context := map[string]interface{}{
832+
"random_suffix": acctest.RandString(t, 10),
833+
}
834+
835+
acctest.VcrTest(t, resource.TestCase{
836+
PreCheck: func() { acctest.AccTestPreCheck(t) },
837+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
838+
CheckDestroy: testAccCheckArtifactRegistryRepositoryDestroyProducer(t),
839+
Steps: []resource.TestStep{
840+
{
841+
Config: testAccArtifactRegistryRepository_artifactRegistryRepositoryRemoteCommonRepositoryWithArtifactRegistryUriExample(context),
842+
},
843+
{
844+
ResourceName: "google_artifact_registry_repository.my-repo",
845+
ImportState: true,
846+
ImportStateVerify: true,
847+
ImportStateVerifyIgnore: []string{"labels", "location", "remote_repository_config.0.disable_upstream_validation", "repository_id", "terraform_labels"},
848+
},
849+
},
850+
})
851+
}
852+
853+
func testAccArtifactRegistryRepository_artifactRegistryRepositoryRemoteCommonRepositoryWithArtifactRegistryUriExample(context map[string]interface{}) string {
854+
return acctest.Nprintf(`
855+
data "google_project" "project" {}
856+
857+
resource "google_artifact_registry_repository" "upstream_repo" {
858+
location = "us-central1"
859+
repository_id = "tf-test-example-upstream-repo%{random_suffix}"
860+
description = "example upstream repository%{random_suffix}"
861+
format = "DOCKER"
862+
}
863+
864+
resource "google_artifact_registry_repository" "my-repo" {
865+
location = "us-central1"
866+
repository_id = "tf-test-example-common-remote%{random_suffix}"
867+
description = "example remote common repository with docker upstream%{random_suffix}"
868+
format = "DOCKER"
869+
mode = "REMOTE_REPOSITORY"
870+
remote_repository_config {
871+
description = "pull-through cache of another Artifact Registry repository by URL"
872+
common_repository {
873+
uri = "https://us-central1-docker.pkg.dev//tf-test-example-upstream-repo%{random_suffix}"
874+
}
875+
}
876+
}
877+
`, context)
878+
}
879+
880+
func TestAccArtifactRegistryRepository_artifactRegistryRepositoryRemoteCommonRepositoryWithCustomUpstreamExample(t *testing.T) {
881+
t.Parallel()
882+
883+
context := map[string]interface{}{
884+
"random_suffix": acctest.RandString(t, 10),
885+
}
886+
887+
acctest.VcrTest(t, resource.TestCase{
888+
PreCheck: func() { acctest.AccTestPreCheck(t) },
889+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
890+
CheckDestroy: testAccCheckArtifactRegistryRepositoryDestroyProducer(t),
891+
Steps: []resource.TestStep{
892+
{
893+
Config: testAccArtifactRegistryRepository_artifactRegistryRepositoryRemoteCommonRepositoryWithCustomUpstreamExample(context),
894+
},
895+
{
896+
ResourceName: "google_artifact_registry_repository.my-repo",
897+
ImportState: true,
898+
ImportStateVerify: true,
899+
ImportStateVerifyIgnore: []string{"labels", "location", "remote_repository_config.0.disable_upstream_validation", "repository_id", "terraform_labels"},
900+
},
901+
},
902+
})
903+
}
904+
905+
func testAccArtifactRegistryRepository_artifactRegistryRepositoryRemoteCommonRepositoryWithCustomUpstreamExample(context map[string]interface{}) string {
906+
return acctest.Nprintf(`
907+
data "google_project" "project" {}
908+
909+
resource "google_secret_manager_secret" "tf-test-example-remote-secret%{random_suffix}" {
910+
secret_id = "tf-test-example-secret%{random_suffix}"
911+
replication {
912+
auto {}
913+
}
914+
}
915+
916+
resource "google_secret_manager_secret_version" "tf-test-example-remote-secret%{random_suffix}_version" {
917+
secret = google_secret_manager_secret.tf-test-example-remote-secret%{random_suffix}.id
918+
secret_data = "tf-test-remote-password%{random_suffix}"
919+
}
920+
921+
resource "google_secret_manager_secret_iam_member" "secret-access" {
922+
secret_id = google_secret_manager_secret.tf-test-example-remote-secret%{random_suffix}.id
923+
role = "roles/secretmanager.secretAccessor"
924+
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-artifactregistry.iam.gserviceaccount.com"
925+
}
926+
927+
resource "google_artifact_registry_repository" "my-repo" {
928+
location = "us-central1"
929+
repository_id = "tf-test-example-docker-custom-remote%{random_suffix}"
930+
description = "example remote custom docker repository with credentia%{random_suffix}"
931+
format = "DOCKER"
932+
mode = "REMOTE_REPOSITORY"
933+
remote_repository_config {
934+
description = "custom common docker remote with credentials"
935+
disable_upstream_validation = true
936+
common_repository {
937+
uri = "https://registry-1.docker.io"
938+
}
939+
upstream_credentials {
940+
username_password_credentials {
941+
username = "tf-test-remote-username%{random_suffix}"
942+
password_secret_version = google_secret_manager_secret_version.tf-test-example-remote-secret%{random_suffix}_version.name
943+
}
944+
}
945+
}
946+
}
947+
`, context)
948+
}
949+
828950
func testAccCheckArtifactRegistryRepositoryDestroyProducer(t *testing.T) func(s *terraform.State) error {
829951
return func(s *terraform.State) error {
830952
for name, rs := range s.RootModule().Resources {

Diff for: website/docs/r/artifact_registry_repository.html.markdown

+90-5
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,88 @@ resource "google_artifact_registry_repository" "my-repo" {
542542
}
543543
}
544544
```
545+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
546+
<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_remote_common_repository_with_artifact_registry_uri&open_in_editor=main.tf" target="_blank">
547+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
548+
</a>
549+
</div>
550+
## Example Usage - Artifact Registry Repository Remote Common Repository With Artifact Registry Uri
551+
552+
553+
```hcl
554+
data "google_project" "project" {}
555+
556+
resource "google_artifact_registry_repository" "upstream_repo" {
557+
location = "us-central1"
558+
repository_id = "example-upstream-repo"
559+
description = "example upstream repository"
560+
format = "DOCKER"
561+
}
562+
563+
resource "google_artifact_registry_repository" "my-repo" {
564+
location = "us-central1"
565+
repository_id = "example-common-remote"
566+
description = "example remote common repository with docker upstream"
567+
format = "DOCKER"
568+
mode = "REMOTE_REPOSITORY"
569+
remote_repository_config {
570+
description = "pull-through cache of another Artifact Registry repository by URL"
571+
common_repository {
572+
uri = "https://us-central1-docker.pkg.dev//example-upstream-repo"
573+
}
574+
}
575+
}
576+
```
577+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
578+
<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_remote_common_repository_with_custom_upstream&open_in_editor=main.tf" target="_blank">
579+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
580+
</a>
581+
</div>
582+
## Example Usage - Artifact Registry Repository Remote Common Repository With Custom Upstream
583+
584+
585+
```hcl
586+
data "google_project" "project" {}
587+
588+
resource "google_secret_manager_secret" "example-remote-secret" {
589+
secret_id = "example-secret"
590+
replication {
591+
auto {}
592+
}
593+
}
594+
595+
resource "google_secret_manager_secret_version" "example-remote-secret_version" {
596+
secret = google_secret_manager_secret.example-remote-secret.id
597+
secret_data = "remote-password"
598+
}
599+
600+
resource "google_secret_manager_secret_iam_member" "secret-access" {
601+
secret_id = google_secret_manager_secret.example-remote-secret.id
602+
role = "roles/secretmanager.secretAccessor"
603+
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-artifactregistry.iam.gserviceaccount.com"
604+
}
605+
606+
resource "google_artifact_registry_repository" "my-repo" {
607+
location = "us-central1"
608+
repository_id = "example-docker-custom-remote"
609+
description = "example remote custom docker repository with credentials"
610+
format = "DOCKER"
611+
mode = "REMOTE_REPOSITORY"
612+
remote_repository_config {
613+
description = "custom common docker remote with credentials"
614+
disable_upstream_validation = true
615+
common_repository {
616+
uri = "https://registry-1.docker.io"
617+
}
618+
upstream_credentials {
619+
username_password_credentials {
620+
username = "remote-username"
621+
password_secret_version = google_secret_manager_secret_version.example-remote-secret_version.name
622+
}
623+
}
624+
}
625+
}
626+
```
545627

546628
## Argument Reference
547629

@@ -818,7 +900,7 @@ The following arguments are supported:
818900

819901
* `custom_repository` -
820902
(Optional)
821-
Settings for a remote repository with a custom uri.
903+
[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.
822904
Structure is [documented below](#nested_custom_repository).
823905

824906

@@ -838,7 +920,7 @@ The following arguments are supported:
838920

839921
* `custom_repository` -
840922
(Optional)
841-
Settings for a remote repository with a custom uri.
923+
[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.
842924
Structure is [documented below](#nested_custom_repository).
843925

844926

@@ -858,7 +940,7 @@ The following arguments are supported:
858940

859941
* `custom_repository` -
860942
(Optional)
861-
Settings for a remote repository with a custom uri.
943+
[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.
862944
Structure is [documented below](#nested_custom_repository).
863945

864946

@@ -878,7 +960,7 @@ The following arguments are supported:
878960

879961
* `custom_repository` -
880962
(Optional)
881-
Settings for a remote repository with a custom uri.
963+
[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.
882964
Structure is [documented below](#nested_custom_repository).
883965

884966

@@ -911,7 +993,10 @@ The following arguments are supported:
911993

912994
* `uri` -
913995
(Required)
914-
Specific uri to the Artifact Registory repository, e.g. `projects/UPSTREAM_PROJECT_ID/locations/REGION/repositories/UPSTREAM_REPOSITORY`
996+
One of:
997+
a. Artifact Registry Repository resource, e.g. `projects/UPSTREAM_PROJECT_ID/locations/REGION/repositories/UPSTREAM_REPOSITORY`
998+
b. URI to the registry, e.g. `"https://registry-1.docker.io"`
999+
c. URI to Artifact Registry Repository, e.g. `"https://REGION-docker.pkg.dev/UPSTREAM_PROJECT_ID/UPSTREAM_REPOSITORY"`
9151000

9161001
<a name="nested_upstream_credentials"></a>The `upstream_credentials` block supports:
9171002

0 commit comments

Comments
 (0)