Skip to content

Commit

Permalink
fix: Add missing on_demand_throughput attrs for aws_dynamodb_table da…
Browse files Browse the repository at this point in the history
…ta source (#41350)
  • Loading branch information
acwwat authored Feb 12, 2025
1 parent a244b2d commit 2cb81dd
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/41350.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_dynamodb_table: Add missing `on_demand_throughput` and `global_secondary_index.*.on_demand_throughput` attributes to resolve read error
```
36 changes: 36 additions & 0 deletions internal/service/dynamodb/table_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ func dataSourceTable() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"on_demand_throughput": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max_read_request_units": {
Type: schema.TypeInt,
Computed: true,
},
"max_write_request_units": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"projection_type": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -122,6 +138,22 @@ func dataSourceTable() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"on_demand_throughput": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max_read_request_units": {
Type: schema.TypeInt,
Computed: true,
},
"max_write_request_units": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"point_in_time_recovery": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -269,6 +301,10 @@ func dataSourceTableRead(ctx context.Context, d *schema.ResourceData, meta inter
return sdkdiag.AppendErrorf(diags, "setting global_secondary_index: %s", err)
}

if err := d.Set("on_demand_throughput", flattenOnDemandThroughput(table.OnDemandThroughput)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting on_demand_throughput: %s", err)
}

if table.StreamSpecification != nil {
d.Set("stream_view_type", table.StreamSpecification.StreamViewType)
d.Set("stream_enabled", table.StreamSpecification.StreamEnabled)
Expand Down
91 changes: 91 additions & 0 deletions internal/service/dynamodb/table_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,44 @@ func TestAccDynamoDBTableDataSource_basic(t *testing.T) {
})
}

func TestAccDynamoDBTableDataSource_onDemandThroughput(t *testing.T) {
ctx := acctest.Context(t)
datasourceName := "data.aws_dynamodb_table.test"
resourceName := "aws_dynamodb_table.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.DynamoDBServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccTableDataSourceConfig_onDemandThroughput(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, names.AttrName, resourceName, names.AttrName),
resource.TestCheckResourceAttrPair(datasourceName, "hash_key", resourceName, "hash_key"),
resource.TestCheckResourceAttrPair(datasourceName, "range_key", resourceName, "range_key"),
resource.TestCheckResourceAttrPair(datasourceName, "attribute.#", resourceName, "attribute.#"),
resource.TestCheckResourceAttrPair(datasourceName, "global_secondary_index.#", resourceName, "global_secondary_index.#"),
resource.TestCheckResourceAttrPair(datasourceName, "global_secondary_index.0.on_demand_throughput.0.max_read_request_units", resourceName, "global_secondary_index.0.on_demand_throughput.0.max_read_request_units"),
resource.TestCheckResourceAttrPair(datasourceName, "global_secondary_index.0.on_demand_throughput.0.max_write_request_units", resourceName, "global_secondary_index.0.on_demand_throughput.0.max_write_request_units"),
resource.TestCheckResourceAttrPair(datasourceName, "on_demand_throughput.0.max_read_request_units", resourceName, "on_demand_throughput.0.max_read_request_units"),
resource.TestCheckResourceAttrPair(datasourceName, "on_demand_throughput.0.max_write_request_units", resourceName, "on_demand_throughput.0.max_write_request_units"),
resource.TestCheckResourceAttrPair(datasourceName, "ttl.#", resourceName, "ttl.#"),
resource.TestCheckResourceAttrPair(datasourceName, acctest.CtTagsPercent, resourceName, acctest.CtTagsPercent),
resource.TestCheckResourceAttrPair(datasourceName, "tags.Name", resourceName, "tags.Name"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.Environment", resourceName, "tags.Environment"),
resource.TestCheckResourceAttrPair(datasourceName, "server_side_encryption.#", resourceName, "server_side_encryption.#"),
resource.TestCheckResourceAttrPair(datasourceName, "billing_mode", resourceName, "billing_mode"),
resource.TestCheckResourceAttrPair(datasourceName, "point_in_time_recovery.#", resourceName, "point_in_time_recovery.#"),
resource.TestCheckResourceAttrPair(datasourceName, "point_in_time_recovery.0.enabled", resourceName, "point_in_time_recovery.0.enabled"),
resource.TestCheckResourceAttrPair(datasourceName, "table_class", resourceName, "table_class"),
),
},
},
})
}

func testAccTableDataSourceConfig_basic(tableName string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "test" {
Expand Down Expand Up @@ -94,3 +132,56 @@ data "aws_dynamodb_table" "test" {
}
`, tableName)
}

func testAccTableDataSourceConfig_onDemandThroughput(tableName string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "test" {
name = %[1]q
billing_mode = "PAY_PER_REQUEST"
hash_key = "UserId"
range_key = "GameTitle"
attribute {
name = "UserId"
type = "S"
}
attribute {
name = "GameTitle"
type = "S"
}
attribute {
name = "TopScore"
type = "N"
}
global_secondary_index {
name = "GameTitleIndex"
hash_key = "GameTitle"
range_key = "TopScore"
projection_type = "INCLUDE"
non_key_attributes = ["UserId"]
on_demand_throughput {
max_read_request_units = 10
max_write_request_units = 10
}
}
on_demand_throughput {
max_read_request_units = 10
max_write_request_units = 10
}
tags = {
Name = "dynamodb-table-1"
Environment = "test"
}
}
data "aws_dynamodb_table" "test" {
name = aws_dynamodb_table.test.name
}
`, tableName)
}

0 comments on commit 2cb81dd

Please sign in to comment.