From 324c0a237e244564f13225402f7469042451467b Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sat, 16 Jun 2018 13:07:08 +0400 Subject: [PATCH 1/6] add new resource aws_neptune_cluster_parameter_group --- aws/provider.go | 1 + ...rce_aws_neptune_cluster_parameter_group.go | 254 ++++++++++++++++++ aws/validators.go | 47 ++++ aws/validators_test.go | 88 ++++++ 4 files changed, 390 insertions(+) create mode 100644 aws/resource_aws_neptune_cluster_parameter_group.go diff --git a/aws/provider.go b/aws/provider.go index 1cdb7219dc8..a2940995f22 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -625,6 +625,7 @@ func Provider() terraform.ResourceProvider { "aws_batch_job_definition": resourceAwsBatchJobDefinition(), "aws_batch_job_queue": resourceAwsBatchJobQueue(), "aws_neptune_subnet_group": resourceAwsNeptuneSubnetGroup(), + "aws_neptune_cluster_parameter_group": resourceAwsNeptuneClusterParameterGroup(), // ALBs are actually LBs because they can be type `network` or `application` // To avoid regressions, we will add a new resource for each and they both point diff --git a/aws/resource_aws_neptune_cluster_parameter_group.go b/aws/resource_aws_neptune_cluster_parameter_group.go new file mode 100644 index 00000000000..b7a6e47984c --- /dev/null +++ b/aws/resource_aws_neptune_cluster_parameter_group.go @@ -0,0 +1,254 @@ +package aws + +import ( + "fmt" + "log" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/neptune" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" +) + +const neptuneClusterParameterGroupMaxParamsBulkEdit = 20 + +func resourceAwsNeptuneClusterParameterGroup() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsNeptuneClusterParameterGroupCreate, + Read: resourceAwsNeptuneClusterParameterGroupRead, + Update: resourceAwsNeptuneClusterParameterGroupUpdate, + Delete: resourceAwsNeptuneClusterParameterGroupDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"name_prefix"}, + ValidateFunc: validateNeptuneParamGroupName, + }, + "name_prefix": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: validateNeptuneParamGroupNamePrefix, + }, + "family": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: "Managed by Terraform", + }, + "parameter": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "value": { + Type: schema.TypeString, + Required: true, + }, + "apply_method": { + Type: schema.TypeString, + Optional: true, + Default: neptune.ApplyMethodPendingReboot, + ValidateFunc: validation.StringInSlice([]string{ + neptune.ApplyMethodImmediate, + neptune.ApplyMethodPendingReboot, + }, false), + }, + }, + }, + }, + + "tags": tagsSchema(), + }, + } +} + +func resourceAwsNeptuneClusterParameterGroupCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).neptuneconn + tags := tagsFromMapNeptune(d.Get("tags").(map[string]interface{})) + + var groupName string + if v, ok := d.GetOk("name"); ok { + groupName = v.(string) + } else if v, ok := d.GetOk("name_prefix"); ok { + groupName = resource.PrefixedUniqueId(v.(string)) + } else { + groupName = resource.UniqueId() + } + + createOpts := neptune.CreateDBClusterParameterGroupInput{ + DBClusterParameterGroupName: aws.String(groupName), + DBParameterGroupFamily: aws.String(d.Get("family").(string)), + Description: aws.String(d.Get("description").(string)), + Tags: tags, + } + + log.Printf("[DEBUG] Create Neptune Cluster Parameter Group: %#v", createOpts) + _, err := conn.CreateDBClusterParameterGroup(&createOpts) + if err != nil { + return fmt.Errorf("Error creating Neptune Cluster Parameter Group: %s", err) + } + + d.SetId(aws.StringValue(createOpts.DBClusterParameterGroupName)) + log.Printf("[INFO] Neptune Cluster Parameter Group ID: %s", d.Id()) + + return resourceAwsNeptuneClusterParameterGroupUpdate(d, meta) +} + +func resourceAwsNeptuneClusterParameterGroupRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).neptuneconn + + describeOpts := neptune.DescribeDBClusterParameterGroupsInput{ + DBClusterParameterGroupName: aws.String(d.Id()), + } + + describeResp, err := conn.DescribeDBClusterParameterGroups(&describeOpts) + if err != nil { + if isAWSErr(err, neptune.ErrCodeDBParameterGroupNotFoundFault, "") { + log.Printf("[WARN] Neptune Cluster Parameter Group (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil + } + + return err + } + + if len(describeResp.DBClusterParameterGroups) != 1 || + aws.StringValue(describeResp.DBClusterParameterGroups[0].DBClusterParameterGroupName) != d.Id() { + return fmt.Errorf("Unable to find Cluster Parameter Group: %#v", describeResp.DBClusterParameterGroups) + } + + d.Set("name", describeResp.DBClusterParameterGroups[0].DBClusterParameterGroupName) + d.Set("family", describeResp.DBClusterParameterGroups[0].DBParameterGroupFamily) + d.Set("description", describeResp.DBClusterParameterGroups[0].Description) + arn := aws.StringValue(describeResp.DBClusterParameterGroups[0].DBClusterParameterGroupArn) + d.Set("arn", arn) + + // Only include user customized parameters as there's hundreds of system/default ones + describeParametersOpts := neptune.DescribeDBClusterParametersInput{ + DBClusterParameterGroupName: aws.String(d.Id()), + Source: aws.String("user"), + } + + describeParametersResp, err := conn.DescribeDBClusterParameters(&describeParametersOpts) + if err != nil { + return err + } + + if err := d.Set("parameter", flattenNeptuneParameters(describeParametersResp.Parameters)); err != nil { + return fmt.Errorf("error setting neptune parameter: %s", err) + } + + resp, err := conn.ListTagsForResource(&neptune.ListTagsForResourceInput{ + ResourceName: aws.String(arn), + }) + if err != nil { + log.Printf("[DEBUG] Error retrieving tags for ARN: %s", arn) + } + + d.Set("tags", tagsToMapNeptune(resp.TagList)) + + return nil +} + +func resourceAwsNeptuneClusterParameterGroupUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).neptuneconn + + d.Partial(true) + + if d.HasChange("parameter") { + o, n := d.GetChange("parameter") + if o == nil { + o = new(schema.Set) + } + if n == nil { + n = new(schema.Set) + } + + os := o.(*schema.Set) + ns := n.(*schema.Set) + + parameters, err := expandNeptuneParameters(ns.Difference(os).List()) + if err != nil { + return err + } + + if len(parameters) > 0 { + // We can only modify 20 parameters at a time, so walk them until + // we've got them all. + for parameters != nil { + paramsToModify := make([]*neptune.Parameter, 0) + if len(parameters) <= neptuneClusterParameterGroupMaxParamsBulkEdit { + paramsToModify, parameters = parameters[:], nil + } else { + paramsToModify, parameters = parameters[:neptuneClusterParameterGroupMaxParamsBulkEdit], parameters[neptuneClusterParameterGroupMaxParamsBulkEdit:] + } + parameterGroupName := d.Get("name").(string) + modifyOpts := neptune.ModifyDBClusterParameterGroupInput{ + DBClusterParameterGroupName: aws.String(parameterGroupName), + Parameters: paramsToModify, + } + + log.Printf("[DEBUG] Modify Neptune Cluster Parameter Group: %s", modifyOpts) + _, err = conn.ModifyDBClusterParameterGroup(&modifyOpts) + if err != nil { + return fmt.Errorf("Error modifying Neptune Cluster Parameter Group: %s", err) + } + } + d.SetPartial("parameter") + } + } + + arn := d.Get("arn").(string) + if err := setTagsNeptune(conn, d, arn); err != nil { + return err + } else { + d.SetPartial("tags") + } + + d.Partial(false) + + return resourceAwsNeptuneClusterParameterGroupRead(d, meta) +} + +func resourceAwsNeptuneClusterParameterGroupDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).neptuneconn + + input := neptune.DeleteDBClusterParameterGroupInput{ + DBClusterParameterGroupName: aws.String(d.Id()), + } + + log.Printf("[DEBUG] Deleting Neptune Cluster Parameter Group: %s", d.Id()) + _, err := conn.DeleteDBClusterParameterGroup(&input) + if err != nil { + if isAWSErr(err, neptune.ErrCodeDBParameterGroupNotFoundFault, "") { + return nil + } + return fmt.Errorf("error deleting Neptune Cluster Parameter Group (%s): %s", d.Id(), err) + } + + return nil +} diff --git a/aws/validators.go b/aws/validators.go index 9d16431e3eb..2b1ebfe2955 100644 --- a/aws/validators.go +++ b/aws/validators.go @@ -1816,3 +1816,50 @@ func validateLaunchTemplateId(v interface{}, k string) (ws []string, errors []er } return } + +func validateNeptuneParamGroupName(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "only lowercase alphanumeric characters and hyphens allowed in %q", k)) + } + if !regexp.MustCompile(`^[a-z]`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "first character of %q must be a letter", k)) + } + if regexp.MustCompile(`--`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "%q cannot contain two consecutive hyphens", k)) + } + if regexp.MustCompile(`-$`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "%q cannot end with a hyphen", k)) + } + if len(value) > 255 { + errors = append(errors, fmt.Errorf( + "%q cannot be greater than 255 characters", k)) + } + return +} + +func validateNeptuneParamGroupNamePrefix(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "only lowercase alphanumeric characters and hyphens allowed in %q", k)) + } + if !regexp.MustCompile(`^[a-z]`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "first character of %q must be a letter", k)) + } + if regexp.MustCompile(`--`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "%q cannot contain two consecutive hyphens", k)) + } + prefixMaxLength := 255 - resource.UniqueIDSuffixLength + if len(value) > prefixMaxLength { + errors = append(errors, fmt.Errorf( + "%q cannot be greater than %d characters", k, prefixMaxLength)) + } + return +} diff --git a/aws/validators_test.go b/aws/validators_test.go index 5a10f44d1a5..95facbc73e4 100644 --- a/aws/validators_test.go +++ b/aws/validators_test.go @@ -2646,3 +2646,91 @@ func TestValidateLaunchTemplateId(t *testing.T) { } } } + +func TestValidateNeptuneParamGroupName(t *testing.T) { + cases := []struct { + Value string + ErrCount int + }{ + { + Value: "tEsting123", + ErrCount: 1, + }, + { + Value: "testing123!", + ErrCount: 1, + }, + { + Value: "1testing123", + ErrCount: 1, + }, + { + Value: "testing--123", + ErrCount: 1, + }, + { + Value: "testing_123", + ErrCount: 1, + }, + { + Value: "testing123-", + ErrCount: 1, + }, + { + Value: randomString(256), + ErrCount: 1, + }, + } + + for _, tc := range cases { + _, errors := validateNeptuneParamGroupName(tc.Value, "aws_neptune_cluster_parameter_group_name") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the Neptune Parameter Group Name to trigger a validation error") + } + } +} + +func TestValidateNeptuneParamGroupNamePrefix(t *testing.T) { + cases := []struct { + Value string + ErrCount int + }{ + { + Value: "tEsting123", + ErrCount: 1, + }, + { + Value: "testing123!", + ErrCount: 1, + }, + { + Value: "1testing123", + ErrCount: 1, + }, + { + Value: "testing--123", + ErrCount: 1, + }, + { + Value: "testing_123", + ErrCount: 1, + }, + { + Value: "testing123-", + ErrCount: 1, + }, + { + Value: randomString(256), + ErrCount: 1, + }, + } + + for _, tc := range cases { + _, errors := validateNeptuneParamGroupNamePrefix(tc.Value, "aws_neptune_cluster_parameter_group_name") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the Neptune Parameter Group Name to trigger a validation error") + } + } +} From eb7a3de792bb2a289e56a750651c48b04163238b Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sat, 16 Jun 2018 14:22:53 +0400 Subject: [PATCH 2/6] add acceptance test --- ...ws_neptune_cluster_parameter_group_test.go | 229 ++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 aws/resource_aws_neptune_cluster_parameter_group_test.go diff --git a/aws/resource_aws_neptune_cluster_parameter_group_test.go b/aws/resource_aws_neptune_cluster_parameter_group_test.go new file mode 100644 index 00000000000..8d96f30d993 --- /dev/null +++ b/aws/resource_aws_neptune_cluster_parameter_group_test.go @@ -0,0 +1,229 @@ +package aws + +import ( + "errors" + "fmt" + "regexp" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/neptune" + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAWSNeptuneClusterParameterGroup_basic(t *testing.T) { + var v neptune.DBClusterParameterGroup + + parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSNeptuneClusterParameterGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSNeptuneClusterParameterGroupConfig(parameterGroupName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSNeptuneClusterParameterGroupExists("aws_neptune_cluster_parameter_group.bar", &v), + testAccCheckAWSNeptuneClusterParameterGroupAttributes(&v, parameterGroupName), + resource.TestCheckResourceAttr( + "aws_neptune_cluster_parameter_group.bar", "name", parameterGroupName), + resource.TestCheckResourceAttr( + "aws_neptune_cluster_parameter_group.bar", "family", "neptune1"), + resource.TestCheckResourceAttr( + "aws_neptune_cluster_parameter_group.bar", "description", "Test cluster parameter group for terraform"), + resource.TestCheckResourceAttr("aws_neptune_cluster_parameter_group.bar", "parameter.#", "1"), + resource.TestCheckResourceAttr( + "aws_neptune_cluster_parameter_group.bar", "tags.%", "1"), + ), + }, + }, + }) +} + +func TestAccAWSNeptuneClusterParameterGroup_namePrefix(t *testing.T) { + var v neptune.DBClusterParameterGroup + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSNeptuneClusterParameterGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSNeptuneClusterParameterGroupConfig_namePrefix, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSNeptuneClusterParameterGroupExists("aws_neptune_cluster_parameter_group.test", &v), + resource.TestMatchResourceAttr( + "aws_neptune_cluster_parameter_group.test", "name", regexp.MustCompile("^tf-test-")), + ), + }, + }, + }) +} + +func TestAccAWSNeptuneClusterParameterGroup_generatedName(t *testing.T) { + var v neptune.DBClusterParameterGroup + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSNeptuneClusterParameterGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSNeptuneClusterParameterGroupConfig_generatedName, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSNeptuneClusterParameterGroupExists("aws_neptune_cluster_parameter_group.test", &v), + ), + }, + }, + }) +} + +func TestAccAWSNeptuneClusterParameterGroup_withoutParameter(t *testing.T) { + var v neptune.DBClusterParameterGroup + + parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-tf-%d", acctest.RandInt()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSNeptuneClusterParameterGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSNeptuneClusterParameterGroupOnlyConfig(parameterGroupName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSNeptuneClusterParameterGroupExists("aws_neptune_cluster_parameter_group.bar", &v), + testAccCheckAWSNeptuneClusterParameterGroupAttributes(&v, parameterGroupName), + resource.TestCheckResourceAttr( + "aws_neptune_cluster_parameter_group.bar", "name", parameterGroupName), + resource.TestCheckResourceAttr( + "aws_neptune_cluster_parameter_group.bar", "family", "neptune1"), + resource.TestCheckResourceAttr( + "aws_neptune_cluster_parameter_group.bar", "description", "Managed by Terraform"), + resource.TestCheckResourceAttr("aws_neptune_cluster_parameter_group.bar", "parameter.#", "0"), + ), + }, + }, + }) +} + +func testAccCheckAWSNeptuneClusterParameterGroupDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).neptuneconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_neptune_cluster_parameter_group" { + continue + } + + resp, err := conn.DescribeDBClusterParameterGroups( + &neptune.DescribeDBClusterParameterGroupsInput{ + DBClusterParameterGroupName: aws.String(rs.Primary.ID), + }) + + if err == nil { + if len(resp.DBClusterParameterGroups) != 0 && + aws.StringValue(resp.DBClusterParameterGroups[0].DBClusterParameterGroupName) == rs.Primary.ID { + return errors.New("Neptune Cluster Parameter Group still exists") + } + } + + if err != nil { + if isAWSErr(err, neptune.ErrCodeDBParameterGroupNotFoundFault, "") { + return nil + } + return err + } + } + + return nil +} + +func testAccCheckAWSNeptuneClusterParameterGroupAttributes(v *neptune.DBClusterParameterGroup, name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + + if *v.DBClusterParameterGroupName != name { + return fmt.Errorf("bad name: %#v expected: %v", *v.DBClusterParameterGroupName, name) + } + + if *v.DBParameterGroupFamily != "neptune1" { + return fmt.Errorf("bad family: %#v", *v.DBParameterGroupFamily) + } + + return nil + } +} + +func testAccCheckAWSNeptuneClusterParameterGroupExists(n string, v *neptune.DBClusterParameterGroup) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return errors.New("No Neptune Cluster Parameter Group ID is set") + } + + conn := testAccProvider.Meta().(*AWSClient).neptuneconn + + opts := neptune.DescribeDBClusterParameterGroupsInput{ + DBClusterParameterGroupName: aws.String(rs.Primary.ID), + } + + resp, err := conn.DescribeDBClusterParameterGroups(&opts) + + if err != nil { + return err + } + + if len(resp.DBClusterParameterGroups) != 1 || + aws.StringValue(resp.DBClusterParameterGroups[0].DBClusterParameterGroupName) != rs.Primary.ID { + return errors.New("Neptune Cluster Parameter Group not found") + } + + *v = *resp.DBClusterParameterGroups[0] + + return nil + } +} + +func testAccAWSNeptuneClusterParameterGroupConfig(name string) string { + return fmt.Sprintf(` +resource "aws_neptune_cluster_parameter_group" "bar" { + name = "%s" + family = "neptune1" + description = "Test cluster parameter group for terraform" + + parameter { + name = "neptune_enable_audit_log" + value = 1 + } + + tags { + foo = "bar" + } +} +`, name) +} + +func testAccAWSNeptuneClusterParameterGroupOnlyConfig(name string) string { + return fmt.Sprintf(`resource "aws_neptune_cluster_parameter_group" "bar" { + name = "%s" + family = "neptune1" + description = "Managed by Terraform" +}`, name) +} + +const testAccAWSNeptuneClusterParameterGroupConfig_namePrefix = ` +resource "aws_neptune_cluster_parameter_group" "test" { + name_prefix = "tf-test-" + family = "neptune1" +} +` +const testAccAWSNeptuneClusterParameterGroupConfig_generatedName = ` +resource "aws_neptune_cluster_parameter_group" "test" { + family = "neptune1" +} +` From 89924d04dcabddaa4e4458bbd5170de8d64abf30 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sat, 16 Jun 2018 14:39:20 +0400 Subject: [PATCH 3/6] add document for neptune_cluster_parameter_group --- ...tune_cluster_parameter_group.html.markdown | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 website/docs/r/neptune_cluster_parameter_group.html.markdown diff --git a/website/docs/r/neptune_cluster_parameter_group.html.markdown b/website/docs/r/neptune_cluster_parameter_group.html.markdown new file mode 100644 index 00000000000..1b4c36ac57c --- /dev/null +++ b/website/docs/r/neptune_cluster_parameter_group.html.markdown @@ -0,0 +1,59 @@ +--- +layout: "aws" +page_title: "AWS: aws_neptune_cluster_parameter_group" +sidebar_current: "docs-aws-resource-aws-neptune-cluster-parameter-group" +description: |- + Manages a Neptune Cluster Parameter Group +--- + +# aws_neptune_cluster_parameter_group + +Manages a Neptune Cluster Parameter Group + +## Example Usage + +```hcl +resource "aws_neptune_cluster_parameter_group" "example" { + family = "neptune1" + name = "example" + description = "neptune cluster parameter group" + + parameter { + name = "neptune_enable_audit_log" + value = 1 + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Optional, Forces new resource) The name of the neptune cluster parameter group. If omitted, Terraform will assign a random, unique name. +* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`. +* `family` - (Required) The family of the neptune cluster parameter group. +* `description` - (Optional) The description of the neptune cluster 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) Valid values are `immediate` and `pending-reboot`. Defaults to `pending-reboot`. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The neptune cluster parameter group name. +* `arn` - The ARN of the neptune cluster parameter group. + + +## Import + +Neptune Cluster Parameter Groups can be imported using the `name`, e.g. + +``` +$ terraform import aws_neptune_cluster_parameter_group.cluster_pg production-pg-1 +``` From ac4f6c011fc133b458d74ef00b7e4b9d821fb122 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sun, 17 Jun 2018 17:40:10 +0400 Subject: [PATCH 4/6] fix the issue in setting tags --- aws/resource_aws_neptune_cluster_parameter_group.go | 13 +++++++++++-- ...urce_aws_neptune_cluster_parameter_group_test.go | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_neptune_cluster_parameter_group.go b/aws/resource_aws_neptune_cluster_parameter_group.go index b7a6e47984c..b02c099cf49 100644 --- a/aws/resource_aws_neptune_cluster_parameter_group.go +++ b/aws/resource_aws_neptune_cluster_parameter_group.go @@ -5,6 +5,7 @@ import ( "log" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/neptune" "github.com/hashicorp/terraform/helper/resource" @@ -169,7 +170,9 @@ func resourceAwsNeptuneClusterParameterGroupRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Error retrieving tags for ARN: %s", arn) } - d.Set("tags", tagsToMapNeptune(resp.TagList)) + if err := d.Set("tags", tagsToMapNeptune(resp.TagList)); err != nil { + return fmt.Errorf("error setting neptune tags: %s", err) + } return nil } @@ -222,7 +225,13 @@ func resourceAwsNeptuneClusterParameterGroupUpdate(d *schema.ResourceData, meta } } - arn := d.Get("arn").(string) + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Service: "rds", + Region: meta.(*AWSClient).region, + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("cluster-pg:%s", d.Id()), + }.String() if err := setTagsNeptune(conn, d, arn); err != nil { return err } else { diff --git a/aws/resource_aws_neptune_cluster_parameter_group_test.go b/aws/resource_aws_neptune_cluster_parameter_group_test.go index 8d96f30d993..b057da37a9c 100644 --- a/aws/resource_aws_neptune_cluster_parameter_group_test.go +++ b/aws/resource_aws_neptune_cluster_parameter_group_test.go @@ -212,7 +212,6 @@ func testAccAWSNeptuneClusterParameterGroupOnlyConfig(name string) string { return fmt.Sprintf(`resource "aws_neptune_cluster_parameter_group" "bar" { name = "%s" family = "neptune1" - description = "Managed by Terraform" }`, name) } From 05c3a3cc1f709c845aa6013c0263830154c07883 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Mon, 18 Jun 2018 20:06:36 +0400 Subject: [PATCH 5/6] fix the unit testing --- aws/validators_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/aws/validators_test.go b/aws/validators_test.go index 95facbc73e4..94756c1b75e 100644 --- a/aws/validators_test.go +++ b/aws/validators_test.go @@ -2686,7 +2686,7 @@ func TestValidateNeptuneParamGroupName(t *testing.T) { _, errors := validateNeptuneParamGroupName(tc.Value, "aws_neptune_cluster_parameter_group_name") if len(errors) != tc.ErrCount { - t.Fatalf("Expected the Neptune Parameter Group Name to trigger a validation error") + t.Fatalf("Expected the Neptune Parameter Group Name to trigger a validation error for %q", tc.Value) } } } @@ -2716,10 +2716,6 @@ func TestValidateNeptuneParamGroupNamePrefix(t *testing.T) { Value: "testing_123", ErrCount: 1, }, - { - Value: "testing123-", - ErrCount: 1, - }, { Value: randomString(256), ErrCount: 1, @@ -2730,7 +2726,7 @@ func TestValidateNeptuneParamGroupNamePrefix(t *testing.T) { _, errors := validateNeptuneParamGroupNamePrefix(tc.Value, "aws_neptune_cluster_parameter_group_name") if len(errors) != tc.ErrCount { - t.Fatalf("Expected the Neptune Parameter Group Name to trigger a validation error") + t.Fatalf("Expected the Neptune Parameter Group Name to trigger a validation error for %q", tc.Value) } } } From 27641268ef8680cac3153b6a4fa3dca465e3e5c8 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Mon, 18 Jun 2018 21:09:36 +0400 Subject: [PATCH 6/6] corrections based on feedback --- ...rce_aws_neptune_cluster_parameter_group.go | 20 ++++++++----------- ...ws_neptune_cluster_parameter_group_test.go | 2 ++ website/aws.erb | 14 ++++--------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/aws/resource_aws_neptune_cluster_parameter_group.go b/aws/resource_aws_neptune_cluster_parameter_group.go index b02c099cf49..4e5932d91e2 100644 --- a/aws/resource_aws_neptune_cluster_parameter_group.go +++ b/aws/resource_aws_neptune_cluster_parameter_group.go @@ -5,7 +5,6 @@ import ( "log" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/neptune" "github.com/hashicorp/terraform/helper/resource" @@ -108,7 +107,7 @@ func resourceAwsNeptuneClusterParameterGroupCreate(d *schema.ResourceData, meta } log.Printf("[DEBUG] Create Neptune Cluster Parameter Group: %#v", createOpts) - _, err := conn.CreateDBClusterParameterGroup(&createOpts) + resp, err := conn.CreateDBClusterParameterGroup(&createOpts) if err != nil { return fmt.Errorf("Error creating Neptune Cluster Parameter Group: %s", err) } @@ -116,6 +115,8 @@ func resourceAwsNeptuneClusterParameterGroupCreate(d *schema.ResourceData, meta d.SetId(aws.StringValue(createOpts.DBClusterParameterGroupName)) log.Printf("[INFO] Neptune Cluster Parameter Group ID: %s", d.Id()) + d.Set("arn", resp.DBClusterParameterGroup.DBClusterParameterGroupArn) + return resourceAwsNeptuneClusterParameterGroupUpdate(d, meta) } @@ -137,9 +138,10 @@ func resourceAwsNeptuneClusterParameterGroupRead(d *schema.ResourceData, meta in return err } - if len(describeResp.DBClusterParameterGroups) != 1 || - aws.StringValue(describeResp.DBClusterParameterGroups[0].DBClusterParameterGroupName) != d.Id() { - return fmt.Errorf("Unable to find Cluster Parameter Group: %#v", describeResp.DBClusterParameterGroups) + if len(describeResp.DBClusterParameterGroups) == 0 { + log.Printf("[WARN] Neptune Cluster Parameter Group (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil } d.Set("name", describeResp.DBClusterParameterGroups[0].DBClusterParameterGroupName) @@ -225,13 +227,7 @@ func resourceAwsNeptuneClusterParameterGroupUpdate(d *schema.ResourceData, meta } } - arn := arn.ARN{ - Partition: meta.(*AWSClient).partition, - Service: "rds", - Region: meta.(*AWSClient).region, - AccountID: meta.(*AWSClient).accountid, - Resource: fmt.Sprintf("cluster-pg:%s", d.Id()), - }.String() + arn := d.Get("arn").(string) if err := setTagsNeptune(conn, d, arn); err != nil { return err } else { diff --git a/aws/resource_aws_neptune_cluster_parameter_group_test.go b/aws/resource_aws_neptune_cluster_parameter_group_test.go index b057da37a9c..83a0cf218e0 100644 --- a/aws/resource_aws_neptune_cluster_parameter_group_test.go +++ b/aws/resource_aws_neptune_cluster_parameter_group_test.go @@ -37,6 +37,8 @@ func TestAccAWSNeptuneClusterParameterGroup_basic(t *testing.T) { resource.TestCheckResourceAttr("aws_neptune_cluster_parameter_group.bar", "parameter.#", "1"), resource.TestCheckResourceAttr( "aws_neptune_cluster_parameter_group.bar", "tags.%", "1"), + resource.TestMatchResourceAttr( + "aws_neptune_cluster_parameter_group.bar", "arn", regexp.MustCompile(fmt.Sprintf("^arn:[^:]+:rds:[^:]+:\\d{12}:cluster-pg:%s", parameterGroupName))), ), }, }, diff --git a/website/aws.erb b/website/aws.erb index 0dbdf32b417..9a032003e55 100644 --- a/website/aws.erb +++ b/website/aws.erb @@ -1625,6 +1625,10 @@ aws_neptune_subnet_group + > + aws_neptune_cluster_parameter_group + + @@ -1647,16 +1651,6 @@ > aws_redshift_subnet_group - > - Neptune Resources - -