Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix virtual go repo external_dependencies_patterns still force replacement on update #1051

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 11.5.2 (August 12, 2024). Tested on Artifactory 7.90.7 with Terraform 1.9.4 and OpenTofu 1.8.1

BUG FIXES:

* resource/artifactory_virtual_go_repository: Fix updating `external_dependencies_patterns` attribute triggers a resource replacement that wasn't fixed in PR [#1005](https://github.com/jfrog/terraform-provider-artifactory/pull/1005). Issue: [#1004](https://github.com/jfrog/terraform-provider-artifactory/issues/1004) PR: [#1051](https://github.com/jfrog/terraform-provider-artifactory/pull/1051)

## 11.5.1 (August 8, 2024). Tested on Artifactory 7.90.6 with Terraform 1.9.4 and OpenTofu 1.8.1

BUG FIXES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@ import (

const GoPackageType = "go"

var GoVirtualSchema = utilsdk.MergeMaps(BaseVirtualRepoSchema, map[string]*schema.Schema{
"external_dependencies_enabled": {
Type: schema.TypeBool,
Default: true,
Optional: true,
Description: "When set (default), Artifactory will automatically follow remote VCS roots in 'go-import' meta tags to download remote modules.",
},
"external_dependencies_patterns": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
var GoVirtualSchema = utilsdk.MergeMaps(
BaseVirtualRepoSchema,
map[string]*schema.Schema{
"external_dependencies_enabled": {
Type: schema.TypeBool,
Default: true,
Optional: true,
Description: "When set (default), Artifactory will automatically follow remote VCS roots in 'go-import' meta tags to download remote modules.",
},
"external_dependencies_patterns": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
RequiredWith: []string{"external_dependencies_enabled"},
Description: "An allow list of Ant-style path patterns that determine which remote VCS roots Artifactory will " +
"follow to download remote modules from, when presented with 'go-import' meta tags in the remote repository response.",
},
RequiredWith: []string{"external_dependencies_enabled"},
Description: "An allow list of Ant-style path patterns that determine which remote VCS roots Artifactory will " +
"follow to download remote modules from, when presented with 'go-import' meta tags in the remote repository response.",
},
}, repository.RepoLayoutRefSchema(Rclass, GoPackageType))
repository.RepoLayoutRefSchema(Rclass, GoPackageType),
)

func ResourceArtifactoryVirtualGoRepository() *schema.Resource {
type GoVirtualRepositoryParams struct {
Expand All @@ -44,7 +47,6 @@ func ResourceArtifactoryVirtualGoRepository() *schema.Resource {
ExternalDependenciesPatterns: d.GetList("external_dependencies_patterns"),
ExternalDependenciesEnabled: d.GetBool("external_dependencies_enabled", false),
}
repo.PackageType = "go"
return &repo, repo.Key, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/go-resty/resty/v2"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/jfrog/terraform-provider-artifactory/v11/pkg/acctest"
"github.com/jfrog/terraform-provider-artifactory/v11/pkg/artifactory/resource/repository"
"github.com/jfrog/terraform-provider-artifactory/v11/pkg/artifactory/resource/repository/virtual"
Expand Down Expand Up @@ -956,6 +957,107 @@ func TestAccVirtualBowerExternalDependenciesRepository(t *testing.T) {
})
}

