diff --git a/.changelog/12290.txt b/.changelog/12290.txt new file mode 100644 index 00000000000..7f6670f0bda --- /dev/null +++ b/.changelog/12290.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +artifactregistry: added `common_repository` field to `google_artifact_registry_repository` resource +``` \ No newline at end of file diff --git a/google/services/artifactregistry/resource_artifact_registry_repository.go b/google/services/artifactregistry/resource_artifact_registry_repository.go index b42e0ae29b8..253a64c95c6 100644 --- a/google/services/artifactregistry/resource_artifact_registry_repository.go +++ b/google/services/artifactregistry/resource_artifact_registry_repository.go @@ -339,7 +339,25 @@ snapshot versions.`, }, }, }, - ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository"}, + ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"}, + }, + "common_repository": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Description: `Specific settings for an Artifact Registory remote repository.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "uri": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `Specific uri to the Artifact Registory repository, e.g. 'projects/UPSTREAM_PROJECT_ID/locations/REGION/repositories/UPSTREAM_REPOSITORY'`, + }, + }, + }, + ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"}, }, "description": { Type: schema.TypeString, @@ -390,7 +408,7 @@ not be validated.`, }, }, }, - ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository"}, + ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"}, }, "maven_repository": { Type: schema.TypeList, @@ -429,7 +447,7 @@ not be validated.`, }, }, }, - ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository"}, + ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"}, }, "npm_repository": { Type: schema.TypeList, @@ -468,7 +486,7 @@ not be validated.`, }, }, }, - ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository"}, + ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"}, }, "python_repository": { Type: schema.TypeList, @@ -507,7 +525,7 @@ not be validated.`, }, }, }, - ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository"}, + ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"}, }, "upstream_credentials": { Type: schema.TypeList, @@ -579,7 +597,7 @@ remote repository. Must be in the format of }, }, }, - ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository"}, + ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"}, }, }, }, @@ -1407,6 +1425,8 @@ func flattenArtifactRegistryRepositoryRemoteRepositoryConfig(v interface{}, d *s flattenArtifactRegistryRepositoryRemoteRepositoryConfigPythonRepository(original["pythonRepository"], d, config) transformed["yum_repository"] = flattenArtifactRegistryRepositoryRemoteRepositoryConfigYumRepository(original["yumRepository"], d, config) + transformed["common_repository"] = + flattenArtifactRegistryRepositoryRemoteRepositoryConfigCommonRepository(original["commonRepository"], d, config) transformed["upstream_credentials"] = flattenArtifactRegistryRepositoryRemoteRepositoryConfigUpstreamCredentials(original["upstreamCredentials"], d, config) transformed["disable_upstream_validation"] = @@ -1649,6 +1669,23 @@ func flattenArtifactRegistryRepositoryRemoteRepositoryConfigYumRepositoryPublicR return v } +func flattenArtifactRegistryRepositoryRemoteRepositoryConfigCommonRepository(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["uri"] = + flattenArtifactRegistryRepositoryRemoteRepositoryConfigCommonRepositoryUri(original["uri"], d, config) + return []interface{}{transformed} +} +func flattenArtifactRegistryRepositoryRemoteRepositoryConfigCommonRepositoryUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenArtifactRegistryRepositoryRemoteRepositoryConfigUpstreamCredentials(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return nil @@ -2075,6 +2112,13 @@ func expandArtifactRegistryRepositoryRemoteRepositoryConfig(v interface{}, d tpg transformed["yumRepository"] = transformedYumRepository } + transformedCommonRepository, err := expandArtifactRegistryRepositoryRemoteRepositoryConfigCommonRepository(original["common_repository"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedCommonRepository); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["commonRepository"] = transformedCommonRepository + } + transformedUpstreamCredentials, err := expandArtifactRegistryRepositoryRemoteRepositoryConfigUpstreamCredentials(original["upstream_credentials"], d, config) if err != nil { return nil, err @@ -2414,6 +2458,29 @@ func expandArtifactRegistryRepositoryRemoteRepositoryConfigYumRepositoryPublicRe return v, nil } +func expandArtifactRegistryRepositoryRemoteRepositoryConfigCommonRepository(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedUri, err := expandArtifactRegistryRepositoryRemoteRepositoryConfigCommonRepositoryUri(original["uri"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUri); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["uri"] = transformedUri + } + + return transformed, nil +} + +func expandArtifactRegistryRepositoryRemoteRepositoryConfigCommonRepositoryUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandArtifactRegistryRepositoryRemoteRepositoryConfigUpstreamCredentials(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/google/services/artifactregistry/resource_artifact_registry_repository_generated_test.go b/google/services/artifactregistry/resource_artifact_registry_repository_generated_test.go index 3de7ec42499..b232e962cd2 100644 --- a/google/services/artifactregistry/resource_artifact_registry_repository_generated_test.go +++ b/google/services/artifactregistry/resource_artifact_registry_repository_generated_test.go @@ -775,6 +775,56 @@ resource "google_artifact_registry_repository" "my-repo" { `, context) } +func TestAccArtifactRegistryRepository_artifactRegistryRepositoryRemoteCommonRepositoryWithDockerExample(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_artifactRegistryRepositoryRemoteCommonRepositoryWithDockerExample(context), + }, + { + ResourceName: "google_artifact_registry_repository.my-repo", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"labels", "location", "remote_repository_config.0.disable_upstream_validation", "repository_id", "terraform_labels"}, + }, + }, + }) +} + +func testAccArtifactRegistryRepository_artifactRegistryRepositoryRemoteCommonRepositoryWithDockerExample(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_artifact_registry_repository" "upstream_repo" { + location = "us-central1" + repository_id = "tf-test-example-upstream-repo%{random_suffix}" + description = "example upstream repository%{random_suffix}" + format = "DOCKER" +} + +resource "google_artifact_registry_repository" "my-repo" { + location = "us-central1" + repository_id = "tf-test-example-common-remote%{random_suffix}" + description = "example remote common repository with docker upstream%{random_suffix}" + format = "DOCKER" + mode = "REMOTE_REPOSITORY" + remote_repository_config { + description = "pull-through cache of another Artifact Registry repository" + common_repository { + uri = google_artifact_registry_repository.upstream_repo.id + } + } +} +`, context) +} + func testAccCheckArtifactRegistryRepositoryDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { for name, rs := range s.RootModule().Resources { diff --git a/website/docs/r/artifact_registry_repository.html.markdown b/website/docs/r/artifact_registry_repository.html.markdown index ea7233bf6da..959d4365e91 100644 --- a/website/docs/r/artifact_registry_repository.html.markdown +++ b/website/docs/r/artifact_registry_repository.html.markdown @@ -512,6 +512,36 @@ resource "google_artifact_registry_repository" "my-repo" { } } ``` +
+ + Open in Cloud Shell + +
+## Example Usage - Artifact Registry Repository Remote Common Repository With Docker + + +```hcl +resource "google_artifact_registry_repository" "upstream_repo" { + location = "us-central1" + repository_id = "example-upstream-repo" + description = "example upstream repository" + format = "DOCKER" +} + +resource "google_artifact_registry_repository" "my-repo" { + location = "us-central1" + repository_id = "example-common-remote" + description = "example remote common repository with docker upstream" + format = "DOCKER" + mode = "REMOTE_REPOSITORY" + remote_repository_config { + description = "pull-through cache of another Artifact Registry repository" + common_repository { + uri = google_artifact_registry_repository.upstream_repo.id + } + } +} +``` ## Argument Reference @@ -743,6 +773,11 @@ The following arguments are supported: Specific settings for an Yum remote repository. Structure is [documented below](#nested_yum_repository). +* `common_repository` - + (Optional) + Specific settings for an Artifact Registory remote repository. + Structure is [documented below](#nested_common_repository). + * `upstream_credentials` - (Optional) The credentials used to access the remote repository. @@ -872,6 +907,12 @@ The following arguments are supported: (Required) Specific repository from the base, e.g. `"pub/rocky/9/BaseOS/x86_64/os"` +The `common_repository` block supports: + +* `uri` - + (Required) + Specific uri to the Artifact Registory repository, e.g. `projects/UPSTREAM_PROJECT_ID/locations/REGION/repositories/UPSTREAM_REPOSITORY` + The `upstream_credentials` block supports: * `username_password_credentials` -