Skip to content

Commit a5ecbd6

Browse files
committed
Merge pull request jfrog#804 from jfrog/remove-repos-project-key-default
Remove repos project key default
2 parents a342a30 + d663356 commit a5ecbd6

File tree

13 files changed

+128
-36
lines changed

13 files changed

+128
-36
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
## 9.0.0 (Sep 15, 2023). Tested on Artifactory 7.68.7 with Terraform CLI v1.5.7
2+
3+
IMPROVEMENTS:
4+
* resource/artifactory_\*\_repository: remove default value of "default" from `project_key` attribute. This is a REST API bug fix that is part of Artifactory v7.68.7 (self-hosted) and v7.67.0 (cloud). Existing Terraform state with "default" value should be automatically migrated to "" on `terraform apply`. No state drift should occurs on `terraform plan`. Issue: [#779](https://github.com/jfrog/terraform-provider-artifactory/issues/779)
5+
* Fix incorrect description for remote repository attribute `block_mismatching_mime_types`. Issue: [#799](https://github.com/jfrog/terraform-provider-artifactory/pull/799)
6+
* Add multiple users and groups HCL example for `artifactory_permission_target` resource. Issue: [#800](https://github.com/jfrog/terraform-provider-artifactory/pull/800)
7+
8+
PR: [#804](https://github.com/jfrog/terraform-provider-artifactory/pull/804)
9+
110
## 8.9.1 (Sep 11, 2023). Tested on Artifactory 7.63.14 with Terraform CLI v1.5.7
11+
212
BUG FIX:
313
* resource/artifactory_local_\*\_repository, resource/artifactory_remote_\*\_repository, resource/artifactory_virtual_\*\_repository, resource/artifactory_federated_\*\_repository: fix unable to set `description` and `notes` attributes with empty text.
414

docs/resources/local.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ The following arguments are supported:
2424
contain spaces or special characters.
2525
* `description` - (Optional)
2626
* `notes` - (Optional)
27-
* `project_key` - (Optional) Project key for assigning this repository to. Must be 2 - 20 lowercase alphanumeric and hyphen characters.
28-
When assigning repository to a project, repository key must be prefixed with project key, separated by a dash.
29-
We don't recommend using this attribute to assign the repository to the project. Use the `repos` attribute in Project provider
30-
to manage the list of repositories. Default value - `default`.
27+
* `project_key` - (Optional) Project key for assigning this repository to. Must be 2 - 20 lowercase alphanumeric and hyphen characters. When assigning repository to a project, repository key must be prefixed with project key, separated by a dash. We don't recommend using this attribute to assign the repository to the project. Use the `repos` attribute in Project provider to manage the list of repositories.
3128
* `project_environments` - (Optional) Project environment for assigning this repository to. Allow values: `DEV` or `PROD`.
3229
Before Artifactory 7.53.1, up to 2 values (`DEV` and `PROD`) are allowed. From 7.53.1 onward, only one value is allowed.
3330
The attribute should only be used if the repository is already assigned to the existing project.

docs/resources/permission_target.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ resource "artifactory_permission_target" "test-perm" {
2323
permissions = ["read", "write"]
2424
}
2525
26+
users {
27+
name = "user1"
28+
permissions = ["read", "write"]
29+
}
30+
2631
groups {
2732
name = "readers"
2833
permissions = ["read"]
2934
}
35+
36+
groups {
37+
name = "dev"
38+
permissions = ["read", "write"]
39+
}
3040
}
3141
}
3242
@@ -37,6 +47,11 @@ resource "artifactory_permission_target" "test-perm" {
3747
actions {
3848
users {
3949
name = "anonymous"
50+
permissions = ["read"]
51+
}
52+
53+
users {
54+
name = "user1"
4055
permissions = ["read", "write"]
4156
}
4257
}

docs/resources/remote.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ All generic repo arguments are supported, in addition to:
3737
* `key` - (Required) A mandatory identifier for the repository that must be unique. It cannot begin with a number or contain spaces or special characters.
3838
* `description` - (Optional) Public description.
3939
* `notes` - (Optional) Internal description.
40-
* `project_key` - (Optional) Project key for assigning this repository to. Must be 2 - 20 lowercase alphanumeric and hyphen characters.
41-
When assigning repository to a project, repository key must be prefixed with project key, separated by a dash.
42-
We don't recommend using this attribute to assign the repository to the project. Use the `repos` attribute in Project provider
43-
to manage the list of repositories. Default value - `default`.
40+
* `project_key` - (Optional) Project key for assigning this repository to. Must be 2 - 20 lowercase alphanumeric and hyphen characters. When assigning repository to a project, repository key must be prefixed with project key, separated by a dash. We don't recommend using this attribute to assign the repository to the project. Use the `repos` attribute in Project provider to manage the list of repositories.
4441
* `project_environments` - (Optional) Project environment for assigning this repository to. Allow values: `DEV` or `PROD`.
4542
Before Artifactory 7.53.1, up to 2 values (`DEV` and `PROD`) are allowed. From 7.53.1 onward, only one value is allowed.
4643
The attribute should only be used if the repository is already assigned to the existing project.
@@ -68,7 +65,7 @@ All generic repo arguments are supported, in addition to:
6865
* `assumed_offline_period_secs` - (Optional, Default: `300`) The number of seconds the repository stays in assumed offline state after a connection error. At the end of this time, an online check is attempted in order to reset the offline status. A value of 0 means the repository is never assumed offline.
6966
* `share_configuration` - (Optional) The attribute is 'Computed', so it's not managed by the Provider. There is no corresponding field in the UI, but the attribute is returned by Get.
7067
* `synchronize_properties` - (Optional, Default: `false`) When set, remote artifacts are fetched along with their properties.
71-
* `block_mismatching_mime_types` - (Optional, Default: `true`) Before caching an artifact, Artifactory first sends a HEAD request to the remote resource. In some remote resources, HEAD requests are disallowed and therefore rejected, even though downloading the artifact is allowed. When checked, Artifactory will bypass the HEAD request and cache the artifact directly using a GET request. Note: dafault value in the UI is `true`, but it is `false` if the repo was created using the API call. We are copying the UI behavior.
68+
* `block_mismatching_mime_types` - (Optional, Default: `true`) If set, artifacts will fail to download if a mismatch is detected between requested and received mimetype, according to the list specified in the system properties file under blockedMismatchingMimeTypes. You can override by adding mimetypes to the override list `mismatching_mime_types_override_list`.
7269
* `mismatching_mime_types_override_list` - (Optional) The set of mime types that should override the block_mismatching_mime_types setting. Eg: "application/json,application/xml". Default value is empty.
7370
* `property_sets` - (Optional) List of property set names.
7471
* `allow_any_host_auth` - (Optional, Default: `false`) Also known as 'Lenient Host Authentication', Allow credentials of this repository to be used on requests redirected to any other host.

docs/resources/virtual.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ The following arguments are supported:
2828
* `key` - (Required) A mandatory identifier for the repository that must be unique. It cannot begin with a number or
2929
contain spaces or special characters.
3030
* `repositories` - (Optional) The effective list of actual repositories included in this virtual repository.
31-
* `project_key` - (Optional) Project key for assigning this repository to. Must be 2 - 20 lowercase alphanumeric and hyphen characters.
32-
When assigning repository to a project, repository key must be prefixed with project key, separated by a dash.
33-
We don't recommend using this attribute to assign the repository to the project. Use the `repos` attribute in Project provider
34-
to manage the list of repositories. Default value - `default`.
31+
* `project_key` - (Optional) Project key for assigning this repository to. Must be 2 - 20 lowercase alphanumeric and hyphen characters. When assigning repository to a project, repository key must be prefixed with project key, separated by a dash. We don't recommend using this attribute to assign the repository to the project. Use the `repos` attribute in Project provider to manage the list of repositories.
3532
* `project_environments` - (Optional) Project environment for assigning this repository to. Allow values: `DEV` or `PROD`.
3633
Before Artifactory 7.53.1, up to 2 values (`DEV` and `PROD`) are allowed. From 7.53.1 onward, only one value is allowed.
3734
The attribute should only be used if the repository is already assigned to the existing project.

pkg/artifactory/resource/repository/federated/federated.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,22 @@ func mkResourceSchema(skeema map[string]*schema.Schema, packer packer.PackFunc,
182182
},
183183

184184
Schema: skeema,
185-
SchemaVersion: 2,
185+
SchemaVersion: 3,
186+
StateUpgraders: []schema.StateUpgrader{
187+
{
188+
// this only works because the schema hasn't changed, except the removal of default value
189+
// from `project_key` attribute.
190+
Type: resourceV2(skeema).CoreConfigSchema().ImpliedType(),
191+
Upgrade: repository.ResourceUpgradeProjectKey,
192+
Version: 2,
193+
},
194+
},
186195
CustomizeDiff: repository.ProjectEnvironmentsDiff,
187196
}
188197
}
198+
199+
func resourceV2(skeema map[string]*schema.Schema) *schema.Resource {
200+
return &schema.Resource{
201+
Schema: skeema,
202+
}
203+
}

pkg/artifactory/resource/repository/local/resource_artifactory_local_generic_repository.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import (
88
)
99

1010
func GetGenericRepoSchema(repoType string) map[string]*schema.Schema {
11-
return utilsdk.MergeMaps(BaseLocalRepoSchema, repository.RepoLayoutRefSchema("local", repoType))
11+
return utilsdk.MergeMaps(BaseLocalRepoSchema, repository.RepoLayoutRefSchema(rclass, repoType))
1212
}
1313

1414
func ResourceArtifactoryLocalGenericRepository(repoType string) *schema.Resource {
1515
constructor := func() (interface{}, error) {
1616
return &RepositoryBaseParams{
1717
PackageType: repoType,
18-
Rclass: "local",
18+
Rclass: rclass,
1919
}, nil
2020
}
2121

2222
unpack := func(data *schema.ResourceData) (interface{}, string, error) {
23-
repo := UnpackBaseRepo("local", data, repoType)
23+
repo := UnpackBaseRepo(rclass, data, repoType)
2424
return repo, repo.Id(), nil
2525
}
2626

pkg/artifactory/resource/repository/remote/remote.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ var resourceV1 = &schema.Resource{
555555
Schema: baseRemoteRepoSchemaV1,
556556
}
557557

558+
var resourceV2 = &schema.Resource{
559+
Schema: baseRemoteRepoSchemaV2,
560+
}
561+
558562
func mkResourceSchema(skeema map[string]*schema.Schema, packer packer.PackFunc, unpack unpacker.UnpackFunc, constructor repository.Constructor) *schema.Resource {
559563
var reader = repository.MkRepoRead(packer, constructor)
560564
return &schema.Resource{
@@ -572,10 +576,17 @@ func mkResourceSchema(skeema map[string]*schema.Schema, packer packer.PackFunc,
572576
Upgrade: ResourceStateUpgradeV1,
573577
Version: 1,
574578
},
579+
{
580+
// this only works because the schema hasn't changed, except the removal of default value
581+
// from `project_key` attribute.
582+
Type: resourceV2.CoreConfigSchema().ImpliedType(),
583+
Upgrade: repository.ResourceUpgradeProjectKey,
584+
Version: 2,
585+
},
575586
},
576587

577588
Schema: skeema,
578-
SchemaVersion: 2,
589+
SchemaVersion: 3,
579590
CustomizeDiff: customdiff.All(
580591
repository.ProjectEnvironmentsDiff,
581592
verifyExternalDependenciesDockerAndHelm,

pkg/artifactory/resource/repository/remote/resource_artifactory_remote_repository_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func TestAccRemoteUpgradeFromVersionWithNoDisableProxyAttr(t *testing.T) {
4747
Source: "registry.terraform.io/jfrog/artifactory",
4848
},
4949
},
50-
Config: config,
50+
Config: config,
51+
ExpectNonEmptyPlan: true,
5152
Check: resource.ComposeTestCheckFunc(
5253
resource.TestCheckResourceAttr(fqrn, "key", name),
5354
resource.TestCheckResourceAttr(fqrn, "repo_layout_ref", "go-default"),

pkg/artifactory/resource/repository/repository.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"github.com/jfrog/terraform-provider-shared/validator"
2323
)
2424

25-
const defaultProjectKey = "default"
26-
2725
var BaseRepoSchema = map[string]*schema.Schema{
2826
"key": {
2927
Type: schema.TypeString,
@@ -35,7 +33,6 @@ var BaseRepoSchema = map[string]*schema.Schema{
3533
"project_key": {
3634
Type: schema.TypeString,
3735
Optional: true,
38-
Default: "default",
3936
ValidateDiagFunc: validator.ProjectKey,
4037
Description: "Project key for assigning this repository to. Must be 2 - 20 lowercase alphanumeric and hyphen characters. When assigning repository to a project, repository key must be prefixed with project key, separated by a dash.",
4138
},
@@ -198,8 +195,8 @@ func MkRepoUpdate(unpack unpacker.UnpackFunc, read schema.ReadContextFunc) schem
198195
newProjectKey := newProject.(string)
199196
tflog.Debug(ctx, fmt.Sprintf("oldProjectKey: %v, newProjectKey: %v", oldProjectKey, newProjectKey))
200197

201-
assignToProject := oldProjectKey == defaultProjectKey && len(newProjectKey) > 0
202-
unassignFromProject := len(oldProjectKey) > 0 && newProjectKey == defaultProjectKey
198+
assignToProject := oldProjectKey == "" && len(newProjectKey) > 0
199+
unassignFromProject := len(oldProjectKey) > 0 && newProjectKey == ""
203200
tflog.Debug(ctx, fmt.Sprintf("assignToProject: %v, unassignFromProject: %v", assignToProject, unassignFromProject))
204201

205202
var err error
@@ -252,13 +249,6 @@ func Retry400(response *resty.Response, _ error) bool {
252249
return response.StatusCode() == http.StatusBadRequest
253250
}
254251

255-
func repoExists(d *schema.ResourceData, m interface{}) (bool, error) {
256-
_, err := CheckRepo(d.Id(), m.(utilsdk.ProvderMetadata).Client.R().AddRetryCondition(Retry400))
257-
return err == nil, err
258-
}
259-
260-
var repoTypeValidator = validation.StringInSlice(RepoTypesSupported, false)
261-
262252
var RepoKeyValidator = validation.All(
263253
validation.StringDoesNotMatch(regexp.MustCompile("^[0-9].*"), "repo key cannot start with a number"),
264254
validation.StringDoesNotContainAny(" !@#$%^&*()+={}[]:;<>,/?~`|\\"),
@@ -341,12 +331,12 @@ func ProjectEnvironmentsDiff(ctx context.Context, diff *schema.ResourceDiff, met
341331

342332
isSupported, err := utilsdk.CheckVersion(providerMetadata.ArtifactoryVersion, CustomProjectEnvironmentSupportedVersion)
343333
if err != nil {
344-
return fmt.Errorf("Failed to check version %s", err)
334+
return fmt.Errorf("failed to check version %s", err)
345335
}
346336

347337
if isSupported {
348338
if len(projectEnvironments) == 2 {
349-
return fmt.Errorf("For Artifactory %s or later, only one environment can be assigned to a repository.", CustomProjectEnvironmentSupportedVersion)
339+
return fmt.Errorf("for Artifactory %s or later, only one environment can be assigned to a repository", CustomProjectEnvironmentSupportedVersion)
350340
}
351341
} else { // Before 7.53.1
352342
projectEnvironments := data.(*schema.Set).List()
@@ -373,10 +363,35 @@ func MkResourceSchema(skeema map[string]*schema.Schema, packer packer.PackFunc,
373363
},
374364

375365
Schema: skeema,
366+
SchemaVersion: 1,
367+
StateUpgraders: []schema.StateUpgrader{
368+
{
369+
// this only works because the schema hasn't changed, except the removal of default value
370+
// from `project_key` attribute. Future common schema changes that involve attributes should
371+
// figure out a way to create a previous and new version.
372+
Type: resourceV0(skeema).CoreConfigSchema().ImpliedType(),
373+
Upgrade: ResourceUpgradeProjectKey,
374+
Version: 0,
375+
},
376+
},
376377
CustomizeDiff: ProjectEnvironmentsDiff,
377378
}
378379
}
379380

381+
func resourceV0(skeema map[string]*schema.Schema) *schema.Resource {
382+
return &schema.Resource{
383+
Schema: skeema,
384+
}
385+
}
386+
387+
func ResourceUpgradeProjectKey(ctx context.Context, rawState map[string]any, meta any) (map[string]any, error) {
388+
if rawState["project_key"] == "default" {
389+
rawState["project_key"] = ""
390+
}
391+
392+
return rawState, nil
393+
}
394+
380395
const RepositoriesEndpoint = "artifactory/api/repositories/{key}"
381396

382397
func CheckRepo(id string, request *resty.Request) (*resty.Response, error) {

0 commit comments

Comments
 (0)