-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add data source aws_db_parameter_group
- Loading branch information
Showing
4 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/rds" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" | ||
) | ||
|
||
func dataSourceAwsDbParameterGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsDbParameterGroupRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"family": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tagsSchemaComputed(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) error { | ||
rdsconn := meta.(*AWSClient).rdsconn | ||
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig | ||
|
||
groupName := d.Get("name").(string) | ||
|
||
describeOpts := rds.DescribeDBParameterGroupsInput{ | ||
DBParameterGroupName: aws.String(groupName), | ||
} | ||
|
||
describeResp, err := rdsconn.DescribeDBParameterGroups(&describeOpts) | ||
if err != nil { | ||
return fmt.Errorf("Error getting DB Parameter Groups: %v", err) | ||
} | ||
|
||
if len(describeResp.DBParameterGroups) != 1 || | ||
*describeResp.DBParameterGroups[0].DBParameterGroupName != groupName { | ||
return fmt.Errorf("Unable to find Parameter Group: %#v", describeResp.DBParameterGroups) | ||
} | ||
|
||
d.SetId(aws.StringValue(describeResp.DBParameterGroups[0].DBParameterGroupName)) | ||
d.Set("name", describeResp.DBParameterGroups[0].DBParameterGroupName) | ||
d.Set("arn", describeResp.DBParameterGroups[0].DBParameterGroupArn) | ||
d.Set("family", describeResp.DBParameterGroups[0].DBParameterGroupFamily) | ||
d.Set("description", describeResp.DBParameterGroups[0].Description) | ||
|
||
tags, err := keyvaluetags.RdsListTags(rdsconn, d.Get("arn").(string)) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error listing tags for RDS DB Parameter Group (%s): %s", d.Get("arn").(string), err) | ||
} | ||
|
||
if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { | ||
return fmt.Errorf("error setting tags: %s", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccAWSDbParameterGroupDataSource_basic(t *testing.T) { | ||
datasourceName := "data.aws_db_parameter_group.test" | ||
resourceName := "aws_db_parameter_group.test" | ||
rInt := acctest.RandInt() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAwsDbParameterGroupDataSourceConfig_nonExistent, | ||
ExpectError: regexp.MustCompile(`Error getting DB Parameter Groups`), | ||
}, | ||
{ | ||
Config: testAccAwsDbParameterGroupDataSourceConfig_basic(rInt), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "family", resourceName, "family"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "description", resourceName, "description"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccAwsDbParameterGroupDataSourceConfig_nonExistent = ` | ||
data "aws_db_parameter_group" "test" { | ||
name = "tf-acc-test-does-not-exist" | ||
} | ||
` | ||
|
||
func testAccAwsDbParameterGroupDataSourceConfig_basic(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "aws_db_parameter_group" "test" { | ||
name = "tf-acc-test-%d" | ||
family = "postgres12" | ||
parameter { | ||
name = "client_encoding" | ||
value = "UTF8" | ||
apply_method = "pending-reboot" | ||
} | ||
} | ||
data "aws_db_parameter_group" "test" { | ||
name = aws_db_parameter_group.test.name | ||
} | ||
`, rInt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
subcategory: "RDS" | ||
layout: "aws" | ||
page_title: "AWS: aws_db_parameter_group" | ||
description: |- | ||
Provides details about an RDS Database Parameter Group. | ||
--- | ||
|
||
# Data Source: aws_backup_vault | ||
|
||
Use this data source to get information on an existing database parameter group. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_db_parameter_group" "example" { | ||
name = "name-of-parameter" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the database parameter group. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `arn` - The ARN of the DB parameter group. | ||
* `family` - The name of the DB parameter group family that this DB parameter is compatible with. | ||
* `description` - The customer specified description for the DB parameter group. | ||
* `tags` - Metadata that you can assign to help organize the resources that you create. |