Skip to content

Commit

Permalink
Merge pull request #32160 from lawliet89/fis-target-parameters
Browse files Browse the repository at this point in the history
`r/aws_fis_experiment_template`: Add `parameters` to `target` blocks
  • Loading branch information
ewbankkit authored Jun 28, 2023
2 parents eb62ec0 + c1d2374 commit 5c5ab41
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/32160.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_fis_experiment_template: Add `parameters` attribute to the `target` configuration block
```
14 changes: 14 additions & 0 deletions internal/service/fis/experiment_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ func ResourceExperimentTemplate() *schema.Resource {
Required: true,
ValidateFunc: validation.StringLenBetween(0, 64),
},
"parameters": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"resource_arns": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -650,6 +655,10 @@ func expandExperimentTemplateTargets(l *schema.Set) (map[string]types.CreateExpe
config.SelectionMode = aws.String(v)
}

if v, ok := raw["parameters"].(map[string]interface{}); ok && len(v) > 0 {
config.Parameters = flex.ExpandStringValueMap(v)
}

if v, ok := raw["name"].(string); ok && v != "" {
attrs[v] = config
}
Expand Down Expand Up @@ -702,6 +711,10 @@ func expandExperimentTemplateTargetsForUpdate(l *schema.Set) (map[string]types.U
config.SelectionMode = aws.String(v)
}

if v, ok := raw["parameters"].(map[string]interface{}); ok && len(v) > 0 {
config.Parameters = flex.ExpandStringValueMap(v)
}

if v, ok := raw["name"].(string); ok && v != "" {
attrs[v] = config
}
Expand Down Expand Up @@ -852,6 +865,7 @@ func flattenExperimentTemplateTargets(configured map[string]types.ExperimentTemp
item["resource_tag"] = flattenExperimentTemplateTargetResourceTags(v.ResourceTags)
item["resource_type"] = aws.ToString(v.ResourceType)
item["selection_mode"] = aws.ToString(v.SelectionMode)
item["parameters"] = v.Parameters

item["name"] = k

Expand Down
106 changes: 106 additions & 0 deletions internal/service/fis/experiment_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,57 @@ func TestAccFISExperimentTemplate_ebs(t *testing.T) {
})
}

func TestAccFISExperimentTemplate_ebsParameters(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_fis_experiment_template.test"
var conf types.ExperimentTemplate

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, fis.ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckExperimentTemplateDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccExperimentTemplateConfig_ebsVolumeParameters(rName, "EBS Volume Pause I/O Experiment", "ebs-paused-io-action", "EBS Volume Pause I/O", "aws:ebs:pause-volume-io", "Volumes", "ebs-volume-to-pause-io", "duration", "PT6M", "aws:ec2:ebs-volume", "ALL", "env", "test"),
Check: resource.ComposeTestCheckFunc(
testAccExperimentTemplateExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "description", "EBS Volume Pause I/O Experiment"),
resource.TestCheckResourceAttrPair(resourceName, "role_arn", "aws_iam_role.test_fis", "arn"),
resource.TestCheckResourceAttr(resourceName, "stop_condition.0.source", "none"),
resource.TestCheckResourceAttr(resourceName, "stop_condition.0.value", ""),
resource.TestCheckResourceAttr(resourceName, "stop_condition.#", "1"),
resource.TestCheckResourceAttr(resourceName, "action.0.name", "ebs-paused-io-action"),
resource.TestCheckResourceAttr(resourceName, "action.0.description", "EBS Volume Pause I/O"),
resource.TestCheckResourceAttr(resourceName, "action.0.action_id", "aws:ebs:pause-volume-io"),
resource.TestCheckResourceAttr(resourceName, "action.0.parameter.#", "1"),
resource.TestCheckResourceAttr(resourceName, "action.0.parameter.0.key", "duration"),
resource.TestCheckResourceAttr(resourceName, "action.0.parameter.0.value", "PT6M"),
resource.TestCheckResourceAttr(resourceName, "action.0.start_after.#", "0"),
resource.TestCheckResourceAttr(resourceName, "action.0.target.0.key", "Volumes"),
resource.TestCheckResourceAttr(resourceName, "action.0.target.0.value", "ebs-volume-to-pause-io"),
resource.TestCheckResourceAttr(resourceName, "action.0.target.#", "1"),
resource.TestCheckResourceAttr(resourceName, "action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "target.0.name", "ebs-volume-to-pause-io"),
resource.TestCheckResourceAttr(resourceName, "target.0.resource_type", "aws:ec2:ebs-volume"),
resource.TestCheckResourceAttr(resourceName, "target.0.selection_mode", "ALL"),
resource.TestCheckResourceAttr(resourceName, "target.0.parameters.%", "1"),
resource.TestCheckResourceAttrPair(resourceName, "target.0.parameters.availabilityZoneIdentifier", "aws_ebs_volume.test", "availability_zone"),
resource.TestCheckResourceAttr(resourceName, "target.0.filter.#", "0"),
resource.TestCheckResourceAttr(resourceName, "target.0.resource_tag.#", "1"),
resource.TestCheckResourceAttr(resourceName, "target.0.resource_tag.0.key", "Name"),
resource.TestCheckResourceAttrPair(resourceName, "target.0.resource_tag.0.value", "aws_ebs_volume.test", "tags.Name"),
resource.TestCheckResourceAttr(resourceName, "target.#", "1"),
),
},
},
})
}

func TestAccFISExperimentTemplate_loggingConfiguration(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -747,6 +798,61 @@ resource "aws_fis_experiment_template" "test" {
`, rName+"-fis", desc, actionName, actionDesc, actionID, actionTargetK, actionTargetV, paramK1, paramV1, targetResType, targetSelectMode, targetResTagK, targetResTagV))
}

