Skip to content

Commit

Permalink
Merge pull request #34985 from sagitsofan/f-aws_neptune_storage_type
Browse files Browse the repository at this point in the history
Neptune - support new storage type
  • Loading branch information
ewbankkit authored Jan 11, 2024
2 parents 1919fbe + 28ee0aa commit fb291b3
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 65 deletions.
7 changes: 7 additions & 0 deletions .changelog/34985.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_neptune_cluster: Add `storage_type` argument
```

```release-note:enhancement
resource/aws_neptune_cluster_instance: Add `storage_type` attribute
```
94 changes: 60 additions & 34 deletions internal/service/neptune/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,20 @@ func ResourceCluster() *schema.Resource {
ForceNew: true,
Default: false,
},
"storage_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
// https://docs.aws.amazon.com/neptune/latest/userguide/storage-types.html#provisioned-iops-storage:
// "You can determine whether a cluster is using I/O–Optimized storage using any describe- call. If the I/O–Optimized storage is enabled, the call returns a storage-type field set to iopt1".
if old == "" && new == storageTypeStandard {
return true
}
return new == old
},
ValidateFunc: validation.StringInSlice(storageType_Values(), false),
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"vpc_security_group_ids": {
Expand Down Expand Up @@ -363,12 +377,6 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
}
}

if v, ok := d.GetOk("global_cluster_identifier"); ok {
v := v.(string)

inputC.GlobalClusterIdentifier = aws.String(v)
}

if v, ok := d.GetOk("enable_cloudwatch_logs_exports"); ok && v.(*schema.Set).Len() > 0 {
v := v.(*schema.Set)

Expand All @@ -383,6 +391,12 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
inputR.EngineVersion = aws.String(v)
}

if v, ok := d.GetOk("global_cluster_identifier"); ok {
v := v.(string)

inputC.GlobalClusterIdentifier = aws.String(v)
}

if v, ok := d.GetOk("iam_database_authentication_enabled"); ok {
v := v.(bool)

Expand Down Expand Up @@ -432,6 +446,13 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
inputC.ReplicationSourceIdentifier = aws.String(v)
}

if v, ok := d.GetOk("storage_type"); ok {
v := v.(string)

inputC.StorageType = aws.String(v)
inputR.StorageType = aws.String(v)
}

if v, ok := d.GetOk("vpc_security_group_ids"); ok && v.(*schema.Set).Len() > 0 {
v := v.(*schema.Set)

Expand Down Expand Up @@ -549,6 +570,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter
return sdkdiag.AppendErrorf(diags, "setting serverless_v2_scaling_configuration: %s", err)
}
d.Set("storage_encrypted", dbc.StorageEncrypted)
d.Set("storage_type", dbc.StorageType)
var securityGroupIDs []string
for _, v := range dbc.VpcSecurityGroups {
securityGroupIDs = append(securityGroupIDs, aws.StringValue(v.VpcSecurityGroupId))
Expand All @@ -570,23 +592,16 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int
DBClusterIdentifier: aws.String(d.Id()),
}

if d.HasChange("copy_tags_to_snapshot") {
input.CopyTagsToSnapshot = aws.Bool(d.Get("copy_tags_to_snapshot").(bool))
if d.HasChange("backup_retention_period") {
input.BackupRetentionPeriod = aws.Int64(int64(d.Get("backup_retention_period").(int)))
}

// The DBInstanceParameterGroupName parameter is only valid in combination with the AllowMajorVersionUpgrade parameter.
if allowMajorVersionUpgrade {
if v, ok := d.GetOk("neptune_instance_parameter_group_name"); ok {
input.DBInstanceParameterGroupName = aws.String(v.(string))
}
if d.HasChange("copy_tags_to_snapshot") {
input.CopyTagsToSnapshot = aws.Bool(d.Get("copy_tags_to_snapshot").(bool))
}

if d.HasChange("vpc_security_group_ids") {
if v := d.Get("vpc_security_group_ids").(*schema.Set); v.Len() > 0 {
input.VpcSecurityGroupIds = flex.ExpandStringSet(v)
} else {
input.VpcSecurityGroupIds = aws.StringSlice([]string{})
}
if d.HasChange("deletion_protection") {
input.DeletionProtection = aws.Bool(d.Get("deletion_protection").(bool))
}

if d.HasChange("enable_cloudwatch_logs_exports") {
Expand All @@ -609,39 +624,50 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int
input.CloudwatchLogsExportConfiguration = logs
}

if d.HasChange("preferred_backup_window") {
input.PreferredBackupWindow = aws.String(d.Get("preferred_backup_window").(string))
}

if d.HasChange("preferred_maintenance_window") {
input.PreferredMaintenanceWindow = aws.String(d.Get("preferred_maintenance_window").(string))
if d.HasChange("engine_version") {
input.EngineVersion = aws.String(d.Get("engine_version").(string))
input.DBClusterParameterGroupName = aws.String(d.Get("neptune_cluster_parameter_group_name").(string))
}

if d.HasChange("backup_retention_period") {
input.BackupRetentionPeriod = aws.Int64(int64(d.Get("backup_retention_period").(int)))
if d.HasChange("iam_database_authentication_enabled") {
input.EnableIAMDatabaseAuthentication = aws.Bool(d.Get("iam_database_authentication_enabled").(bool))
}

if d.HasChange("neptune_cluster_parameter_group_name") {
input.DBClusterParameterGroupName = aws.String(d.Get("neptune_cluster_parameter_group_name").(string))
}

if d.HasChange("iam_database_authentication_enabled") {
input.EnableIAMDatabaseAuthentication = aws.Bool(d.Get("iam_database_authentication_enabled").(bool))
// The DBInstanceParameterGroupName parameter is only valid in combination with the AllowMajorVersionUpgrade parameter.
if allowMajorVersionUpgrade {
if v, ok := d.GetOk("neptune_instance_parameter_group_name"); ok {
input.DBInstanceParameterGroupName = aws.String(v.(string))
}
}

if d.HasChange("deletion_protection") {
input.DeletionProtection = aws.Bool(d.Get("deletion_protection").(bool))
if d.HasChange("preferred_backup_window") {
input.PreferredBackupWindow = aws.String(d.Get("preferred_backup_window").(string))
}

if d.HasChange("engine_version") {
input.EngineVersion = aws.String(d.Get("engine_version").(string))
input.DBClusterParameterGroupName = aws.String(d.Get("neptune_cluster_parameter_group_name").(string))
if d.HasChange("preferred_maintenance_window") {
input.PreferredMaintenanceWindow = aws.String(d.Get("preferred_maintenance_window").(string))
}

if d.HasChange("serverless_v2_scaling_configuration") {
input.ServerlessV2ScalingConfiguration = expandServerlessConfiguration(d.Get("serverless_v2_scaling_configuration").([]interface{}))
}

if d.HasChange("storage_type") {
input.StorageType = aws.String(d.Get("storage_type").(string))
}

if d.HasChange("vpc_security_group_ids") {
if v := d.Get("vpc_security_group_ids").(*schema.Set); v.Len() > 0 {
input.VpcSecurityGroupIds = flex.ExpandStringSet(v)
} else {
input.VpcSecurityGroupIds = aws.StringSlice([]string{})
}
}

_, err := tfresource.RetryWhen(ctx, 5*time.Minute,
func() (interface{}, error) {
return conn.ModifyDBClusterWithContext(ctx, input)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/neptune/cluster_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ resource "aws_neptune_cluster" "test" {
cluster_identifier = %[1]q
availability_zones = local.availability_zone_names
engine = "neptune"
neptune_cluster_parameter_group_name = "default.neptune1.2"
neptune_cluster_parameter_group_name = "default.neptune1.3"
skip_final_snapshot = true
}
`, rName))
Expand Down
5 changes: 5 additions & 0 deletions internal/service/neptune/cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func ResourceClusterInstance() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"storage_type": {
Type: schema.TypeString,
Computed: true,
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"writer": {
Expand Down Expand Up @@ -282,6 +286,7 @@ func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, me
d.Set("promotion_tier", db.PromotionTier)
d.Set("publicly_accessible", db.PubliclyAccessible)
d.Set("storage_encrypted", db.StorageEncrypted)
d.Set("storage_type", db.StorageType)

if db.Endpoint != nil {
address := aws.StringValue(db.Endpoint.Address)
Expand Down
9 changes: 5 additions & 4 deletions internal/service/neptune/cluster_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestAccNeptuneClusterInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "promotion_tier", "3"),
resource.TestCheckResourceAttr(resourceName, "publicly_accessible", "false"),
resource.TestCheckResourceAttr(resourceName, "storage_encrypted", "false"),
resource.TestCheckResourceAttr(resourceName, "storage_type", "standard"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "writer", "true"),
),
Expand Down Expand Up @@ -352,7 +353,7 @@ data "aws_neptune_orderable_db_instance" "test" {
resource "aws_neptune_parameter_group" "test" {
name = %[1]q
family = "neptune1.2"
family = "neptune1.3"
parameter {
name = "neptune_query_timeout"
Expand All @@ -368,7 +369,7 @@ resource "aws_neptune_cluster" "test" {
cluster_identifier = %[1]q
availability_zones = slice(data.aws_availability_zones.available.names, 0, min(3, length(data.aws_availability_zones.available.names)))
engine = "neptune"
neptune_cluster_parameter_group_name = "default.neptune1.2"
neptune_cluster_parameter_group_name = "default.neptune1.3"
skip_final_snapshot = true
}
`, rName))
Expand Down Expand Up @@ -494,7 +495,7 @@ resource "aws_neptune_subnet_group" "test" {
resource "aws_neptune_cluster" "test" {
cluster_identifier = %[1]q
neptune_subnet_group_name = aws_neptune_subnet_group.test.name
neptune_cluster_parameter_group_name = "default.neptune1.2"
neptune_cluster_parameter_group_name = "default.neptune1.3"
skip_final_snapshot = true
}
`, rName))
Expand Down Expand Up @@ -539,7 +540,7 @@ resource "aws_neptune_cluster" "test" {
storage_encrypted = true
kms_key_arn = aws_kms_key.test.arn
neptune_cluster_parameter_group_name = "default.neptune1.2"
neptune_cluster_parameter_group_name = "default.neptune1.3"
}
`, rName))
}
2 changes: 1 addition & 1 deletion internal/service/neptune/cluster_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ resource "aws_neptune_cluster" "test" {
cluster_identifier = %[1]q
skip_final_snapshot = true
neptune_cluster_parameter_group_name = "default.neptune1.2"
neptune_cluster_parameter_group_name = "default.neptune1.3"
}
resource "aws_neptune_cluster_snapshot" "test" {
Expand Down
Loading

0 comments on commit fb291b3

Please sign in to comment.