github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/aws/resource_aws_dynamodb_table_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "log" 6 "testing" 7 8 "github.com/aws/aws-sdk-go/aws" 9 "github.com/aws/aws-sdk-go/aws/awserr" 10 "github.com/aws/aws-sdk-go/service/dynamodb" 11 "github.com/hashicorp/terraform/helper/acctest" 12 "github.com/hashicorp/terraform/helper/resource" 13 "github.com/hashicorp/terraform/terraform" 14 ) 15 16 func TestAccAWSDynamoDbTable_basic(t *testing.T) { 17 var conf dynamodb.DescribeTableOutput 18 19 rName := acctest.RandomWithPrefix("TerraformTestTable-") 20 21 resource.Test(t, resource.TestCase{ 22 PreCheck: func() { testAccPreCheck(t) }, 23 Providers: testAccProviders, 24 CheckDestroy: testAccCheckAWSDynamoDbTableDestroy, 25 Steps: []resource.TestStep{ 26 { 27 Config: testAccAWSDynamoDbConfigInitialState(rName), 28 Check: resource.ComposeTestCheckFunc( 29 testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &conf), 30 testAccCheckInitialAWSDynamoDbTableConf("aws_dynamodb_table.basic-dynamodb-table"), 31 ), 32 }, 33 { 34 Config: testAccAWSDynamoDbConfigAddSecondaryGSI(rName), 35 Check: resource.ComposeTestCheckFunc( 36 testAccCheckDynamoDbTableWasUpdated("aws_dynamodb_table.basic-dynamodb-table"), 37 ), 38 }, 39 }, 40 }) 41 } 42 43 func TestAccAWSDynamoDbTable_streamSpecification(t *testing.T) { 44 var conf dynamodb.DescribeTableOutput 45 46 resource.Test(t, resource.TestCase{ 47 PreCheck: func() { testAccPreCheck(t) }, 48 Providers: testAccProviders, 49 CheckDestroy: testAccCheckAWSDynamoDbTableDestroy, 50 Steps: []resource.TestStep{ 51 { 52 Config: testAccAWSDynamoDbConfigStreamSpecification(), 53 Check: resource.ComposeTestCheckFunc( 54 testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &conf), 55 testAccCheckInitialAWSDynamoDbTableConf("aws_dynamodb_table.basic-dynamodb-table"), 56 resource.TestCheckResourceAttr( 57 "aws_dynamodb_table.basic-dynamodb-table", "stream_enabled", "true"), 58 resource.TestCheckResourceAttr( 59 "aws_dynamodb_table.basic-dynamodb-table", "stream_view_type", "KEYS_ONLY"), 60 ), 61 }, 62 }, 63 }) 64 } 65 66 func TestAccAWSDynamoDbTable_tags(t *testing.T) { 67 var conf dynamodb.DescribeTableOutput 68 69 resource.Test(t, resource.TestCase{ 70 PreCheck: func() { testAccPreCheck(t) }, 71 Providers: testAccProviders, 72 CheckDestroy: testAccCheckAWSDynamoDbTableDestroy, 73 Steps: []resource.TestStep{ 74 { 75 Config: testAccAWSDynamoDbConfigTags(), 76 Check: resource.ComposeTestCheckFunc( 77 testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &conf), 78 testAccCheckInitialAWSDynamoDbTableConf("aws_dynamodb_table.basic-dynamodb-table"), 79 resource.TestCheckResourceAttr( 80 "aws_dynamodb_table.basic-dynamodb-table", "tags.%", "3"), 81 ), 82 }, 83 }, 84 }) 85 } 86 87 // https://github.com/hashicorp/terraform/issues/13243 88 func TestAccAWSDynamoDbTable_gsiUpdate(t *testing.T) { 89 var conf dynamodb.DescribeTableOutput 90 name := acctest.RandString(10) 91 92 resource.Test(t, resource.TestCase{ 93 PreCheck: func() { testAccPreCheck(t) }, 94 Providers: testAccProviders, 95 CheckDestroy: testAccCheckAWSDynamoDbTableDestroy, 96 Steps: []resource.TestStep{ 97 { 98 Config: testAccAWSDynamoDbConfigGsiUpdate(name), 99 Check: resource.ComposeTestCheckFunc( 100 testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.test", &conf), 101 ), 102 }, 103 { 104 Config: testAccAWSDynamoDbConfigGsiUpdated(name), 105 Check: resource.ComposeTestCheckFunc( 106 testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.test", &conf), 107 ), 108 }, 109 }, 110 }) 111 } 112 113 func TestAccAWSDynamoDbTable_ttl(t *testing.T) { 114 var conf dynamodb.DescribeTableOutput 115 116 rName := acctest.RandomWithPrefix("TerraformTestTable-") 117 118 resource.Test(t, resource.TestCase{ 119 PreCheck: func() { testAccPreCheck(t) }, 120 Providers: testAccProviders, 121 CheckDestroy: testAccCheckAWSDynamoDbTableDestroy, 122 Steps: []resource.TestStep{ 123 { 124 Config: testAccAWSDynamoDbConfigInitialState(rName), 125 Check: resource.ComposeTestCheckFunc( 126 testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &conf), 127 ), 128 }, 129 { 130 Config: testAccAWSDynamoDbConfigAddTimeToLive(rName), 131 Check: resource.ComposeTestCheckFunc( 132 testAccCheckDynamoDbTableTimeToLiveWasUpdated("aws_dynamodb_table.basic-dynamodb-table"), 133 ), 134 }, 135 }, 136 }) 137 } 138 func testAccCheckDynamoDbTableTimeToLiveWasUpdated(n string) resource.TestCheckFunc { 139 return func(s *terraform.State) error { 140 log.Printf("[DEBUG] Trying to create initial table state!") 141 rs, ok := s.RootModule().Resources[n] 142 if !ok { 143 return fmt.Errorf("Not found: %s", n) 144 } 145 146 if rs.Primary.ID == "" { 147 return fmt.Errorf("No DynamoDB table name specified!") 148 } 149 150 conn := testAccProvider.Meta().(*AWSClient).dynamodbconn 151 152 params := &dynamodb.DescribeTimeToLiveInput{ 153 TableName: aws.String(rs.Primary.ID), 154 } 155 156 resp, err := conn.DescribeTimeToLive(params) 157 158 if err != nil { 159 return fmt.Errorf("[ERROR] Problem describing time to live for table '%s': %s", rs.Primary.ID, err) 160 } 161 162 ttlDescription := resp.TimeToLiveDescription 163 164 log.Printf("[DEBUG] Checking on table %s", rs.Primary.ID) 165 166 if *ttlDescription.TimeToLiveStatus != dynamodb.TimeToLiveStatusEnabled { 167 return fmt.Errorf("TimeToLiveStatus %s, not ENABLED!", *ttlDescription.TimeToLiveStatus) 168 } 169 170 if *ttlDescription.AttributeName != "TestTTL" { 171 return fmt.Errorf("AttributeName was %s, not TestTTL!", *ttlDescription.AttributeName) 172 } 173 174 return nil 175 } 176 } 177 178 func TestResourceAWSDynamoDbTableStreamViewType_validation(t *testing.T) { 179 cases := []struct { 180 Value string 181 ErrCount int 182 }{ 183 { 184 Value: "KEYS-ONLY", 185 ErrCount: 1, 186 }, 187 { 188 Value: "RANDOM-STRING", 189 ErrCount: 1, 190 }, 191 { 192 Value: "KEYS_ONLY", 193 ErrCount: 0, 194 }, 195 { 196 Value: "NEW_AND_OLD_IMAGES", 197 ErrCount: 0, 198 }, 199 { 200 Value: "NEW_IMAGE", 201 ErrCount: 0, 202 }, 203 { 204 Value: "OLD_IMAGE", 205 ErrCount: 0, 206 }, 207 } 208 209 for _, tc := range cases { 210 _, errors := validateStreamViewType(tc.Value, "aws_dynamodb_table_stream_view_type") 211 212 if len(errors) != tc.ErrCount { 213 t.Fatalf("Expected the DynamoDB stream_view_type to trigger a validation error") 214 } 215 } 216 } 217 218 func testAccCheckAWSDynamoDbTableDestroy(s *terraform.State) error { 219 conn := testAccProvider.Meta().(*AWSClient).dynamodbconn 220 221 for _, rs := range s.RootModule().Resources { 222 if rs.Type != "aws_dynamodb_table" { 223 continue 224 } 225 226 log.Printf("[DEBUG] Checking if DynamoDB table %s exists", rs.Primary.ID) 227 // Check if queue exists by checking for its attributes 228 params := &dynamodb.DescribeTableInput{ 229 TableName: aws.String(rs.Primary.ID), 230 } 231 232 _, err := conn.DescribeTable(params) 233 if err == nil { 234 return fmt.Errorf("DynamoDB table %s still exists. Failing!", rs.Primary.ID) 235 } 236 237 // Verify the error is what we want 238 if dbErr, ok := err.(awserr.Error); ok && dbErr.Code() == "ResourceNotFoundException" { 239 return nil 240 } 241 242 return err 243 } 244 245 return nil 246 } 247 248 func testAccCheckInitialAWSDynamoDbTableExists(n string, table *dynamodb.DescribeTableOutput) resource.TestCheckFunc { 249 return func(s *terraform.State) error { 250 log.Printf("[DEBUG] Trying to create initial table state!") 251 rs, ok := s.RootModule().Resources[n] 252 if !ok { 253 return fmt.Errorf("Not found: %s", n) 254 } 255 256 if rs.Primary.ID == "" { 257 return fmt.Errorf("No DynamoDB table name specified!") 258 } 259 260 conn := testAccProvider.Meta().(*AWSClient).dynamodbconn 261 262 params := &dynamodb.DescribeTableInput{ 263 TableName: aws.String(rs.Primary.ID), 264 } 265 266 resp, err := conn.DescribeTable(params) 267 268 if err != nil { 269 return fmt.Errorf("[ERROR] Problem describing table '%s': %s", rs.Primary.ID, err) 270 } 271 272 *table = *resp 273 274 return nil 275 } 276 } 277 278 func testAccCheckInitialAWSDynamoDbTableConf(n string) resource.TestCheckFunc { 279 return func(s *terraform.State) error { 280 log.Printf("[DEBUG] Trying to create initial table state!") 281 rs, ok := s.RootModule().Resources[n] 282 if !ok { 283 return fmt.Errorf("Not found: %s", n) 284 } 285 286 if rs.Primary.ID == "" { 287 return fmt.Errorf("No DynamoDB table name specified!") 288 } 289 290 conn := testAccProvider.Meta().(*AWSClient).dynamodbconn 291 292 params := &dynamodb.DescribeTableInput{ 293 TableName: aws.String(rs.Primary.ID), 294 } 295 296 resp, err := conn.DescribeTable(params) 297 298 if err != nil { 299 return fmt.Errorf("[ERROR] Problem describing table '%s': %s", rs.Primary.ID, err) 300 } 301 302 table := resp.Table 303 304 log.Printf("[DEBUG] Checking on table %s", rs.Primary.ID) 305 306 if *table.ProvisionedThroughput.WriteCapacityUnits != 20 { 307 return fmt.Errorf("Provisioned write capacity was %d, not 20!", table.ProvisionedThroughput.WriteCapacityUnits) 308 } 309 310 if *table.ProvisionedThroughput.ReadCapacityUnits != 10 { 311 return fmt.Errorf("Provisioned read capacity was %d, not 10!", table.ProvisionedThroughput.ReadCapacityUnits) 312 } 313 314 attrCount := len(table.AttributeDefinitions) 315 gsiCount := len(table.GlobalSecondaryIndexes) 316 lsiCount := len(table.LocalSecondaryIndexes) 317 318 if attrCount != 4 { 319 return fmt.Errorf("There were %d attributes, not 4 like there should have been!", attrCount) 320 } 321 322 if gsiCount != 1 { 323 return fmt.Errorf("There were %d GSIs, not 1 like there should have been!", gsiCount) 324 } 325 326 if lsiCount != 1 { 327 return fmt.Errorf("There were %d LSIs, not 1 like there should have been!", lsiCount) 328 } 329 330 attrmap := dynamoDbAttributesToMap(&table.AttributeDefinitions) 331 if attrmap["TestTableHashKey"] != "S" { 332 return fmt.Errorf("Test table hash key was of type %s instead of S!", attrmap["TestTableHashKey"]) 333 } 334 if attrmap["TestTableRangeKey"] != "S" { 335 return fmt.Errorf("Test table range key was of type %s instead of S!", attrmap["TestTableRangeKey"]) 336 } 337 if attrmap["TestLSIRangeKey"] != "N" { 338 return fmt.Errorf("Test table LSI range key was of type %s instead of N!", attrmap["TestLSIRangeKey"]) 339 } 340 if attrmap["TestGSIRangeKey"] != "S" { 341 return fmt.Errorf("Test table GSI range key was of type %s instead of S!", attrmap["TestGSIRangeKey"]) 342 } 343 344 return nil 345 } 346 } 347 348 func testAccCheckDynamoDbTableWasUpdated(n string) resource.TestCheckFunc { 349 return func(s *terraform.State) error { 350 rs, ok := s.RootModule().Resources[n] 351 if !ok { 352 return fmt.Errorf("Not found: %s", n) 353 } 354 355 if rs.Primary.ID == "" { 356 return fmt.Errorf("No DynamoDB table name specified!") 357 } 358 359 conn := testAccProvider.Meta().(*AWSClient).dynamodbconn 360 361 params := &dynamodb.DescribeTableInput{ 362 TableName: aws.String(rs.Primary.ID), 363 } 364 resp, err := conn.DescribeTable(params) 365 table := resp.Table 366 367 if err != nil { 368 return err 369 } 370 371 attrCount := len(table.AttributeDefinitions) 372 gsiCount := len(table.GlobalSecondaryIndexes) 373 lsiCount := len(table.LocalSecondaryIndexes) 374 375 if attrCount != 4 { 376 return fmt.Errorf("There were %d attributes, not 4 like there should have been!", attrCount) 377 } 378 379 if gsiCount != 1 { 380 return fmt.Errorf("There were %d GSIs, not 1 like there should have been!", gsiCount) 381 } 382 383 if lsiCount != 1 { 384 return fmt.Errorf("There were %d LSIs, not 1 like there should have been!", lsiCount) 385 } 386 387 if dynamoDbGetGSIIndex(&table.GlobalSecondaryIndexes, "ReplacementTestTableGSI") == -1 { 388 return fmt.Errorf("Could not find GSI named 'ReplacementTestTableGSI' in the table!") 389 } 390 391 if dynamoDbGetGSIIndex(&table.GlobalSecondaryIndexes, "InitialTestTableGSI") != -1 { 392 return fmt.Errorf("Should have removed 'InitialTestTableGSI' but it still exists!") 393 } 394 395 attrmap := dynamoDbAttributesToMap(&table.AttributeDefinitions) 396 if attrmap["TestTableHashKey"] != "S" { 397 return fmt.Errorf("Test table hash key was of type %s instead of S!", attrmap["TestTableHashKey"]) 398 } 399 if attrmap["TestTableRangeKey"] != "S" { 400 return fmt.Errorf("Test table range key was of type %s instead of S!", attrmap["TestTableRangeKey"]) 401 } 402 if attrmap["TestLSIRangeKey"] != "N" { 403 return fmt.Errorf("Test table LSI range key was of type %s instead of N!", attrmap["TestLSIRangeKey"]) 404 } 405 if attrmap["ReplacementGSIRangeKey"] != "N" { 406 return fmt.Errorf("Test table replacement GSI range key was of type %s instead of N!", attrmap["ReplacementGSIRangeKey"]) 407 } 408 409 return nil 410 } 411 } 412 413 func dynamoDbGetGSIIndex(gsiList *[]*dynamodb.GlobalSecondaryIndexDescription, target string) int { 414 for idx, gsiObject := range *gsiList { 415 if *gsiObject.IndexName == target { 416 return idx 417 } 418 } 419 420 return -1 421 } 422 423 func dynamoDbAttributesToMap(attributes *[]*dynamodb.AttributeDefinition) map[string]string { 424 attrmap := make(map[string]string) 425 426 for _, attrdef := range *attributes { 427 attrmap[*attrdef.AttributeName] = *attrdef.AttributeType 428 } 429 430 return attrmap 431 } 432 433 func testAccAWSDynamoDbConfigInitialState(rName string) string { 434 return fmt.Sprintf(` 435 resource "aws_dynamodb_table" "basic-dynamodb-table" { 436 name = "%s" 437 read_capacity = 10 438 write_capacity = 20 439 hash_key = "TestTableHashKey" 440 range_key = "TestTableRangeKey" 441 442 attribute { 443 name = "TestTableHashKey" 444 type = "S" 445 } 446 447 attribute { 448 name = "TestTableRangeKey" 449 type = "S" 450 } 451 452 attribute { 453 name = "TestLSIRangeKey" 454 type = "N" 455 } 456 457 attribute { 458 name = "TestGSIRangeKey" 459 type = "S" 460 } 461 462 local_secondary_index { 463 name = "TestTableLSI" 464 range_key = "TestLSIRangeKey" 465 projection_type = "ALL" 466 } 467 468 global_secondary_index { 469 name = "InitialTestTableGSI" 470 hash_key = "TestTableHashKey" 471 range_key = "TestGSIRangeKey" 472 write_capacity = 10 473 read_capacity = 10 474 projection_type = "KEYS_ONLY" 475 } 476 } 477 `, rName) 478 } 479 480 func testAccAWSDynamoDbConfigAddSecondaryGSI(rName string) string { 481 return fmt.Sprintf(` 482 resource "aws_dynamodb_table" "basic-dynamodb-table" { 483 name = "%s" 484 read_capacity = 20 485 write_capacity = 20 486 hash_key = "TestTableHashKey" 487 range_key = "TestTableRangeKey" 488 489 attribute { 490 name = "TestTableHashKey" 491 type = "S" 492 } 493 494 attribute { 495 name = "TestTableRangeKey" 496 type = "S" 497 } 498 499 attribute { 500 name = "TestLSIRangeKey" 501 type = "N" 502 } 503 504 attribute { 505 name = "ReplacementGSIRangeKey" 506 type = "N" 507 } 508 509 local_secondary_index { 510 name = "TestTableLSI" 511 range_key = "TestLSIRangeKey" 512 projection_type = "ALL" 513 } 514 515 global_secondary_index { 516 name = "ReplacementTestTableGSI" 517 hash_key = "TestTableHashKey" 518 range_key = "ReplacementGSIRangeKey" 519 write_capacity = 5 520 read_capacity = 5 521 projection_type = "INCLUDE" 522 non_key_attributes = ["TestNonKeyAttribute"] 523 } 524 }`, rName) 525 } 526 527 func testAccAWSDynamoDbConfigStreamSpecification() string { 528 return fmt.Sprintf(` 529 resource "aws_dynamodb_table" "basic-dynamodb-table" { 530 name = "TerraformTestStreamTable-%d" 531 read_capacity = 10 532 write_capacity = 20 533 hash_key = "TestTableHashKey" 534 range_key = "TestTableRangeKey" 535 536 attribute { 537 name = "TestTableHashKey" 538 type = "S" 539 } 540 541 attribute { 542 name = "TestTableRangeKey" 543 type = "S" 544 } 545 546 attribute { 547 name = "TestLSIRangeKey" 548 type = "N" 549 } 550 551 attribute { 552 name = "TestGSIRangeKey" 553 type = "S" 554 } 555 556 local_secondary_index { 557 name = "TestTableLSI" 558 range_key = "TestLSIRangeKey" 559 projection_type = "ALL" 560 } 561 562 global_secondary_index { 563 name = "InitialTestTableGSI" 564 hash_key = "TestTableHashKey" 565 range_key = "TestGSIRangeKey" 566 write_capacity = 10 567 read_capacity = 10 568 projection_type = "KEYS_ONLY" 569 } 570 stream_enabled = true 571 stream_view_type = "KEYS_ONLY" 572 } 573 `, acctest.RandInt()) 574 } 575 576 func testAccAWSDynamoDbConfigTags() string { 577 return fmt.Sprintf(` 578 resource "aws_dynamodb_table" "basic-dynamodb-table" { 579 name = "TerraformTestTable-%d" 580 read_capacity = 10 581 write_capacity = 20 582 hash_key = "TestTableHashKey" 583 range_key = "TestTableRangeKey" 584 585 attribute { 586 name = "TestTableHashKey" 587 type = "S" 588 } 589 590 attribute { 591 name = "TestTableRangeKey" 592 type = "S" 593 } 594 595 attribute { 596 name = "TestLSIRangeKey" 597 type = "N" 598 } 599 600 attribute { 601 name = "TestGSIRangeKey" 602 type = "S" 603 } 604 605 local_secondary_index { 606 name = "TestTableLSI" 607 range_key = "TestLSIRangeKey" 608 projection_type = "ALL" 609 } 610 611 global_secondary_index { 612 name = "InitialTestTableGSI" 613 hash_key = "TestTableHashKey" 614 range_key = "TestGSIRangeKey" 615 write_capacity = 10 616 read_capacity = 10 617 projection_type = "KEYS_ONLY" 618 } 619 620 tags { 621 Name = "terraform-test-table-%d" 622 AccTest = "yes" 623 Testing = "absolutely" 624 } 625 } 626 `, acctest.RandInt(), acctest.RandInt()) 627 } 628 629 func testAccAWSDynamoDbConfigGsiUpdate(name string) string { 630 return fmt.Sprintf(` 631 variable "capacity" { 632 default = 10 633 } 634 635 resource "aws_dynamodb_table" "test" { 636 name = "tf-acc-test-%s" 637 read_capacity = "${var.capacity}" 638 write_capacity = "${var.capacity}" 639 hash_key = "id" 640 641 attribute { 642 name = "id" 643 type = "S" 644 } 645 646 attribute { 647 name = "att1" 648 type = "S" 649 } 650 651 attribute { 652 name = "att2" 653 type = "S" 654 } 655 656 attribute { 657 name = "att3" 658 type = "S" 659 } 660 661 global_secondary_index { 662 name = "att1-index" 663 hash_key = "att1" 664 write_capacity = "${var.capacity}" 665 read_capacity = "${var.capacity}" 666 projection_type = "ALL" 667 } 668 669 global_secondary_index { 670 name = "att2-index" 671 hash_key = "att2" 672 write_capacity = "${var.capacity}" 673 read_capacity = "${var.capacity}" 674 projection_type = "ALL" 675 } 676 677 global_secondary_index { 678 name = "att3-index" 679 hash_key = "att3" 680 write_capacity = "${var.capacity}" 681 read_capacity = "${var.capacity}" 682 projection_type = "ALL" 683 } 684 } 685 `, name) 686 } 687 688 func testAccAWSDynamoDbConfigGsiUpdated(name string) string { 689 return fmt.Sprintf(` 690 variable "capacity" { 691 default = 20 692 } 693 694 resource "aws_dynamodb_table" "test" { 695 name = "tf-acc-test-%s" 696 read_capacity = "${var.capacity}" 697 write_capacity = "${var.capacity}" 698 hash_key = "id" 699 700 attribute { 701 name = "id" 702 type = "S" 703 } 704 705 attribute { 706 name = "att1" 707 type = "S" 708 } 709 710 attribute { 711 name = "att2" 712 type = "S" 713 } 714 715 attribute { 716 name = "att3" 717 type = "S" 718 } 719 720 global_secondary_index { 721 name = "att1-index" 722 hash_key = "att1" 723 write_capacity = "${var.capacity}" 724 read_capacity = "${var.capacity}" 725 projection_type = "ALL" 726 } 727 728 global_secondary_index { 729 name = "att2-index" 730 hash_key = "att2" 731 write_capacity = "${var.capacity}" 732 read_capacity = "${var.capacity}" 733 projection_type = "ALL" 734 } 735 736 global_secondary_index { 737 name = "att3-index" 738 hash_key = "att3" 739 write_capacity = "${var.capacity}" 740 read_capacity = "${var.capacity}" 741 projection_type = "ALL" 742 } 743 } 744 `, name) 745 } 746 747 func testAccAWSDynamoDbConfigAddTimeToLive(rName string) string { 748 return fmt.Sprintf(` 749 resource "aws_dynamodb_table" "basic-dynamodb-table" { 750 name = "%s" 751 read_capacity = 10 752 write_capacity = 20 753 hash_key = "TestTableHashKey" 754 range_key = "TestTableRangeKey" 755 756 attribute { 757 name = "TestTableHashKey" 758 type = "S" 759 } 760 761 attribute { 762 name = "TestTableRangeKey" 763 type = "S" 764 } 765 766 attribute { 767 name = "TestLSIRangeKey" 768 type = "N" 769 } 770 771 attribute { 772 name = "TestGSIRangeKey" 773 type = "S" 774 } 775 776 local_secondary_index { 777 name = "TestTableLSI" 778 range_key = "TestLSIRangeKey" 779 projection_type = "ALL" 780 } 781 782 ttl { 783 attribute_name = "TestTTL" 784 enabled = true 785 } 786 787 global_secondary_index { 788 name = "InitialTestTableGSI" 789 hash_key = "TestTableHashKey" 790 range_key = "TestGSIRangeKey" 791 write_capacity = 10 792 read_capacity = 10 793 projection_type = "KEYS_ONLY" 794 } 795 } 796 `, rName) 797 }