func TestAccVirtualGoExternalDependenciesRepository(t *testing.T) {
id := testutil.RandomInt()
name := fmt.Sprintf("go-virtual-%d", id)
remoteRepoName := fmt.Sprintf("go-remote-%d", id)
fqrn := fmt.Sprintf("artifactory_virtual_go_repository.%s", name)

params := map[string]interface{}{
"name": name,
"remoteRepoName": remoteRepoName,
}
config := util.ExecuteTemplate("TestAccVirtualGo", `
resource "artifactory_remote_go_repository" "go-remote" {
key = "{{ .remoteRepoName }}"
url = "https://proxy.golang.org/"
}

resource "artifactory_virtual_go_repository" "{{ .name }}" {
key = "{{ .name }}"
repositories = [artifactory_remote_go_repository.go-remote.key]
external_dependencies_enabled = true
external_dependencies_patterns = [
"**/github.com/**",
"**/bitbucket.org/**",
"**/gopkg.in/**",
"**/golang.org/**",
"**/k8s.io/**",
]
}
`, params)

updatedConfig := util.ExecuteTemplate("TestAccVirtualGo", `
resource "artifactory_remote_go_repository" "go-remote" {
key = "{{ .remoteRepoName }}"
url = "https://proxy.golang.org/"
}

resource "artifactory_virtual_go_repository" "{{ .name }}" {
key = "{{ .name }}"
repositories = [artifactory_remote_go_repository.go-remote.key]
external_dependencies_enabled = true
external_dependencies_patterns = [
"**/github.com/**",
"**/gopkg.in/**",
"**/golang.org/**",
"**/k8s.io/**",
]
}
`, params)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: acctest.VerifyDeleted(fqrn, "", acctest.CheckRepo),

Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(fqrn, "key", name),
resource.TestCheckResourceAttr(fqrn, "package_type", "go"),
resource.TestCheckResourceAttr(fqrn, "repositories.#", "1"),
resource.TestCheckResourceAttr(fqrn, "repositories.0", remoteRepoName),
resource.TestCheckResourceAttr(fqrn, "external_dependencies_enabled", "true"),
resource.TestCheckResourceAttr(fqrn, "external_dependencies_patterns.#", "5"),
resource.TestCheckTypeSetElemAttr(fqrn, "external_dependencies_patterns.*", "**/github.com/**"),
resource.TestCheckTypeSetElemAttr(fqrn, "external_dependencies_patterns.*", "**/bitbucket.org/**"),
resource.TestCheckTypeSetElemAttr(fqrn, "external_dependencies_patterns.*", "**/gopkg.in/**"),
resource.TestCheckTypeSetElemAttr(fqrn, "external_dependencies_patterns.*", "**/golang.org/**"),
resource.TestCheckTypeSetElemAttr(fqrn, "external_dependencies_patterns.*", "**/k8s.io/**"),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(fqrn, "key", name),
resource.TestCheckResourceAttr(fqrn, "package_type", "go"),
resource.TestCheckResourceAttr(fqrn, "repositories.#", "1"),
resource.TestCheckResourceAttr(fqrn, "repositories.0", remoteRepoName),
resource.TestCheckResourceAttr(fqrn, "external_dependencies_enabled", "true"),
resource.TestCheckResourceAttr(fqrn, "external_dependencies_patterns.#", "4"),
resource.TestCheckTypeSetElemAttr(fqrn, "external_dependencies_patterns.*", "**/github.com/**"),
resource.TestCheckTypeSetElemAttr(fqrn, "external_dependencies_patterns.*", "**/gopkg.in/**"),
resource.TestCheckTypeSetElemAttr(fqrn, "external_dependencies_patterns.*", "**/golang.org/**"),
resource.TestCheckTypeSetElemAttr(fqrn, "external_dependencies_patterns.*", "**/k8s.io/**"),
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(fqrn, plancheck.ResourceActionUpdate),
},
},
},
{
ResourceName: fqrn,
ImportState: true,
ImportStateVerify: true,
ImportStateCheck: validator.CheckImportState(name, "key"),
},
},
})
}

func TestAccVirtualNpmExternalDependenciesRepository(t *testing.T) {
id := testutil.RandomInt()
name := fmt.Sprintf("npm-virtual-%d", id)
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-artifactory-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ echo "ARTIFACTORY_VERSION=${ARTIFACTORY_VERSION}" > /dev/stderr
set -euf

mkdir -p ${SCRIPT_DIR}/artifactory/extra_conf
mkdir -p ${SCRIPT_DIR}/artifactory/var
mkdir -p ${SCRIPT_DIR}/artifactory/var/etc/access

cp ${SCRIPT_DIR}/artifactory.lic ${SCRIPT_DIR}/artifactory/extra_conf
cp ${SCRIPT_DIR}/system.yaml ${SCRIPT_DIR}/artifactory/var/etc/
Expand Down
Loading