Skip to content

Commit

Permalink
resource/aws_neptune_parameter_group: Address #4724 PR feedback and e…
Browse files Browse the repository at this point in the history
…nsure acceptance testing is per attribute

make testacc TEST=./aws TESTARGS='-run=TestAccAWSNeptuneParameterGroup'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSNeptuneParameterGroup -timeout 120m
=== RUN   TestAccAWSNeptuneParameterGroup_basic
--- PASS: TestAccAWSNeptuneParameterGroup_basic (14.14s)
=== RUN   TestAccAWSNeptuneParameterGroup_Description
--- PASS: TestAccAWSNeptuneParameterGroup_Description (14.47s)
=== RUN   TestAccAWSNeptuneParameterGroup_Parameter
--- PASS: TestAccAWSNeptuneParameterGroup_Parameter (25.46s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	54.107s
  • Loading branch information
bflad committed Jun 13, 2018
1 parent 8a4a508 commit 20a5e29
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 123 deletions.
28 changes: 6 additions & 22 deletions aws/resource_aws_neptune_parameter_group.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package aws

import (
"bytes"
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/neptune"
Expand Down Expand Up @@ -64,19 +63,14 @@ func resourceAwsNeptuneParameterGroup() *schema.Resource {
"apply_method": {
Type: schema.TypeString,
Optional: true,
Default: "immediate",
// this parameter is not actually state, but a
// meta-parameter describing how the RDS API call
// to modify the parameter group should be made.
// Future reads of the resource from AWS don't tell
// us what we used for apply_method previously, so
// by squashing state to an empty string we avoid
// needing to do an update for every future run.
StateFunc: func(interface{}) string { return "" },
Default: neptune.ApplyMethodPendingReboot,
ValidateFunc: validation.StringInSlice([]string{
neptune.ApplyMethodImmediate,
neptune.ApplyMethodPendingReboot,
}, false),
},
},
},
Set: resourceAwsNeptuneParameterHash,
},
},
}
Expand Down Expand Up @@ -268,13 +262,3 @@ func resourceAwsNeptuneParameterGroupDelete(d *schema.ResourceData, meta interfa
return nil
})
}

func resourceAwsNeptuneParameterHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))
// Store the value as a lower case string, to match how we store them in flattenParameters
buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(m["value"].(string))))

