Skip to content

Commit

Permalink
Merge pull request #36740 from sbldevnet/f-aws_securityhub_configurat…
Browse files Browse the repository at this point in the history
…ion_policy-empty_standars

fix: add enabled_standard_arns if service_enabled is true in aws_securityhub_configuration_policy
  • Loading branch information
ewbankkit authored Apr 5, 2024
2 parents 0e40a5e + e6b7466 commit 4e72a2e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .changelog/36740.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_securityhub_configuration_policy: Mark `configuration_policy.enabled_standard_arns` as Optional, fixing `InvalidInputException: Invalid semantics: Enabled standards and security control configurations must be configured when Security Hub is enabled` errors
```
12 changes: 7 additions & 5 deletions internal/service/securityhub/configuration_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func resourceConfigurationPolicy() *schema.Resource {
Schema: map[string]*schema.Schema{
"enabled_standard_arns": {
Type: schema.TypeSet,
Required: true,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: verify.ValidARN,
Expand Down Expand Up @@ -432,12 +432,14 @@ func expandPolicyMemberSecurityHub(tfMap map[string]interface{}) *types.PolicyMe
SecurityControlsConfiguration: expandSecurityControlsConfiguration(tfMap["security_controls_configuration"]),
}

if v, ok := tfMap["enabled_standard_arns"].(*schema.Set); ok && v.Len() > 0 {
apiObject.EnabledStandardIdentifiers = flex.ExpandStringValueSet(v)
}

if v, ok := tfMap["service_enabled"].(bool); ok {
apiObject.ServiceEnabled = aws.Bool(v)

if v {
if v, ok := tfMap["enabled_standard_arns"].(*schema.Set); ok {
apiObject.EnabledStandardIdentifiers = flex.ExpandStringValueSet(v)
}
}
}

return &types.PolicyMemberSecurityHub{
Expand Down
3 changes: 1 addition & 2 deletions internal/service/securityhub/configuration_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ resource "aws_securityhub_configuration_policy" "test" {
description = %[2]q
configuration_policy {
service_enabled = false
enabled_standard_arns = []
service_enabled = false
}
depends_on = [aws_securityhub_organization_configuration.test]
Expand Down
5 changes: 2 additions & 3 deletions website/docs/r/securityhub_configuration_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ resource "aws_securityhub_configuration_policy" "disabled" {
description = "This is an example of disabled configuration policy"
configuration_policy {
service_enabled = false
enabled_standard_arns = []
service_enabled = false
}
depends_on = [aws_securityhub_organization_configuration.example]
Expand Down Expand Up @@ -130,7 +129,7 @@ This resource supports the following arguments:

The `configuration_policy` block supports the following:

* `enabled_standard_arns` - (Required) A list that defines which security standards are enabled in the configuration policy.
* `enabled_standard_arns` - (Optional) A list that defines which security standards are enabled in the configuration policy. It must be defined if `service_enabled` is set to true.
* `security_controls_configuration` - (Optional) Defines which security controls are enabled in the configuration policy and any customizations to parameters affecting them. See [below](#security_controls_configuration).
* `service_enabled` - (Required) Indicates whether Security Hub is enabled in the policy.

Expand Down

0 comments on commit 4e72a2e

Please sign in to comment.