Skip to content

Commit

Permalink
Merge branch 'jfrog:master' into jfrogGH-621-bulk-import
Browse files Browse the repository at this point in the history
  • Loading branch information
chb0github authored Feb 15, 2024
2 parents b42796e + 2877920 commit 30c0586
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 18 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 10.1.4 (Feb 14, 2024)

BUG FIXES:

* data/artifactory_virtual_maven_repository: Restore data source after being removed from the provider by mistake. PR: [#887](https://github.com/jfrog/terraform-provider-artifactory/pull/887) Issue: [#873](https://github.com/jfrog/terraform-provider-artifactory/issues/873)
* resource/artifactory_permission_target: Add check for '409 Conflict' error during resource creation and ignores it. PR: [#888](https://github.com/jfrog/terraform-provider-artifactory/pull/888) Issue: [#853](https://github.com/jfrog/terraform-provider-artifactory/issues/853)

## 10.1.3 (Feb 7, 2024)

BUG FIXES:

* resource/artifactory_group: Add length validation to `name` attribute to match Artifactory web UI. PR: [#884](https://github.com/jfrog/terraform-provider-artifactory/pull/884) Issue: [#883](https://github.com/jfrog/terraform-provider-artifactory/issues/883)

## 10.1.2 (Jan 19, 2024)

BUG FIXES:
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/general_security.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resource "artifactory_general_security" "security" {

The following arguments are supported:

* `enable_anonoymous_access` - (Optional) Enable anonymous access. Default value is `false`.
* `enable_anonymous_access` - (Optional) Enable anonymous access. Default value is `false`.

## Import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func TestAccDataSourceVirtualAllGradleLikePackageTypes(t *testing.T) {
for _, packageType := range repository.GradleLikePackageTypes {
t.Run(packageType, func(t *testing.T) {
resource.Test(mkNewVirtualTestCase(packageType, t, map[string]interface{}{
"description": fmt.Sprintf("%s virtual repository public description testing.", packageType),
"force_maven_authentication": true,
"description": fmt.Sprintf("%s virtual repository public description testing.", packageType),
"pom_repository_references_cleanup_policy": "discard_active_reference",
}))
})
Expand Down Expand Up @@ -102,6 +101,13 @@ func TestAccDataSourceVirtualHelmRepository(t *testing.T) {
}))
}

func TestAccDataSourceVirtualMavenRepository(t *testing.T) {
resource.Test(mkNewVirtualTestCase(repository.MavenPackageType, t, map[string]interface{}{
"description": "maven virtual repository public description testing.",
"force_maven_authentication": true,
}))
}

func TestAccDataSourceVirtualNpmRepository(t *testing.T) {
resource.Test(mkNewVirtualTestCase(virtual.NpmPackageType, t, map[string]interface{}{
"description": "npm virtual repository public description testing.",
Expand Down
5 changes: 3 additions & 2 deletions pkg/artifactory/provider/datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func datasourcesMap() map[string]*schema.Resource {
"artifactory_local_debian_repository": datasource_local.DataSourceArtifactoryLocalDebianRepository(),
"artifactory_local_docker_v2_repository": datasource_local.DataSourceArtifactoryLocalDockerV2Repository(),
"artifactory_local_docker_v1_repository": datasource_local.DataSourceArtifactoryLocalDockerV1Repository(),
"artifactory_local_maven_repository": datasource_local.DataSourceArtifactoryLocalJavaRepository("maven", false),
"artifactory_local_maven_repository": datasource_local.DataSourceArtifactoryLocalJavaRepository(repository.MavenPackageType, false),
"artifactory_local_nuget_repository": datasource_local.DataSourceArtifactoryLocalNugetRepository(),
"artifactory_local_rpm_repository": datasource_local.DataSourceArtifactoryLocalRpmRepository(),
"artifactory_local_terraform_module_repository": datasource_local.DataSourceArtifactoryLocalTerraformRepository("module"),
Expand All @@ -59,6 +59,7 @@ func datasourcesMap() map[string]*schema.Resource {
"artifactory_virtual_go_repository": datasource_virtual.DatasourceArtifactoryVirtualGoRepository(),
"artifactory_virtual_docker_repository": datasource_virtual.DatasourceArtifactoryVirtualDockerRepository(),
"artifactory_virtual_helm_repository": datasource_virtual.DatasourceArtifactoryVirtualHelmRepository(),
"artifactory_virtual_maven_repository": datasource_virtual.DataSourceArtifactoryVirtualJavaRepository(repository.MavenPackageType),
"artifactory_virtual_npm_repository": datasource_virtual.DatasourceArtifactoryVirtualNpmRepository(),
"artifactory_virtual_nuget_repository": datasource_virtual.DatasourceArtifactoryVirtualNugetRepository(),
"artifactory_virtual_rpm_repository": datasource_virtual.DatasourceArtifactoryVirtualRpmRepository(),
Expand All @@ -69,7 +70,7 @@ func datasourcesMap() map[string]*schema.Resource {
"artifactory_federated_docker_v1_repository": datasource_federated.DataSourceArtifactoryFederatedDockerV1Repository(),
"artifactory_federated_docker_v2_repository": datasource_federated.DataSourceArtifactoryFederatedDockerV2Repository(),
"artifactory_federated_docker_repository": datasource_federated.DataSourceArtifactoryFederatedDockerV2Repository(),
"artifactory_federated_maven_repository": datasource_federated.DataSourceArtifactoryFederatedJavaRepository("maven", false),
"artifactory_federated_maven_repository": datasource_federated.DataSourceArtifactoryFederatedJavaRepository(repository.MavenPackageType, false),
"artifactory_federated_nuget_repository": datasource_federated.DataSourceArtifactoryFederatedNugetRepository(),
"artifactory_federated_rpm_repository": datasource_federated.DataSourceArtifactoryFederatedRpmRepository(),
"artifactory_federated_terraform_module_repository": datasource_federated.DataSourceArtifactoryFederatedTerraformRepository("module"),
Expand Down
6 changes: 3 additions & 3 deletions pkg/artifactory/provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func resourcesMap() map[string]*schema.Resource {
"artifactory_federated_docker_repository": federated.ResourceArtifactoryFederatedDockerV2Repository(), // Alias for backward compatibility
"artifactory_federated_docker_v1_repository": federated.ResourceArtifactoryFederatedDockerV1Repository(),
"artifactory_federated_docker_v2_repository": federated.ResourceArtifactoryFederatedDockerV2Repository(),
"artifactory_federated_maven_repository": federated.ResourceArtifactoryFederatedJavaRepository("maven", false),
"artifactory_federated_maven_repository": federated.ResourceArtifactoryFederatedJavaRepository(repository.MavenPackageType, false),
"artifactory_federated_nuget_repository": federated.ResourceArtifactoryFederatedNugetRepository(),
"artifactory_federated_rpm_repository": federated.ResourceArtifactoryFederatedRpmRepository(),
"artifactory_federated_terraform_module_repository": federated.ResourceArtifactoryFederatedTerraformRepository("module"),
"artifactory_federated_terraform_provider_repository": federated.ResourceArtifactoryFederatedTerraformRepository("provider"),
"artifactory_local_nuget_repository": local.ResourceArtifactoryLocalNugetRepository(),
"artifactory_local_maven_repository": local.ResourceArtifactoryLocalJavaRepository("maven", false),
"artifactory_local_maven_repository": local.ResourceArtifactoryLocalJavaRepository(repository.MavenPackageType, false),
"artifactory_local_alpine_repository": local.ResourceArtifactoryLocalAlpineRepository(),
"artifactory_local_cargo_repository": local.ResourceArtifactoryLocalCargoRepository(),
"artifactory_local_conan_repository": local.ResourceArtifactoryLocalConanRepository(),
Expand Down Expand Up @@ -63,7 +63,7 @@ func resourcesMap() map[string]*schema.Resource {
"artifactory_virtual_conan_repository": virtual.ResourceArtifactoryVirtualConanRepository(),
"artifactory_virtual_debian_repository": virtual.ResourceArtifactoryVirtualDebianRepository(),
"artifactory_virtual_docker_repository": virtual.ResourceArtifactoryVirtualDockerRepository(),
"artifactory_virtual_maven_repository": virtual.ResourceArtifactoryVirtualJavaRepository("maven"),
"artifactory_virtual_maven_repository": virtual.ResourceArtifactoryVirtualJavaRepository(repository.MavenPackageType),
"artifactory_virtual_npm_repository": virtual.ResourceArtifactoryVirtualNpmRepository(),
"artifactory_virtual_nuget_repository": virtual.ResourceArtifactoryVirtualNugetRepository(),
"artifactory_virtual_go_repository": virtual.ResourceArtifactoryVirtualGoRepository(),
Expand Down
2 changes: 2 additions & 0 deletions pkg/artifactory/resource/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ var GradleLikePackageTypes = []string{
"ivy",
}

const MavenPackageType = "maven"

var ProjectEnvironmentsSupported = []string{"DEV", "PROD"}

func RepoLayoutRefSchema(repositoryType string, packageType string) map[string]*schema.Schema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ func ResourceArtifactoryVirtualJavaRepository(repoType string) *schema.Resource
unpackMavenVirtualRepository,
constructor,
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"strconv"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -86,6 +87,9 @@ func (r *ArtifactoryGroupResource) Schema(ctx context.Context, req resource.Sche
"name": schema.StringAttribute{
MarkdownDescription: "Name of the group.",
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 64),
},
},
"description": schema.StringAttribute{
MarkdownDescription: "A description for the group.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"regexp"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -189,6 +190,42 @@ func TestAccGroup_bool_conflict(t *testing.T) {
})
}

func TestAccGroup_name_too_long(t *testing.T) {
_, fqrn, groupName := testutil.MkNames("test-group-full", "artifactory_group")

groupName = fmt.Sprintf("%s%s", groupName, strings.Repeat("X", 60))
temp := `
resource "artifactory_group" "{{ .groupName }}" {
name = "{{ .groupName }}"
description = "Test group"
external_id = "externalID"
auto_join = true
admin_privileges = false
realm = "test"
realm_attributes = "Some attribute"
detach_all_users = true
watch_manager = true
policy_manager = true
reports_manager = true
users_names = ["anonymous", "admin"]
}
`

config := util.ExecuteTemplate(groupName, temp, map[string]string{"groupName": groupName})

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
CheckDestroy: testAccCheckGroupDestroy(fqrn),
Steps: []resource.TestStep{
{
Config: config,
ExpectError: regexp.MustCompile(".*Attribute name string length must be between 1 and 64.*"),
},
},
})
}

func TestAccGroup_unmanaged_members_update(t *testing.T) {
_, fqrn, groupName := testutil.MkNames("test-group-unmanaged-members", "artifactory_group")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package security
import (
"context"
"net/http"
"regexp"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -323,26 +324,37 @@ func PackPermissionTarget(permissionTarget *PermissionTargetParams, d *schema.Re
errors = setValue("release_bundle", packPermission(permissionTarget.ReleaseBundle))
}

if errors != nil && len(errors) > 0 {
if len(errors) > 0 {
return diag.Errorf("failed to marshal permission target %q", errors)
}
return nil
}

var conflictRegex = regexp.MustCompile(`.*Can't create permission target '.+' for type .+\. It already exists.*`)

func resourcePermissionTargetCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
permissionTarget := unpackPermissionTarget(ctx, d)

if _, err := m.(util.ProvderMetadata).Client.R().AddRetryCondition(repository.Retry400).SetBody(permissionTarget).Post(PermissionsEndPoint + permissionTarget.Name); err != nil {
return diag.FromErr(err)
resp, err := m.(util.ProvderMetadata).Client.R().
AddRetryCondition(repository.Retry400).
SetBody(permissionTarget).
Post(PermissionsEndPoint + permissionTarget.Name)
if err != nil {
if !(resp.StatusCode() == http.StatusConflict && conflictRegex.Match(resp.Body())) {
return diag.FromErr(err)
}
}

d.SetId(permissionTarget.Name)
return nil
return resourcePermissionTargetRead(ctx, d, m)
}

func resourcePermissionTargetRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
permissionTarget := new(PermissionTargetParams)
resp, err := m.(util.ProvderMetadata).Client.R().SetResult(permissionTarget).Get(PermissionsEndPoint + d.Id())
var permissionTarget PermissionTargetParams

resp, err := m.(util.ProvderMetadata).Client.R().
SetResult(&permissionTarget).
Get(PermissionsEndPoint + d.Id())
if err != nil {
if resp != nil && resp.StatusCode() == http.StatusNotFound {
d.SetId("")
Expand All @@ -351,13 +363,16 @@ func resourcePermissionTargetRead(_ context.Context, d *schema.ResourceData, m i
return diag.FromErr(err)
}

return PackPermissionTarget(permissionTarget, d)
return PackPermissionTarget(&permissionTarget, d)
}

func resourcePermissionTargetUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
permissionTarget := unpackPermissionTarget(ctx, d)

if _, err := m.(util.ProvderMetadata).Client.R().SetBody(permissionTarget).Put(PermissionsEndPoint + d.Id()); err != nil {
_, err := m.(util.ProvderMetadata).Client.R().
SetBody(permissionTarget).
Put(PermissionsEndPoint + d.Id())
if err != nil {
return diag.FromErr(err)
}

Expand Down
2 changes: 1 addition & 1 deletion sample.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
artifactory = {
source = "registry.terraform.io/jfrog/artifactory"
version = "10.0.2"
version = "10.1.4"
}
}
}
Expand Down

0 comments on commit 30c0586

Please sign in to comment.