Skip to content

Commit 00e8110

Browse files
authored
Merge pull request #1123 from jfrog/GH-1120-fix-webhook-criteria-with-unkonwn-values
Check for attribute value being null or unknown before using it for validation
2 parents af010e9 + 2e63204 commit 00e8110

16 files changed

+138
-16
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 12.4.1 (November 11, 2024). Tested on Artifactory 7.98.8 with Terraform 1.9.8 and OpenTofu 1.8.5
2+
3+
BUG FIXES:
4+
5+
* resource/artifactory_build_webhook, resource/artifactory_release_bundle_webhook, resource/artifactory_release_bundle_v2_webhook, resource/artifactory_artifact_webhook, resource/artifactory_artifact_property_webhook, resource/artifactory_docker_webhook, resource/artifactory_build_custom_webhook, resource/artifactory_release_bundle_custom_webhook, resource/artifactory_release_bundle_v2_custom_webhook, resource/artifactory_artifact_custom_webhook, resource/artifactory_artifact_property_custom_webhook, resource/artifactory_docker_custom_webhook, resource/artifactory_ldap_group_setting_v2, resource/artifactory_repository_layout, resource/artifactory_release_bundle_v2, resource/artifactory_vault_configuration, resource/artifactory_user, resource/artifactory_managed_user, resource/artifactory_unmanaged_user: Fix attribute validation not working for unknown value (e.g. when resource is used in a module). Issue: [#1120](https://github.com/jfrog/terraform-provider-artifactory/issues/1120) PR: [#1123](https://github.com/jfrog/terraform-provider-artifactory/pull/1123)
6+
17
## 12.4.0 (November 4, 2024). Tested on Artifactory 7.98.7 with Terraform 1.9.8 and OpenTofu 1.8.5
28

39
IMPROVEMENTS:

pkg/artifactory/resource/configuration/resource_artifactory_ldap_group_setting_v2.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,16 @@ func (r *ArtifactoryLdapGroupSettingResource) ValidateConfig(ctx context.Context
358358
return
359359
}
360360

361+
if data.Strategy.IsNull() || data.Strategy.IsUnknown() {
362+
return
363+
}
364+
365+
if data.SubTree.IsNull() || data.SubTree.IsUnknown() {
366+
return
367+
}
368+
361369
// Validate strategy and sub_tree
362-
if !data.Strategy.IsNull() && strings.ToUpper(data.Strategy.ValueString()) == "HIERARCHICAL" && data.SubTree.ValueBool() {
370+
if strings.ToUpper(data.Strategy.ValueString()) == "HIERARCHICAL" && data.SubTree.ValueBool() {
363371
resp.Diagnostics.AddAttributeError(
364372
path.Root("sub_tree"),
365373
"Incorrect Attribute Configuration",

pkg/artifactory/resource/configuration/resource_artifactory_repository_layout.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,15 @@ func (r RepositoryLayoutResource) ValidateConfig(ctx context.Context, req resour
123123
return
124124
}
125125

126-
if data.DistinctiveDescriptorPathPattern.ValueBool() && len(data.DescriptorPathPattern.ValueString()) == 0 {
126+
if data.DistinctiveDescriptorPathPattern.IsNull() || data.DistinctiveDescriptorPathPattern.IsUnknown() {
127+
return
128+
}
129+
130+
if data.DescriptorPathPattern.IsUnknown() {
131+
return
132+
}
133+
134+
if data.DistinctiveDescriptorPathPattern.ValueBool() && (data.DescriptorPathPattern.IsNull() || len(data.DescriptorPathPattern.ValueString()) == 0) {
127135
resp.Diagnostics.AddAttributeError(
128136
path.Root("descriptor_path_pattern"),
129137
"Invalid attribute configuration",

pkg/artifactory/resource/lifecycle/resource_artifactory_release_bundle_v2.go

+8
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ func (r ReleaseBundleV2Resource) ValidateConfig(ctx context.Context, req resourc
439439
return
440440
}
441441

442+
if data.SourceType.IsNull() || data.SourceType.IsUnknown() {
443+
return
444+
}
445+
446+
if data.Source.IsNull() || data.Source.IsUnknown() {
447+
return
448+
}
449+
442450
sourceType := data.SourceType.ValueString()
443451
sourceAttrs := data.Source.Attributes()
444452

pkg/artifactory/resource/security/resource_artifactory_vault_configuration.go

+4
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ func (r VaultConfigurationResource) ValidateConfig(ctx context.Context, req reso
319319
return
320320
}
321321

322+
if data.Config.IsNull() || data.Config.IsUnknown() {
323+
return
324+
}
325+
322326
configAttrs := data.Config.Attributes()
323327
authAttrs := configAttrs["auth"].(types.Object).Attributes()
324328
authType := authAttrs["type"].(types.String)

pkg/artifactory/resource/user/user.go

+4
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ func (r *ArtifactoryBaseUserResource) validatePasswordByPolicy(plan ArtifactoryU
504504
return nil
505505
}
506506

507+
if plan.PasswordPolicy.IsUnknown() {
508+
return nil
509+
}
510+
507511
// Default password policy should match Access default configuration:
508512
// https://jfrog.com/help/r/jfrog-installation-setup-documentation/supported-access-configurations
509513
minLength := int64(8)

pkg/artifactory/resource/webhook/resource_artifactory_custom_webhook_build.go

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ func (m *BuildCustomWebhookResourceModel) fromAPIModel(ctx context.Context, apiM
188188
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
189189

190190
baseCriteriaAttrs, d := m.CustomWebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
191+
if d.HasError() {
192+
diags.Append(d...)
193+
}
191194

192195
criteriaSet, d := fromBuildAPIModel(ctx, criteriaAPIModel, baseCriteriaAttrs)
193196
if d.HasError() {

pkg/artifactory/resource/webhook/resource_artifactory_custom_webhook_release_bundle.go

+3
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ func (m *ReleaseBundleCustomWebhookResourceModel) fromAPIModel(ctx context.Conte
228228
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
229229

230230
baseCriteriaAttrs, d := m.CustomWebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
231+
if d.HasError() {
232+
diags.Append(d...)
233+
}
231234

232235
criteriaSet, d := fromReleaseBundleCriteriaAPIModel(ctx, criteriaAPIModel, baseCriteriaAttrs)
233236
if d.HasError() {

pkg/artifactory/resource/webhook/resource_artifactory_custom_webhook_release_bundle_v2.go

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ func (m *ReleaseBundleV2CustomWebhookResourceModel) fromAPIModel(ctx context.Con
188188
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
189189

190190
baseCriteriaAttrs, d := m.CustomWebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
191+
if d.HasError() {
192+
diags.Append(d...)
193+
}
191194

192195
criteriaSet, d := fromReleaseBundleV2APIModel(ctx, criteriaAPIModel, baseCriteriaAttrs)
193196

pkg/artifactory/resource/webhook/resource_artifactory_custom_webhook_release_bundle_v2_promotion.go

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ func (m *ReleaseBundleV2PromotionCustomWebhookResourceModel) fromAPIModel(ctx co
172172
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
173173

174174
baseCriteriaAttrs, d := m.CustomWebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
175+
if d.HasError() {
176+
diags.Append(d...)
177+
}
175178

176179
criteriaSet, d := fromReleaseBundleV2PromotionAPIModel(ctx, criteriaAPIModel, baseCriteriaAttrs)
177180
if d.HasError() {

pkg/artifactory/resource/webhook/resource_artifactory_custom_webhook_repo.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,23 @@ func (r RepoCustomWebhookResource) ValidateConfig(ctx context.Context, req resou
7878
return
7979
}
8080

81+
if data.Criteria.IsNull() || data.Criteria.IsUnknown() {
82+
return
83+
}
84+
8185
criteriaObj := data.Criteria.Elements()[0].(types.Object)
8286
criteriaAttrs := criteriaObj.Attributes()
8387

84-
anyLocal := criteriaAttrs["any_local"].(types.Bool).ValueBool()
85-
anyRemote := criteriaAttrs["any_remote"].(types.Bool).ValueBool()
86-
anyFederated := criteriaAttrs["any_federated"].(types.Bool).ValueBool()
88+
anyLocal := criteriaAttrs["any_local"].(types.Bool)
89+
anyRemote := criteriaAttrs["any_remote"].(types.Bool)
90+
anyFederated := criteriaAttrs["any_federated"].(types.Bool)
91+
repoKeys := criteriaAttrs["repo_keys"].(types.Set)
92+
93+
if anyLocal.IsUnknown() || anyRemote.IsUnknown() || anyFederated.IsUnknown() || repoKeys.IsUnknown() {
94+
return
95+
}
8796

88-
if (!anyLocal && !anyRemote && !anyFederated) && len(criteriaAttrs["repo_keys"].(types.Set).Elements()) == 0 {
97+
if (!anyLocal.ValueBool() && !anyRemote.ValueBool() && !anyFederated.ValueBool()) && len(repoKeys.Elements()) == 0 {
8998
resp.Diagnostics.AddAttributeError(
9099
path.Root("criteria").AtSetValue(criteriaObj).AtName("repo_keys"),
91100
"Invalid Attribute Configuration",
@@ -208,6 +217,9 @@ func (m RepoCustomWebhookResourceModel) toAPIModel(ctx context.Context, domain s
208217
}
209218

210219
criteriaAPIModel, d := toRepoCriteriaAPIModel(ctx, baseCriteria, criteriaAttrs)
220+
if d.HasError() {
221+
diags.Append(d...)
222+
}
211223

212224
d = m.CustomWebhookResourceModel.toAPIModel(ctx, domain, criteriaAPIModel, apiModel)
213225
if d.HasError() {
@@ -223,6 +235,9 @@ func (m *RepoCustomWebhookResourceModel) fromAPIModel(ctx context.Context, apiMo
223235
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
224236

225237
baseCriteriaAttrs, d := m.CustomWebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
238+
if d.HasError() {
239+
diags.Append(d...)
240+
}
226241

227242
criteriaSet, d := fromRepoCriteriaAPIMode(ctx, criteriaAPIModel, baseCriteriaAttrs)
228243
if d.HasError() {

pkg/artifactory/resource/webhook/resource_artifactory_webhook_build.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,22 @@ func (r *BuildWebhookResource) Configure(ctx context.Context, req resource.Confi
7474
}
7575

7676
func buildValidateConfig(criteria basetypes.SetValue, resp *resource.ValidateConfigResponse) {
77+
if criteria.IsNull() || criteria.IsUnknown() {
78+
return
79+
}
80+
7781
criteriaObj := criteria.Elements()[0].(types.Object)
7882
criteriaAttrs := criteriaObj.Attributes()
7983

80-
anyBuild := criteriaAttrs["any_build"].(types.Bool).ValueBool()
84+
anyBuild := criteriaAttrs["any_build"].(types.Bool)
85+
selectedBuilds := criteriaAttrs["selected_builds"].(types.Set)
86+
includePatterns := criteriaAttrs["include_patterns"].(types.Set)
87+
88+
if anyBuild.IsUnknown() || selectedBuilds.IsUnknown() || includePatterns.IsUnknown() {
89+
return
90+
}
8191

82-
if !anyBuild && len(criteriaAttrs["selected_builds"].(types.Set).Elements()) == 0 && len(criteriaAttrs["include_patterns"].(types.Set).Elements()) == 0 {
92+
if !anyBuild.ValueBool() && len(selectedBuilds.Elements()) == 0 && len(includePatterns.Elements()) == 0 {
8393
resp.Diagnostics.AddAttributeError(
8494
path.Root("criteria").AtSetValue(criteriaObj).AtName("any_build"),
8595
"Invalid Attribute Configuration",
@@ -281,6 +291,9 @@ func fromBuildAPIModel(ctx context.Context, criteriaAPIModel map[string]interfac
281291
buildCriteriaSetResourceModelElementTypes,
282292
[]attr.Value{criteria},
283293
)
294+
if d.HasError() {
295+
diags.Append(d...)
296+
}
284297

285298
return criteriaSet, diags
286299
}
@@ -291,6 +304,9 @@ func (m *BuildWebhookResourceModel) fromAPIModel(ctx context.Context, apiModel W
291304
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
292305

293306
baseCriteriaAttrs, d := m.WebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
307+
if d.HasError() {
308+
diags.Append(d...)
309+
}
294310

295311
criteriaSet, d := fromBuildAPIModel(ctx, criteriaAPIModel, baseCriteriaAttrs)
296312
if d.HasError() {

pkg/artifactory/resource/webhook/resource_artifactory_webhook_release_bundle.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,21 @@ func (r *ReleaseBundleWebhookResource) Configure(ctx context.Context, req resour
108108
}
109109

110110
func releaseBundleValidateConfig(criteria basetypes.SetValue, resp *resource.ValidateConfigResponse) {
111+
if criteria.IsNull() || criteria.IsUnknown() {
112+
return
113+
}
114+
111115
criteriaObj := criteria.Elements()[0].(types.Object)
112116
criteriaAttrs := criteriaObj.Attributes()
113117

114-
anyReleaseBundle := criteriaAttrs["any_release_bundle"].(types.Bool).ValueBool()
118+
anyReleaseBundle := criteriaAttrs["any_release_bundle"].(types.Bool)
119+
registeredReleaseBundleNames := criteriaAttrs["registered_release_bundle_names"].(types.Set)
115120

116-
if !anyReleaseBundle && len(criteriaAttrs["registered_release_bundle_names"].(types.Set).Elements()) == 0 {
121+
if anyReleaseBundle.IsUnknown() || registeredReleaseBundleNames.IsUnknown() {
122+
return
123+
}
124+
125+
if !anyReleaseBundle.ValueBool() && len(registeredReleaseBundleNames.Elements()) == 0 {
117126
resp.Diagnostics.AddAttributeError(
118127
path.Root("criteria").AtSetValue(criteriaObj).AtName("any_release_bundle"),
119128
"Invalid Attribute Configuration",
@@ -329,6 +338,9 @@ func (m *ReleaseBundleWebhookResourceModel) fromAPIModel(ctx context.Context, ap
329338
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
330339

331340
baseCriteriaAttrs, d := m.WebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
341+
if d.HasError() {
342+
diags.Append(d...)
343+
}
332344

333345
criteriaSet, d := fromReleaseBundleCriteriaAPIModel(ctx, criteriaAPIModel, baseCriteriaAttrs)
334346
if d.HasError() {

pkg/artifactory/resource/webhook/resource_artifactory_webhook_release_bundle_v2.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,21 @@ func (r *ReleaseBundleV2WebhookResource) Configure(ctx context.Context, req reso
7474
}
7575

7676
func releaseBundleV2ValidatConfig(criteria basetypes.SetValue, resp *resource.ValidateConfigResponse) {
77+
if criteria.IsNull() || criteria.IsUnknown() {
78+
return
79+
}
80+
7781
criteriaObj := criteria.Elements()[0].(types.Object)
7882
criteriaAttrs := criteriaObj.Attributes()
7983

80-
anyReleaseBundle := criteriaAttrs["any_release_bundle"].(types.Bool).ValueBool()
84+
anyReleaseBundle := criteriaAttrs["any_release_bundle"].(types.Bool)
85+
selectedReleaseBundles := criteriaAttrs["selected_release_bundles"].(types.Set)
86+
87+
if anyReleaseBundle.IsUnknown() || selectedReleaseBundles.IsUnknown() {
88+
return
89+
}
8190

82-
if !anyReleaseBundle && len(criteriaAttrs["selected_release_bundles"].(types.Set).Elements()) == 0 {
91+
if !anyReleaseBundle.ValueBool() && len(selectedReleaseBundles.Elements()) == 0 {
8392
resp.Diagnostics.AddAttributeError(
8493
path.Root("criteria").AtSetValue(criteriaObj).AtName("any_release_bundle"),
8594
"Invalid Attribute Configuration",
@@ -279,6 +288,9 @@ func fromReleaseBundleV2APIModel(ctx context.Context, criteriaAPIModel map[strin
279288
releaseBundleV2CriteriaSetResourceModelElementTypes,
280289
[]attr.Value{criteria},
281290
)
291+
if d.HasError() {
292+
diags.Append(d...)
293+
}
282294

283295
return
284296
}
@@ -289,6 +301,9 @@ func (m *ReleaseBundleV2WebhookResourceModel) fromAPIModel(ctx context.Context,
289301
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
290302

291303
baseCriteriaAttrs, d := m.WebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
304+
if d.HasError() {
305+
diags.Append(d...)
306+
}
292307

293308
criteriaSet, d := fromReleaseBundleV2APIModel(ctx, criteriaAPIModel, baseCriteriaAttrs)
294309
if d.HasError() {

pkg/artifactory/resource/webhook/resource_artifactory_webhook_release_bundle_v2_promotion.go

+3
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ func (m *ReleaseBundleV2PromotionWebhookResourceModel) fromAPIModel(ctx context.
256256
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
257257

258258
baseCriteriaAttrs, d := m.WebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
259+
if d.HasError() {
260+
diags.Append(d...)
261+
}
259262

260263
criteriaSet, d := fromReleaseBundleV2PromotionAPIModel(ctx, criteriaAPIModel, baseCriteriaAttrs)
261264
if d.HasError() {

pkg/artifactory/resource/webhook/resource_artifactory_webhook_repo.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,16 @@ func (r RepoWebhookResource) ValidateConfig(ctx context.Context, req resource.Va
112112
criteriaObj := data.Criteria.Elements()[0].(types.Object)
113113
criteriaAttrs := criteriaObj.Attributes()
114114

115-
anyLocal := criteriaAttrs["any_local"].(types.Bool).ValueBool()
116-
anyRemote := criteriaAttrs["any_remote"].(types.Bool).ValueBool()
117-
anyFederated := criteriaAttrs["any_federated"].(types.Bool).ValueBool()
115+
anyLocal := criteriaAttrs["any_local"].(types.Bool)
116+
anyRemote := criteriaAttrs["any_remote"].(types.Bool)
117+
anyFederated := criteriaAttrs["any_federated"].(types.Bool)
118+
repoKeys := criteriaAttrs["repo_keys"].(types.Set)
118119

119-
if (!anyLocal && !anyRemote && !anyFederated) && len(criteriaAttrs["repo_keys"].(types.Set).Elements()) == 0 {
120+
if anyLocal.IsUnknown() || anyRemote.IsUnknown() || anyFederated.IsUnknown() || repoKeys.IsUnknown() {
121+
return
122+
}
123+
124+
if (!anyLocal.ValueBool() && !anyRemote.ValueBool() && !anyFederated.ValueBool()) && len(repoKeys.Elements()) == 0 {
120125
resp.Diagnostics.AddAttributeError(
121126
path.Root("criteria").AtSetValue(criteriaObj).AtName("repo_keys"),
122127
"Invalid Attribute Configuration",
@@ -257,6 +262,9 @@ func (m RepoWebhookResourceModel) toAPIModel(ctx context.Context, domain string,
257262
}
258263

259264
criteriaAPIModel, d := toRepoCriteriaAPIModel(ctx, baseCriteria, criteriaAttrs)
265+
if d.HasError() {
266+
diags.Append(d...)
267+
}
260268

261269
d = m.WebhookResourceModel.toAPIModel(ctx, domain, criteriaAPIModel, apiModel)
262270
if d.HasError() {
@@ -323,6 +331,9 @@ func (m *RepoWebhookResourceModel) fromAPIModel(ctx context.Context, apiModel We
323331
criteriaAPIModel := apiModel.EventFilter.Criteria.(map[string]interface{})
324332

325333
baseCriteriaAttrs, d := m.WebhookResourceModel.fromBaseCriteriaAPIModel(ctx, criteriaAPIModel)
334+
if d.HasError() {
335+
diags.Append(d...)
336+
}
326337

327338
criteriaSet, d := fromRepoCriteriaAPIMode(ctx, criteriaAPIModel, baseCriteriaAttrs)
328339
if d.HasError() {

0 commit comments

Comments
 (0)