8
8
"fmt"
9
9
"testing"
10
10
11
+ "github.com/aws/aws-sdk-go/aws/endpoints"
11
12
"github.com/aws/aws-sdk-go/service/securityhub"
12
13
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
13
14
"github.com/hashicorp/terraform-plugin-testing/terraform"
@@ -20,6 +21,10 @@ import (
20
21
func testAccAccount_basic (t * testing.T ) {
21
22
ctx := acctest .Context (t )
22
23
resourceName := "aws_securityhub_account.test"
24
+ controlFindingGeneratorDefaultValueFromAWS := "SECURITY_CONTROL"
25
+ if acctest .Partition () == endpoints .AwsUsGovPartitionID {
26
+ controlFindingGeneratorDefaultValueFromAWS = ""
27
+ }
23
28
24
29
resource .Test (t , resource.TestCase {
25
30
PreCheck : func () { acctest .PreCheck (ctx , t ) },
@@ -32,7 +37,7 @@ func testAccAccount_basic(t *testing.T) {
32
37
Check : resource .ComposeTestCheckFunc (
33
38
testAccCheckAccountExists (ctx , resourceName ),
34
39
resource .TestCheckResourceAttr (resourceName , "enable_default_standards" , "true" ),
35
- resource .TestCheckResourceAttr (resourceName , "control_finding_generator" , "SECURITY_CONTROL" ),
40
+ resource .TestCheckResourceAttr (resourceName , "control_finding_generator" , controlFindingGeneratorDefaultValueFromAWS ),
36
41
resource .TestCheckResourceAttr (resourceName , "auto_enable_controls" , "true" ),
37
42
),
38
43
},
@@ -94,27 +99,26 @@ func testAccAccount_full(t *testing.T) {
94
99
resourceName := "aws_securityhub_account.test"
95
100
96
101
resource .Test (t , resource.TestCase {
97
- PreCheck : func () { acctest .PreCheck (ctx , t ) },
102
+ // control_finding_generator not supported in AWS GovCloud.
103
+ PreCheck : func () { acctest .PreCheck (ctx , t ); acctest .PreCheckPartitionNot (t , endpoints .AwsUsGovPartitionID ) },
98
104
ErrorCheck : acctest .ErrorCheck (t , securityhub .EndpointsID ),
99
105
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
100
106
CheckDestroy : testAccCheckAccountDestroy (ctx ),
101
107
Steps : []resource.TestStep {
102
108
{
103
- Config : testAccAccountConfig_basic ,
109
+ Config : testAccAccountConfig_full ( false , "STANDARD_CONTROL" ) ,
104
110
Check : resource .ComposeTestCheckFunc (
105
111
testAccCheckAccountExists (ctx , resourceName ),
106
- resource .TestCheckResourceAttr (resourceName , "enable_default_standards" , "true" ),
107
- resource .TestCheckResourceAttr (resourceName , "control_finding_generator" , "SECURITY_CONTROL" ),
108
- resource .TestCheckResourceAttr (resourceName , "auto_enable_controls" , "true" ),
112
+ resource .TestCheckResourceAttr (resourceName , "auto_enable_controls" , "false" ),
113
+ resource .TestCheckResourceAttr (resourceName , "control_finding_generator" , "STANDARD_CONTROL" ),
109
114
),
110
115
},
111
116
{
112
- Config : testAccAccountConfig_full ,
117
+ Config : testAccAccountConfig_full ( true , "SECURITY_CONTROL" ) ,
113
118
Check : resource .ComposeTestCheckFunc (
114
119
testAccCheckAccountExists (ctx , resourceName ),
115
- resource .TestCheckResourceAttr (resourceName , "enable_default_standards" , "false" ),
116
- resource .TestCheckResourceAttr (resourceName , "control_finding_generator" , "STANDARD_CONTROL" ),
117
- resource .TestCheckResourceAttr (resourceName , "auto_enable_controls" , "false" ),
120
+ resource .TestCheckResourceAttr (resourceName , "auto_enable_controls" , "true" ),
121
+ resource .TestCheckResourceAttr (resourceName , "control_finding_generator" , "SECURITY_CONTROL" ),
118
122
),
119
123
},
120
124
},
@@ -152,6 +156,46 @@ func testAccAccount_migrateV0(t *testing.T) {
152
156
})
153
157
}
154
158
159
+ // https://github.com/hashicorp/terraform-provider-aws/issues/33039 et al.
160
+ func testAccAccount_removeControlFindingGeneratorDefaultValue (t * testing.T ) {
161
+ ctx := acctest .Context (t )
162
+ resourceName := "aws_securityhub_account.test"
163
+ controlFindingGeneratorExpectedValue := "SECURITY_CONTROL"
164
+ if acctest .Partition () == endpoints .AwsUsGovPartitionID {
165
+ controlFindingGeneratorExpectedValue = ""
166
+ }
167
+ expectNonEmptyPlan := acctest .Partition () == endpoints .AwsUsGovPartitionID
168
+
169
+ resource .Test (t , resource.TestCase {
170
+ PreCheck : func () { acctest .PreCheck (ctx , t ) },
171
+ ErrorCheck : acctest .ErrorCheck (t , securityhub .EndpointsID ),
172
+ CheckDestroy : testAccCheckAccountDestroy (ctx ),
173
+ Steps : []resource.TestStep {
174
+ {
175
+ ExternalProviders : map [string ]resource.ExternalProvider {
176
+ "aws" : {
177
+ Source : "hashicorp/aws" ,
178
+ VersionConstraint : "5.13.0" ,
179
+ },
180
+ },
181
+ Config : testAccAccountConfig_basic ,
182
+ Check : resource .ComposeTestCheckFunc (
183
+ testAccCheckAccountExists (ctx , resourceName ),
184
+ resource .TestCheckResourceAttr (resourceName , "enable_default_standards" , "true" ),
185
+ resource .TestCheckResourceAttr (resourceName , "control_finding_generator" , controlFindingGeneratorExpectedValue ),
186
+ resource .TestCheckResourceAttr (resourceName , "auto_enable_controls" , "true" ),
187
+ ),
188
+ ExpectNonEmptyPlan : expectNonEmptyPlan ,
189
+ },
190
+ {
191
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
192
+ Config : testAccAccountConfig_basic ,
193
+ PlanOnly : true ,
194
+ },
195
+ },
196
+ })
197
+ }
198
+
155
199
func testAccCheckAccountExists (ctx context.Context , n string ) resource.TestCheckFunc {
156
200
return func (s * terraform.State ) error {
157
201
rs , ok := s .RootModule ().Resources [n ]
@@ -207,10 +251,11 @@ resource "aws_securityhub_account" "test" {
207
251
}
208
252
`
209
253
210
- const testAccAccountConfig_full = `
254
+ func testAccAccountConfig_full (autoEnableControls bool , controlFindingGenerator string ) string {
255
+ return fmt .Sprintf (`
211
256
resource "aws_securityhub_account" "test" {
212
- enable_default_standards = false
213
- control_finding_generator = "STANDARD_CONTROL"
214
- auto_enable_controls = false
257
+ control_finding_generator = %[2]q
258
+ auto_enable_controls = %[1]t
259
+ }
260
+ ` , autoEnableControls , controlFindingGenerator )
215
261
}
216
- `
0 commit comments