Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yardensachs authored and anGie44 committed May 7, 2021
1 parent cacd6ff commit a870d28
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
14 changes: 9 additions & 5 deletions aws/resource_aws_timestreamwrite_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ func resourceAwsTimestreamWriteDatabase() *schema.Resource {
},

"kms_key_id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: validateArn,
},

"tags": tagsSchema(),
Expand All @@ -58,12 +59,15 @@ func resourceAwsTimestreamWriteDatabaseCreate(d *schema.ResourceData, meta inter
input.Tags = keyvaluetags.New(attr.(map[string]interface{})).IgnoreAws().TimestreamwriteTags()
}

_, err := conn.CreateDatabase(input)
resp, err := conn.CreateDatabase(input)

if err != nil {
return err
}

d.SetId(d.Get("database_name").(string))
name := aws.StringValue(resp.Database.DatabaseName)

d.SetId(name)

return resourceAwsTimestreamWriteDatabaseRead(d, meta)
}
Expand Down
23 changes: 13 additions & 10 deletions aws/resource_aws_timestreamwrite_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -12,7 +13,7 @@ import (
)

func TestAccAWSTimestreamWriteDatabase_basic(t *testing.T) {
resourceName := "aws_timestreamwrite_database.test_database"
resourceName := "aws_timestreamwrite_database.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -24,7 +25,9 @@ func TestAccAWSTimestreamWriteDatabase_basic(t *testing.T) {
Config: testAccAWSTimestreamWriteDatabaseConfigNoTags(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSTimestreamWriteDatabaseExists(resourceName),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "timestream", fmt.Sprintf("database/%s", rName)),
resource.TestCheckResourceAttr(resourceName, "database_name", rName),
testAccMatchResourceAttrRegionalARN(resourceName, "kms_key_id", "kms", regexp.MustCompile(`key/.+`)),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
Expand All @@ -38,9 +41,9 @@ func TestAccAWSTimestreamWriteDatabase_basic(t *testing.T) {
}

func TestAccAWSTimestreamWriteDatabase_kmsKey(t *testing.T) {
resourceName := "aws_timestreamwrite_database.test_database"
resourceName := "aws_timestreamwrite_database.test"
rName := acctest.RandomWithPrefix("tf-acc-test")
kmsResourceName := "aws_kms_key.foo"
kmsResourceName := "aws_kms_key.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -65,7 +68,7 @@ func TestAccAWSTimestreamWriteDatabase_kmsKey(t *testing.T) {
}

func TestAccAWSTimestreamWriteDatabase_Tags(t *testing.T) {
resourceName := "aws_timestreamwrite_database.test_database"
resourceName := "aws_timestreamwrite_database.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -158,15 +161,15 @@ func testAccCheckAWSTimestreamWriteDatabaseExists(n string) resource.TestCheckFu

func testAccAWSTimestreamWriteDatabaseConfigNoTags(rName string) string {
return fmt.Sprintf(`
resource "aws_timestreamwrite_database" "test_database" {
resource "aws_timestreamwrite_database" "test" {
database_name = %[1]q
}
`, rName)
}

func testAccAWSTimestreamWriteDatabaseConfigTags1(rName, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_timestreamwrite_database" "test_database" {
resource "aws_timestreamwrite_database" "test" {
database_name = %[1]q
tags = {
Expand All @@ -178,7 +181,7 @@ resource "aws_timestreamwrite_database" "test_database" {

func testAccAWSTimestreamWriteDatabaseConfigTags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string {
return fmt.Sprintf(`
resource "aws_timestreamwrite_database" "test_database" {
resource "aws_timestreamwrite_database" "test" {
database_name = %[1]q
tags = {
Expand All @@ -191,7 +194,7 @@ resource "aws_timestreamwrite_database" "test_database" {

func testAccAWSTimestreamWriteDatabaseConfigKmsKey(rName string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "foo" {
resource "aws_kms_key" "test" {
description = "Terraform acc test"
policy = <<POLICY
Expand All @@ -211,9 +214,9 @@ resource "aws_kms_key" "foo" {
POLICY
}
resource "aws_timestreamwrite_database" "test_database" {
resource "aws_timestreamwrite_database" "test" {
database_name = %[1]q
kms_key_id = aws_kms_key.foo.arn
kms_key_id = aws_kms_key.test.arn
}
`, rName)
}
11 changes: 2 additions & 9 deletions website/docs/r/timestreamwrite_database.html.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
subcategory: "TimestreamWrite"
subcategory: "Timestream Write"
layout: "aws"
page_title: "AWS: aws_timestreamwrite_database"
description: |-
Expand Down Expand Up @@ -38,14 +38,8 @@ resource "aws_timestreamwrite_database" "test_database" {
The following arguments are supported:

* `database_name` – (Required) The name of the Timestream database. Minimum length of 3. Maximum length of 64.

* `kms_key_id` - (Optional) The KMS key for the database. You can specify a key ID using any of the following:
* Key ID: `1234abcd-12ab-34cd-56ef-1234567890ab`
* Key ARN: `arn:aws:kms:us-east-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab`
* Alias name: `alias/ExampleAlias`
* Alias ARN: `arn:aws:kms:us-east-1:111122223333:alias/ExampleAlias`
* `kms_key_id` - (Optional) The KMS key for the database. You can specify a key ARN.
If the KMS key is not specified, the database will be encrypted with a Timestream managed KMS key located in your account. Refer to [AWS managed KMS keys](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-managed-cmk) for more info.

* `tags` - (Optional) A map of tags to assign to the resource


Expand All @@ -54,7 +48,6 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `arn` - The Amazon Resource Name that uniquely identifies this database.

* `kms_key_id` - The identifier of the KMS key used to encrypt the data stored in the database.

## Import
Expand Down

0 comments on commit a870d28

Please sign in to comment.