return hashcode.String(buf.String())
}
153 changes: 76 additions & 77 deletions aws/resource_aws_neptune_parameter_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/neptune"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
Expand All @@ -14,103 +14,99 @@ import (

func TestAccAWSNeptuneParameterGroup_basic(t *testing.T) {
var v neptune.DBParameterGroup
rName := fmt.Sprintf("parameter-group-test-terraform-%d", acctest.RandInt())
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_neptune_parameter_group.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSNeptuneParameterGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSNeptuneParameterGroupConfig(rName),
{
Config: testAccAWSNeptuneParameterGroupConfig_Required(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSNeptuneParameterGroupExists("aws_neptune_parameter_group.bar", &v),
testAccCheckAWSNeptuneParameterGroupExists(resourceName, &v),
testAccCheckAWSNeptuneParameterGroupAttributes(&v, rName),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "name", rName),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "family", "neptune1"),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "description", "Managed by Terraform"),
resource.TestCheckResourceAttr("aws_neptune_parameter_group.bar", "parameter.#", "1"),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "parameter.562386247.name", "neptune_query_timeout"),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "parameter.562386247.value", "25"),
resource.TestCheckResourceAttr(resourceName, "description", "Managed by Terraform"),
resource.TestCheckResourceAttr(resourceName, "family", "neptune1"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "parameter.#", "0"),
),
},
resource.TestStep{
ResourceName: "aws_neptune_parameter_group.bar",
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSNeptuneParameterGroup_only(t *testing.T) {
func TestAccAWSNeptuneParameterGroup_Description(t *testing.T) {
var v neptune.DBParameterGroup
rName := fmt.Sprintf("parameter-group-test-terraform-%d", acctest.RandInt())
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_neptune_parameter_group.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSNeptuneParameterGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSNeptuneParameterGroupOnlyConfig(rName),
{
Config: testAccAWSNeptuneParameterGroupConfig_Description(rName, "description1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSNeptuneParameterGroupExists("aws_neptune_parameter_group.bar", &v),
testAccCheckAWSNeptuneParameterGroupExists(resourceName, &v),
testAccCheckAWSNeptuneParameterGroupAttributes(&v, rName),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "name", rName),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "family", "neptune1"),
resource.TestCheckResourceAttr(resourceName, "description", "description1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

// Regression for https://github.com/terraform-providers/terraform-provider-aws/issues/116
func TestAccAWSNeptuneParameterGroup_removeParam(t *testing.T) {
func TestAccAWSNeptuneParameterGroup_Parameter(t *testing.T) {
var v neptune.DBParameterGroup
rName := fmt.Sprintf("parameter-group-test-terraform-%d", acctest.RandInt())
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_neptune_parameter_group.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSNeptuneParameterGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSNeptuneParameterGroupConfig(rName),
Config: testAccAWSNeptuneParameterGroupConfig_Parameter(rName, "neptune_query_timeout", "25", "pending-reboot"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSNeptuneParameterGroupExists("aws_neptune_parameter_group.bar", &v),
testAccCheckAWSNeptuneParameterGroupExists(resourceName, &v),
testAccCheckAWSNeptuneParameterGroupAttributes(&v, rName),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "name", rName),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "family", "neptune1"),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "parameter.562386247.name", "neptune_query_timeout"),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "parameter.562386247.value", "25"),
resource.TestCheckResourceAttr(resourceName, "parameter.#", "1"),
resource.TestCheckResourceAttr(resourceName, "parameter.2423897584.apply_method", "pending-reboot"),
resource.TestCheckResourceAttr(resourceName, "parameter.2423897584.name", "neptune_query_timeout"),
resource.TestCheckResourceAttr(resourceName, "parameter.2423897584.value", "25"),
),
},
{
Config: testAccAWSNeptuneParameterGroupOnlyConfig(rName),
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
// This test should be updated with a dynamic parameter when available
{
Config: testAccAWSNeptuneParameterGroupConfig_Parameter(rName, "neptune_query_timeout", "25", "immediate"),
ExpectError: regexp.MustCompile(`cannot use immediate apply method for static parameter`),
},
// Test removing the configuration
{
Config: testAccAWSNeptuneParameterGroupConfig_Required(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSNeptuneParameterGroupExists("aws_neptune_parameter_group.bar", &v),
testAccCheckAWSNeptuneParameterGroupExists(resourceName, &v),
testAccCheckAWSNeptuneParameterGroupAttributes(&v, rName),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "name", rName),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "family", "neptune1"),

resource.TestCheckNoResourceAttr(
"aws_neptune_parameter_group.bar", "parameter.562386247.name"),
resource.TestCheckNoResourceAttr(
"aws_neptune_parameter_group.bar", "parameter.562386247.value"),
resource.TestCheckResourceAttr(resourceName, "parameter.#", "0"),
),
},
},
Expand All @@ -131,20 +127,15 @@ func testAccCheckAWSNeptuneParameterGroupDestroy(s *terraform.State) error {
DBParameterGroupName: aws.String(rs.Primary.ID),
})

