Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f/aws_ssm_parameters_by_path: Add support for recursive parameter retrieval #22222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/22222.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
data-source/aws_ssm_parameters_by_path: Add `recursive` argument
```
6 changes: 6 additions & 0 deletions internal/service/ssm/parameters_by_path_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func DataSourceParametersByPath() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"recursive": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"types": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -54,6 +59,7 @@ func dataSourceParametersReadByPath(d *schema.ResourceData, meta interface{}) er
path := d.Get("path").(string)
input := &ssm.GetParametersByPathInput{
Path: aws.String(path),
Recursive: aws.Bool(d.Get("recursive").(bool)),
WithDecryption: aws.Bool(d.Get("with_decryption").(bool)),
}

Expand Down
50 changes: 50 additions & 0 deletions internal/service/ssm/parameters_by_path_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccSSMParametersByPathDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "types.#", "2"),
resource.TestCheckResourceAttr(resourceName, "values.#", "2"),
resource.TestCheckResourceAttr(resourceName, "with_decryption", "false"),
resource.TestCheckResourceAttr(resourceName, "recursive", "false"),
),
},
},
Expand Down Expand Up @@ -66,3 +67,52 @@ data "aws_ssm_parameters_by_path" "test" {
}
`, rName1, rName2, withDecryption)
}

func TestAccSSMParametersByPathDataSource_withRecursion(t *testing.T) {
resourceName := "data.aws_ssm_parameters_by_path.recursive"
pathPrefix := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, ssm.EndpointsID),
Providers: acctest.Providers,
Steps: []resource.TestStep{
{
Config: testAccCheckParametersByPathDataSourceConfigWithRecursion(pathPrefix),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "arns.#", "2"),
resource.TestCheckResourceAttr(resourceName, "names.#", "2"),
resource.TestCheckResourceAttr(resourceName, "types.#", "2"),
resource.TestCheckResourceAttr(resourceName, "values.#", "2"),
resource.TestCheckResourceAttr(resourceName, "recursive", "true"),
),
},
},
})
}

func testAccCheckParametersByPathDataSourceConfigWithRecursion(pathPrefix string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "top_level" {
name = "/%[1]s/top_param"
type = "String"
value = "TestValueA"
}

resource "aws_ssm_parameter" "nested" {
name = "/%[1]s/nested/param"
type = "String"
value = "TestValueB"
}

data "aws_ssm_parameters_by_path" "recursive" {
path = "/%[1]s/"
recursive = true

depends_on = [
aws_ssm_parameter.top_level,
aws_ssm_parameter.nested,
]
}
`, pathPrefix)
}
2 changes: 1 addition & 1 deletion website/docs/d/ssm_parameters_by_path.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The following arguments are supported:

* `path` - (Required) The prefix path of the parameter.
* `with_decryption` - (Optional) Whether to return decrypted `SecureString` value. Defaults to `true`.

* `recursive` - (Optional) Whether to recursively return parameters under `path`. Defaults to `false`.

In addition to all arguments above, the following attributes are exported:

Expand Down