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

r/aws_neptune_parameter_group: Add name_prefix argument #34500

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/34500.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_neptune_parameter_group: Add name_prefix argument
```
26 changes: 18 additions & 8 deletions internal/service/neptune/parameter_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package neptune
import (
"context"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -17,6 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
Expand Down Expand Up @@ -45,12 +45,20 @@ func ResourceParameterGroup() *schema.Resource {
Computed: true,
},
"name": {
Type: schema.TypeString,
ForceNew: true,
Required: true,
StateFunc: func(val interface{}) string {
return strings.ToLower(val.(string))
},
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ConflictsWith: []string{"name_prefix"},
ValidateFunc: validParamGroupName,
},
"name_prefix": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ConflictsWith: []string{"name"},
ValidateFunc: validParamGroupNamePrefix,
},
"family": {
Type: schema.TypeString,
Expand Down Expand Up @@ -100,8 +108,9 @@ func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, m
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).NeptuneConn(ctx)

name := create.Name(d.Get("name").(string), d.Get("name_prefix").(string))
createOpts := neptune.CreateDBParameterGroupInput{
DBParameterGroupName: aws.String(d.Get("name").(string)),
DBParameterGroupName: aws.String(name),
DBParameterGroupFamily: aws.String(d.Get("family").(string)),
Description: aws.String(d.Get("description").(string)),
Tags: getTagsIn(ctx),
Expand Down Expand Up @@ -150,6 +159,7 @@ func resourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, met
arn := aws.StringValue(describeResp.DBParameterGroups[0].DBParameterGroupArn)
d.Set("arn", arn)
d.Set("name", describeResp.DBParameterGroups[0].DBParameterGroupName)
d.Set("name_prefix", create.NamePrefixFromName(aws.StringValue(describeResp.DBParameterGroups[0].DBParameterGroupName)))
d.Set("family", describeResp.DBParameterGroups[0].DBParameterGroupFamily)
d.Set("description", describeResp.DBParameterGroups[0].Description)

Expand Down
75 changes: 75 additions & 0 deletions internal/service/neptune/parameter_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/neptune"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand Down Expand Up @@ -40,6 +41,7 @@ func TestAccNeptuneParameterGroup_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "description", "Managed by Terraform"),
resource.TestCheckResourceAttr(resourceName, "family", "neptune1"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "name_prefix", ""),
resource.TestCheckResourceAttr(resourceName, "parameter.#", "0"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
Expand All @@ -53,6 +55,62 @@ func TestAccNeptuneParameterGroup_basic(t *testing.T) {
})
}

func TestAccNeptuneParameterGroup_nameGenerated(t *testing.T) {
ctx := acctest.Context(t)
var v neptune.DBParameterGroup
resourceName := "aws_neptune_parameter_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, neptune.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckParameterGroupDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccParameterGroupConfig_nameGenerated(),
Check: resource.ComposeTestCheckFunc(
testAccCheckParameterGroupExists(ctx, resourceName, &v),
acctest.CheckResourceAttrNameGenerated(resourceName, "name"),
resource.TestCheckResourceAttr(resourceName, "name_prefix", id.UniqueIdPrefix),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccNeptuneParameterGroup_namePrefix(t *testing.T) {
ctx := acctest.Context(t)
var v neptune.DBParameterGroup
resourceName := "aws_neptune_parameter_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, neptune.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckParameterGroupDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccParameterGroupConfig_namePrefix("tf-acc-test-prefix-"),
Check: resource.ComposeTestCheckFunc(
testAccCheckParameterGroupExists(ctx, resourceName, &v),
acctest.CheckResourceAttrNameFromPrefix(resourceName, "name", "tf-acc-test-prefix-"),
resource.TestCheckResourceAttr(resourceName, "name_prefix", "tf-acc-test-prefix-"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccNeptuneParameterGroup_description(t *testing.T) {
ctx := acctest.Context(t)
var v neptune.DBParameterGroup
Expand Down Expand Up @@ -270,6 +328,23 @@ resource "aws_neptune_parameter_group" "test" {
`, rName, pApplyMethod, pName, pValue)
}

func testAccParameterGroupConfig_nameGenerated() string {
return fmt.Sprintf(`
resource "aws_neptune_parameter_group" "test" {
family = "neptune1"
}
`)
}

func testAccParameterGroupConfig_namePrefix(namePrefix string) string {
return fmt.Sprintf(`
resource "aws_neptune_parameter_group" "test" {
family = "neptune1"
name_prefix = %[1]q
}
`, namePrefix)
}

func testAccParameterGroupConfig_description(rName, description string) string {
return fmt.Sprintf(`
resource "aws_neptune_parameter_group" "test" {
Expand Down