if err == nil {
if len(resp.DBParameterGroups) != 0 &&
*resp.DBParameterGroups[0].DBParameterGroupName == rs.Primary.ID {
return fmt.Errorf("DB Parameter Group still exists")
if err != nil {
if isAWSErr(err, neptune.ErrCodeDBParameterGroupNotFoundFault, "") {
return nil
}
}

// Verify the error
newerr, ok := err.(awserr.Error)
if !ok {
return err
}
if newerr.Code() != "DBParameterGroupNotFound" {
return err

if len(resp.DBParameterGroups) != 0 && aws.StringValue(resp.DBParameterGroups[0].DBParameterGroupName) == rs.Primary.ID {
return fmt.Errorf("DB Parameter Group still exists")
}
}

Expand Down Expand Up @@ -200,25 +191,33 @@ func testAccCheckAWSNeptuneParameterGroupExists(n string, v *neptune.DBParameter
}
}

func testAccAWSNeptuneParameterGroupConfig(rName string) string {
func testAccAWSNeptuneParameterGroupConfig_Parameter(rName, pName, pValue, pApplyMethod string) string {
return fmt.Sprintf(`
resource "aws_neptune_parameter_group" "bar" {
name = "%s"
family = "neptune1"
parameter {
name = "neptune_query_timeout"
value = "25"
apply_method = "pending-reboot"
resource "aws_neptune_parameter_group" "test" {
family = "neptune1"
name = "%s"
parameter {
apply_method = "%s"
name = "%s"
value = "%s"
}
}`, rName, pApplyMethod, pName, pValue)
}

}
}`, rName)
func testAccAWSNeptuneParameterGroupConfig_Description(rName, description string) string {
return fmt.Sprintf(`
resource "aws_neptune_parameter_group" "test" {
description = "%s"
family = "neptune1"
name = "%s"
}`, description, rName)
}

func testAccAWSNeptuneParameterGroupOnlyConfig(rName string) string {
func testAccAWSNeptuneParameterGroupConfig_Required(rName string) string {
return fmt.Sprintf(`
resource "aws_neptune_parameter_group" "bar" {
name = "%s"
family = "neptune1"
description = "Test parameter group for terraform"
resource "aws_neptune_parameter_group" "test" {
family = "neptune1"
name = "%s"
}`, rName)
}
4 changes: 2 additions & 2 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,9 @@ func flattenNeptuneParameters(list []*neptune.Parameter) []map[string]interface{
for _, i := range list {
if i.ParameterValue != nil {
result = append(result, map[string]interface{}{
"name": strings.ToLower(aws.StringValue(i.ParameterName)),
"apply_method": aws.StringValue(i.ApplyMethod),
"name": aws.StringValue(i.ParameterName),
"value": aws.StringValue(i.ParameterValue),
"apply_method": strings.ToLower(aws.StringValue(i.ParameterName)),
})
}
}
Expand Down
35 changes: 13 additions & 22 deletions website/docs/r/neptune_parameter_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,24 @@ layout: "aws"
page_title: "AWS: aws_neptune_parameter_group"
sidebar_current: "docs-aws-resource-aws-neptune-parameter-group"
description: |-
Provides an Neptune parameter group resource.
Manages a Neptune Parameter Group
---

# aws_neptune_parameter_group

Creates a parameter group for AWS Neptune
Manages a Neptune Parameter Group

## Example Usage

```hcl
resource "aws_neptune_parameter_group" "bar" {
name = "my_group"
family = "neptune1"
description = "Test parameter group for terraform"
}
```

```hcl
resource "aws_neptune_parameter_group" "bar" {
name = "my_group"
family = "neptune1"
description = "Test parameter group for terraform"
parameter {
name = "neptune_query_timeout"
apply_method = "pending-reboot"
value = "25"
}
resource "aws_neptune_parameter_group" "example" {
family = "neptune1"
name = "example"
parameter {
name = "neptune_query_timeout"
value = "25"
}
}
```

Expand All @@ -41,23 +32,23 @@ The following arguments are supported:
* `family` - (Required) The family of the Neptune parameter group.
* `description` - (Optional) The description of the Neptune parameter group. Defaults to "Managed by Terraform".
* `parameter` - (Optional) A list of Neptune parameters to apply.
* `tags` - (Optional) A mapping of tags to assign to the resource.

Parameter blocks support the following:

* `name` - (Required) The name of the Neptune parameter.
* `value` - (Required) The value of the Neptune parameter.
* `apply_method` - (Optional) The apply method of the Neptune parameter. Valid values are `immediate` and `pending-reboot`. Defaults to `pending-reboot`.


## Attributes Reference

The following attributes are exported:

* `id` - The dbNeptune parameter group name.
* `id` - The Neptune parameter group name.

## Import

Neptune Parameter groups can be imported using the `name`, e.g.
Neptune Parameter Groups can be imported using the `name`, e.g.

```
$ terraform import aws_neptune_parameter_group.some_pg some-pg
Expand Down

0 comments on commit 20a5e29

Please sign in to comment.