|
9 | 9 | "testing" |
10 | 10 |
|
11 | 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 12 | + "github.com/hashicorp/terraform-plugin-testing/plancheck" |
12 | 13 | "github.com/hashicorp/terraform-plugin-testing/terraform" |
13 | 14 | "github.com/hashicorp/terraform-provider-aws/internal/acctest" |
14 | 15 | "github.com/hashicorp/terraform-provider-aws/internal/conns" |
@@ -93,6 +94,55 @@ func testAccDetectorFeature_additionalConfiguration(t *testing.T) { |
93 | 94 | }) |
94 | 95 | } |
95 | 96 |
|
| 97 | +func testAccDetectorFeature_additionalConfigurationOrder(t *testing.T) { |
| 98 | + ctx := acctest.Context(t) |
| 99 | + resourceName := "aws_guardduty_detector_feature.test" |
| 100 | + |
| 101 | + resource.Test(t, resource.TestCase{ |
| 102 | + PreCheck: func() { |
| 103 | + acctest.PreCheck(ctx, t) |
| 104 | + testAccPreCheckDetectorNotExists(ctx, t) |
| 105 | + }, |
| 106 | + ErrorCheck: acctest.ErrorCheck(t, names.GuardDutyServiceID), |
| 107 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, |
| 108 | + CheckDestroy: acctest.CheckDestroyNoop, |
| 109 | + Steps: []resource.TestStep{ |
| 110 | + { |
| 111 | + Config: testAccDetectorFeatureConfig_additionalConfiguration_multiple([]string{"EKS_ADDON_MANAGEMENT", "EC2_AGENT_MANAGEMENT", "ECS_FARGATE_AGENT_MANAGEMENT"}), |
| 112 | + Check: resource.ComposeTestCheckFunc( |
| 113 | + testAccCheckDetectorFeatureExists(ctx, resourceName), |
| 114 | + resource.TestCheckResourceAttr(resourceName, "additional_configuration.#", "3"), |
| 115 | + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "additional_configuration.*", |
| 116 | + map[string]string{"name": "EKS_ADDON_MANAGEMENT", "status": "ENABLED"}), |
| 117 | + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "additional_configuration.*", |
| 118 | + map[string]string{"name": "EC2_AGENT_MANAGEMENT", "status": "ENABLED"}), |
| 119 | + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "additional_configuration.*", |
| 120 | + map[string]string{"name": "ECS_FARGATE_AGENT_MANAGEMENT", "status": "ENABLED"}), |
| 121 | + ), |
| 122 | + }, |
| 123 | + { |
| 124 | + // Change the order of the additional_configuration blocks and ensure that there is an empty plan |
| 125 | + Config: testAccDetectorFeatureConfig_additionalConfiguration_multiple([]string{"EC2_AGENT_MANAGEMENT", "ECS_FARGATE_AGENT_MANAGEMENT", "EKS_ADDON_MANAGEMENT"}), |
| 126 | + ConfigPlanChecks: resource.ConfigPlanChecks{ |
| 127 | + PreApply: []plancheck.PlanCheck{ |
| 128 | + plancheck.ExpectEmptyPlan(), |
| 129 | + }, |
| 130 | + }, |
| 131 | + Check: resource.ComposeTestCheckFunc( |
| 132 | + testAccCheckDetectorFeatureExists(ctx, resourceName), |
| 133 | + resource.TestCheckResourceAttr(resourceName, "additional_configuration.#", "3"), |
| 134 | + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "additional_configuration.*", |
| 135 | + map[string]string{"name": "EKS_ADDON_MANAGEMENT", "status": "ENABLED"}), |
| 136 | + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "additional_configuration.*", |
| 137 | + map[string]string{"name": "EC2_AGENT_MANAGEMENT", "status": "ENABLED"}), |
| 138 | + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "additional_configuration.*", |
| 139 | + map[string]string{"name": "ECS_FARGATE_AGENT_MANAGEMENT", "status": "ENABLED"}), |
| 140 | + ), |
| 141 | + }, |
| 142 | + }, |
| 143 | + }) |
| 144 | +} |
| 145 | + |
96 | 146 | func testAccDetectorFeature_multiple(t *testing.T) { |
97 | 147 | ctx := acctest.Context(t) |
98 | 148 | resource1Name := "aws_guardduty_detector_feature.test1" |
@@ -211,6 +261,35 @@ resource "aws_guardduty_detector_feature" "test" { |
211 | 261 | `, featureStatus, additionalConfigurationStatus) |
212 | 262 | } |
213 | 263 |
|
| 264 | +func testAccDetectorFeatureConfig_additionalConfiguration_multiple(configNames []string) string { |
| 265 | + return fmt.Sprintf(` |
| 266 | +resource "aws_guardduty_detector" "test" { |
| 267 | + enable = true |
| 268 | +} |
| 269 | +
|
| 270 | +resource "aws_guardduty_detector_feature" "test" { |
| 271 | + detector_id = aws_guardduty_detector.test.id |
| 272 | + name = "RUNTIME_MONITORING" |
| 273 | + status = "ENABLED" |
| 274 | +
|
| 275 | + additional_configuration { |
| 276 | + name = %[1]q |
| 277 | + status = "ENABLED" |
| 278 | + } |
| 279 | +
|
| 280 | + additional_configuration { |
| 281 | + name = %[2]q |
| 282 | + status = "ENABLED" |
| 283 | + } |
| 284 | +
|
| 285 | + additional_configuration { |
| 286 | + name = %[3]q |
| 287 | + status = "ENABLED" |
| 288 | + } |
| 289 | +} |
| 290 | +`, configNames[0], configNames[1], configNames[2]) |
| 291 | +} |
| 292 | + |
214 | 293 | func testAccDetectorFeatureConfig_multiple(status1, status2, status3 string) string { |
215 | 294 | return fmt.Sprintf(` |
216 | 295 | resource "aws_guardduty_detector" "test" { |
|
0 commit comments