func testAccExperimentTemplateConfig_ebsVolumeParameters(rName, desc, actionName, actionDesc, actionID, actionTargetK, actionTargetV, paramK1, paramV1, targetResType, targetSelectMode, targetResTagK, targetResTagV string) string {
return acctest.ConfigCompose(testAccExperimentTemplateConfig_baseEBSVolume(rName), fmt.Sprintf(`
resource "aws_iam_role" "test_fis" {
name = %[1]q
assume_role_policy = jsonencode({
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = [
"fis.${data.aws_partition.current.dns_suffix}",
]
}
}]
Version = "2012-10-17"
})
}
resource "aws_fis_experiment_template" "test" {
description = %[2]q
role_arn = aws_iam_role.test_fis.arn
stop_condition {
source = "none"
}
action {
name = %[3]q
description = %[4]q
action_id = %[5]q
target {
key = %[6]q
value = %[7]q
}
parameter {
key = %[8]q
value = %[9]q
}
}
target {
name = %[7]q
resource_type = %[10]q
selection_mode = %[11]q
resource_tag {
key = "Name"
value = aws_ebs_volume.test.tags.Name
}
parameters = {
availabilityZoneIdentifier = aws_ebs_volume.test.availability_zone
}
}
tags = {
Name = %[1]q
}
}
`, rName+"-fis", desc, actionName, actionDesc, actionID, actionTargetK, actionTargetV, paramK1, paramV1, targetResType, targetSelectMode, targetResTagK, targetResTagV))
}

func testAccExperimentTemplateConfig_logConfigCloudWatch(rName, desc, actionName, actionDesc, actionID, actionTargetK, actionTargetV, targetResType, targetSelectMode, targetResTagK, targetResTagV string) string {
return fmt.Sprintf(`
data "aws_partition" "current" {}
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/fis_experiment_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ For a list of parameters supported by each action, see [AWS FIS actions referenc
* `filter` - (Optional) Filter(s) for the target. Filters can be used to select resources based on specific attributes returned by the respective describe action of the resource type. For more information, see [Targets for AWS FIS](https://docs.aws.amazon.com/fis/latest/userguide/targets.html#target-filters). See below.
* `resource_arns` - (Optional) Set of ARNs of the resources to target with an action. Conflicts with `resource_tag`.
* `resource_tag` - (Optional) Tag(s) the resources need to have to be considered a valid target for an action. Conflicts with `resource_arns`. See below.
* `parameters` - (Optional) The resource type parameters.

~> **NOTE:** The `target` configuration block requires either `resource_arns` or `resource_tag`.

Expand Down

0 comments on commit 5c5ab41

Please sign in to comment.