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

Read system parameters that exist in config #18486

Merged
merged 2 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/18486.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_docdb_cluster_parameter_group: Read all user parameters and parameters specified in the configuration.
```
3 changes: 1 addition & 2 deletions aws/resource_aws_docdb_cluster_parameter_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,14 @@ func resourceAwsDocDBClusterParameterGroupRead(d *schema.ResourceData, meta inte

describeParametersOpts := &docdb.DescribeDBClusterParametersInput{
DBClusterParameterGroupName: aws.String(d.Id()),
Source: aws.String("user"),
}

describeParametersResp, err := conn.DescribeDBClusterParameters(describeParametersOpts)
if err != nil {
return fmt.Errorf("error reading DocDB Cluster Parameter Group (%s) parameters: %s", d.Id(), err)
}

if err := d.Set("parameter", flattenDocDBParameters(describeParametersResp.Parameters)); err != nil {
if err := d.Set("parameter", flattenDocDBParameters(describeParametersResp.Parameters, d)); err != nil {
return fmt.Errorf("error setting docdb cluster parameter: %s", err)
}

Expand Down
44 changes: 44 additions & 0 deletions aws/resource_aws_docdb_cluster_parameter_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ func TestAccAWSDocDBClusterParameterGroup_basic(t *testing.T) {
})
}

func TestAccAWSDocDBClusterParameterGroup_systemParameter(t *testing.T) {
var v docdb.DBClusterParameterGroup
resourceName := "aws_docdb_cluster_parameter_group.bar"

parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, docdb.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDocDBClusterParameterGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDocDBClusterParameterGroupConfig_SystemParameter(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDocDBClusterParameterGroupExists(resourceName, &v),
testAccCheckAWSDocDBClusterParameterGroupAttributes(&v, parameterGroupName),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "rds", regexp.MustCompile(fmt.Sprintf("cluster-pg:%s$", parameterGroupName))),
resource.TestCheckResourceAttr(resourceName, "name", parameterGroupName),
resource.TestCheckResourceAttr(resourceName, "family", "docdb3.6"),
resource.TestCheckResourceAttr(resourceName, "description", "Managed by Terraform"),
resource.TestCheckResourceAttr(resourceName, "parameter.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
bill-rich marked this conversation as resolved.
Show resolved Hide resolved
},
})
}

func TestAccAWSDocDBClusterParameterGroup_namePrefix(t *testing.T) {
var v docdb.DBClusterParameterGroup

Expand Down Expand Up @@ -352,6 +381,21 @@ resource "aws_docdb_cluster_parameter_group" "bar" {
`, name)
}

func testAccAWSDocDBClusterParameterGroupConfig_SystemParameter(name string) string {
return fmt.Sprintf(`
resource "aws_docdb_cluster_parameter_group" "bar" {
family = "docdb3.6"
name = "%s"

parameter {
name = "tls"
value = "enabled"
apply_method = "pending-reboot"
}
}
`, name)
}

func testAccAWSDocDBClusterParameterGroupConfig_Description(name, description string) string {
return fmt.Sprintf(`
resource "aws_docdb_cluster_parameter_group" "bar" {
Expand Down
17 changes: 16 additions & 1 deletion aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,25 @@ func flattenNeptuneParameters(list []*neptune.Parameter) []map[string]interface{
}

// Flattens an array of Parameters into a []map[string]interface{}
func flattenDocDBParameters(list []*docdb.Parameter) []map[string]interface{} {
func flattenDocDBParameters(list []*docdb.Parameter, d *schema.ResourceData) []map[string]interface{} {
bill-rich marked this conversation as resolved.
Show resolved Hide resolved
result := make([]map[string]interface{}, 0, len(list))
for _, i := range list {
if i.ParameterValue != nil {
name := aws.StringValue(i.ParameterName)

// Check if any non-user parameters are specified in the configuration.
parameterFound := false
for _, configParameter := range d.Get("parameter").(*schema.Set).List() {
bill-rich marked this conversation as resolved.
Show resolved Hide resolved
if configParameter.(map[string]interface{})["name"] == name {
parameterFound = true
}
}

// Skip parameters that are not user defined or specified in the configuration.
if aws.StringValue(i.Source) != "user" && !parameterFound {
continue
}

result = append(result, map[string]interface{}{
"apply_method": aws.StringValue(i.ApplyMethod),
"name": aws.StringValue(i.ParameterName),
Expand Down