From 3d6bd5814686328b50166e66cbd8aaf6f6ea7e85 Mon Sep 17 00:00:00 2001 From: Kavan Bansal Date: Tue, 6 Jun 2023 16:03:05 -0400 Subject: [PATCH 01/20] Adds finspace_kx_database resource --- internal/service/finspace/kx_database.go | 207 ++++++++++++ internal/service/finspace/kx_database_test.go | 306 ++++++++++++++++++ .../docs/r/finspace_kx_database.html.markdown | 62 ++++ 3 files changed, 575 insertions(+) create mode 100644 internal/service/finspace/kx_database.go create mode 100644 internal/service/finspace/kx_database_test.go create mode 100644 website/docs/r/finspace_kx_database.html.markdown diff --git a/internal/service/finspace/kx_database.go b/internal/service/finspace/kx_database.go new file mode 100644 index 00000000000..4129b8fe8af --- /dev/null +++ b/internal/service/finspace/kx_database.go @@ -0,0 +1,207 @@ +package finspace + +import ( + "context" + "errors" + "log" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/finspace" + "github.com/aws/aws-sdk-go-v2/service/finspace/types" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// @SDKResource("aws_finspace_kx_database") +// @Tags(identifierAttribute="arn") +func ResourceKxDatabase() *schema.Resource { + return &schema.Resource{ + CreateWithoutTimeout: resourceKxDatabaseCreate, + ReadWithoutTimeout: resourceKxDatabaseRead, + UpdateWithoutTimeout: resourceKxDatabaseUpdate, + DeleteWithoutTimeout: resourceKxDatabaseDelete, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "created_timestamp": { + Type: schema.TypeString, + Computed: true, + }, + "last_modified_timestamp": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(3, 63), + }, + "environment_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(1, 32), + }, + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(1, 1000), + }, + "tags": tftags.TagsSchema(), + "tags_all": tftags.TagsSchemaComputed(), + }, + CustomizeDiff: verify.SetTagsDiff, + } +} + +const ( + ResNameKxDatabase = "Kx Database" +) + +func resourceKxDatabaseCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).FinSpaceClient() + + in := &finspace.CreateKxDatabaseInput{ + DatabaseName: aws.String(d.Get("name").(string)), + EnvironmentId: aws.String(d.Get("environment_id").(string)), + ClientToken: aws.String(id.UniqueId()), + Tags: GetTagsIn(ctx), + } + + if v, ok := d.GetOk("description"); ok { + in.Description = aws.String(v.(string)) + } + + out, err := conn.CreateKxDatabase(ctx, in) + if err != nil { + return create.DiagError(names.FinSpace, create.ErrActionCreating, ResNameKxDatabase, d.Get("name").(string), err) + } + + if out == nil || out.DatabaseArn == nil { + return create.DiagError(names.FinSpace, create.ErrActionCreating, ResNameKxDatabase, d.Get("name").(string), errors.New("empty output")) + } + + d.SetId(aws.ToString(out.EnvironmentId) + "," + aws.ToString(out.DatabaseName)) + + return resourceKxDatabaseRead(ctx, d, meta) +} + +func resourceKxDatabaseRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).FinSpaceClient() + + out, err := findKxDatabaseByName(ctx, conn, d.Get("name").(string), d.Get("environment_id").(string)) + + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] FinSpace KxDatabase (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil + } + + if err != nil { + return create.DiagError(names.FinSpace, create.ErrActionReading, ResNameKxDatabase, d.Id(), err) + } + + d.Set("arn", out.DatabaseArn) + d.Set("name", out.DatabaseName) + d.Set("environment_id", out.EnvironmentId) + d.Set("description", out.Description) + d.Set("created_timestamp", out.CreatedTimestamp.String()) + d.Set("last_modified_timestamp", out.LastModifiedTimestamp.String()) + + return nil +} + +func resourceKxDatabaseUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).FinSpaceClient() + + update := false + + in := &finspace.UpdateKxDatabaseInput{ + EnvironmentId: aws.String(d.Get("environment_id").(string)), + DatabaseName: aws.String(d.Get("name").(string)), + } + + if d.HasChanges("description") { + in.Description = aws.String(d.Get("description").(string)) + update = true + } + + if !update { + return nil + } + + log.Printf("[DEBUG] Updating FinSpace KxDatabase (%s): %#v", d.Id(), in) + _, err := conn.UpdateKxDatabase(ctx, in) + if err != nil { + return create.DiagError(names.FinSpace, create.ErrActionUpdating, ResNameKxDatabase, d.Id(), err) + } + + return resourceKxDatabaseRead(ctx, d, meta) +} + +func resourceKxDatabaseDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).FinSpaceClient() + + log.Printf("[INFO] Deleting FinSpace KxDatabase %s", d.Id()) + + _, err := conn.DeleteKxDatabase(ctx, &finspace.DeleteKxDatabaseInput{ + EnvironmentId: aws.String(d.Get("environment_id").(string)), + DatabaseName: aws.String(d.Get("name").(string)), + }) + + if err != nil { + var nfe *types.ResourceNotFoundException + if errors.As(err, &nfe) { + return nil + } + + return create.DiagError(names.FinSpace, create.ErrActionDeleting, ResNameKxDatabase, d.Id(), err) + } + + return nil +} + +func findKxDatabaseByName(ctx context.Context, conn *finspace.Client, name string, environmentId string) (*finspace.GetKxDatabaseOutput, error) { + in := &finspace.GetKxDatabaseInput{ + DatabaseName: aws.String(name), + EnvironmentId: aws.String(environmentId), + } + out, err := conn.GetKxDatabase(ctx, in) + if err != nil { + var nfe *types.ResourceNotFoundException + if errors.As(err, &nfe) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + return nil, err + } + + if out == nil || out.DatabaseArn == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + return out, nil +} diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go new file mode 100644 index 00000000000..2bc57207136 --- /dev/null +++ b/internal/service/finspace/kx_database_test.go @@ -0,0 +1,306 @@ +package finspace_test + +import ( + "context" + "errors" + "fmt" + "testing" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/finspace" + "github.com/aws/aws-sdk-go-v2/service/finspace/types" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + tffinspace "github.com/hashicorp/terraform-provider-aws/internal/service/finspace" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccFinSpaceKxDatabase_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + ctx := acctest.Context(t) + var kxdatabase finspace.GetKxDatabaseOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_finspace_kx_database.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, finspace.ServiceID) + }, + ErrorCheck: acctest.ErrorCheck(t, finspace.ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKxDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccKxDatabaseConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + resource.TestCheckResourceAttr(resourceName, "name", rName), + ), + }, + }, + }) +} + +func TestAccFinSpaceKxDatabase_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + ctx := acctest.Context(t) + var kxdatabase finspace.GetKxDatabaseOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_finspace_kx_database.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, finspace.ServiceID) + }, + ErrorCheck: acctest.ErrorCheck(t, finspace.ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKxDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccKxDatabaseConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tffinspace.ResourceKxDatabase(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccFinSpaceKxDatabase_description(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + ctx := acctest.Context(t) + var kxdatabase finspace.GetKxDatabaseOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_finspace_kx_database.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, finspace.ServiceID) + }, + ErrorCheck: acctest.ErrorCheck(t, finspace.ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKxDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccKxDatabaseConfig_description(rName, "description 1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + resource.TestCheckResourceAttr(resourceName, "description", "description 1"), + ), + }, + { + Config: testAccKxDatabaseConfig_description(rName, "description 2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + resource.TestCheckResourceAttr(resourceName, "description", "description 2"), + ), + }, + }, + }) +} + +func TestAccFinSpaceKxDatabase_tags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + ctx := acctest.Context(t) + var kxdatabase finspace.GetKxDatabaseOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_finspace_kx_database.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, finspace.ServiceID) + }, + ErrorCheck: acctest.ErrorCheck(t, finspace.ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKxDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccKxDatabaseConfig_tags1(rName, "key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + Config: testAccKxDatabaseConfig_tags2(rName, "key1", "value1", "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccKxDatabaseConfig_tags1(rName, "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + }, + }) +} + +func testAccCheckKxDatabaseDestroy(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).FinSpaceClient() + ctx := context.Background() + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_finspace_kx_database" { + continue + } + + input := &finspace.GetKxDatabaseInput{ + DatabaseName: aws.String(rs.Primary.Attributes["name"]), + EnvironmentId: aws.String(rs.Primary.Attributes["environment_id"]), + } + _, err := conn.GetKxDatabase(ctx, input) + if err != nil { + var nfe *types.ResourceNotFoundException + if errors.As(err, &nfe) { + return nil + } + return err + } + + return create.Error(names.FinSpace, create.ErrActionCheckingDestroyed, tffinspace.ResNameKxDatabase, rs.Primary.ID, errors.New("not destroyed")) + } + + return nil +} + +func testAccCheckKxDatabaseExists(name string, kxdatabase *finspace.GetKxDatabaseOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return create.Error(names.FinSpace, create.ErrActionCheckingExistence, tffinspace.ResNameKxDatabase, name, errors.New("not found")) + } + + if rs.Primary.ID == "" { + return create.Error(names.FinSpace, create.ErrActionCheckingExistence, tffinspace.ResNameKxDatabase, name, errors.New("not set")) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).FinSpaceClient() + ctx := context.Background() + resp, err := conn.GetKxDatabase(ctx, &finspace.GetKxDatabaseInput{ + DatabaseName: aws.String(rs.Primary.Attributes["name"]), + EnvironmentId: aws.String(rs.Primary.Attributes["environment_id"]), + }) + + if err != nil { + return create.Error(names.FinSpace, create.ErrActionCheckingExistence, tffinspace.ResNameKxDatabase, rs.Primary.ID, err) + } + + *kxdatabase = *resp + + return nil + } +} + +func testAccKxDatabaseConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "aws_kms_key" "test" { + description = %[1]q + deletion_window_in_days = 7 +} + +resource "aws_finspace_kx_environment" "test" { + name = %[1]q + kms_key_id =aws_kms_key.test.arn +} + +resource "aws_finspace_kx_database" "test" { + name = %[1]q + environment_id =aws_finspace_kx_environment.test.id +} +`, rName) +} + +func testAccKxDatabaseConfig_description(rName, description string) string { + return fmt.Sprintf(` +resource "aws_kms_key" "test" { + description = %[1]q + deletion_window_in_days = 7 +} + +resource "aws_finspace_kx_environment" "test" { + name = %[1]q + kms_key_id =aws_kms_key.test.arn +} + +resource "aws_finspace_kx_database" "test" { + name = %[1]q + environment_id =aws_finspace_kx_environment.test.id + description = %[2]q +} +`, rName, description) +} + +func testAccKxDatabaseConfig_tags1(rName, tagKey1, tagValue1 string) string { + return fmt.Sprintf(` +resource "aws_kms_key" "test" { + description = %[1]q + deletion_window_in_days = 7 +} + +resource "aws_finspace_kx_environment" "test" { + name = %[1]q + kms_key_id =aws_kms_key.test.arn +} + +resource "aws_finspace_kx_database" "test" { + name = %[1]q + environment_id =aws_finspace_kx_environment.test.id + tags = { + %[2]q = %[3]q + } +} +`, rName, tagKey1, tagValue1) +} + +func testAccKxDatabaseConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return fmt.Sprintf(` +resource "aws_kms_key" "test" { + description = %[1]q + deletion_window_in_days = 7 +} + +resource "aws_finspace_kx_environment" "test" { + name = %[1]q + kms_key_id =aws_kms_key.test.arn +} + +resource "aws_finspace_kx_database" "test" { + name = %[1]q + environment_id =aws_finspace_kx_environment.test.id + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } +} +`, rName, tagKey1, tagValue1, tagKey2, tagValue2) +} diff --git a/website/docs/r/finspace_kx_database.html.markdown b/website/docs/r/finspace_kx_database.html.markdown new file mode 100644 index 00000000000..01288e004af --- /dev/null +++ b/website/docs/r/finspace_kx_database.html.markdown @@ -0,0 +1,62 @@ +--- +subcategory: "FinSpace" +layout: "aws" +page_title: "AWS: aws_finspace_kx_database" +description: |- + Terraform resource for managing an AWS FinSpace Kx Database. +--- + +# Resource: aws_finspace_kx_database + +Terraform resource for managing an AWS FinSpace Kx Database. + +## Example Usage + +### Basic Usage + +```terraform +resource "aws_kms_key" "example" { + description = "Example KMS Key" + deletion_window_in_days = 7 +} + +resource "aws_finspace_kx_environment" "example" { + name = "my-tf-kx-environment" + kms_key_id =aws_kms_key.example.arn +} + +resource "aws_finspace_kx_database" "example" { + environment_id = aws_finspace_kx_environment.example.id + name = "my-tf-kx-database" + description = "Example database description" +} +``` + +## Argument Reference + +The following arguments are required: + +* `name` - (Required) Name of the KX database. +* `environment_id` - (Required) Unique identifier for the KX environment. + +The following arguments are optional: + +* `description` - (Optional) Description of the KX database. +* `tags` - (Optional) List of key-value pairs to label the KX database. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `arn` - Amazon Resource Name (ARN) identifier of the KX database. +* `created_timestamp` - Timestamp at which the databse is created in FinSpace. Value determined as epoch time in seconds. For example, the value for Monday, November 1, 2021 12:00:00 PM UTC is specified as 1635768000. +* `last_modified_timestamp` - Last timestamp at which the database was updated in FinSpace. Value determined as epoch time in seconds. For example, the value for Monday, November 1, 2021 12:00:00 PM UTC is specified as 1635768000. +* `tags_all` - Map of tags assigned to the resource. + +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +* `create` - (Default `30m`) +* `update` - (Default `30m`) +* `delete` - (Default `30m`) From ab6d36e271e0a898f85bc6524974f2744dfcb868 Mon Sep 17 00:00:00 2001 From: Kavan Bansal Date: Tue, 6 Jun 2023 16:29:53 -0400 Subject: [PATCH 02/20] Ran make servicepackages --- internal/service/finspace/service_package_gen.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/service/finspace/service_package_gen.go b/internal/service/finspace/service_package_gen.go index 774ce1af3cb..62a8f2fa83b 100644 --- a/internal/service/finspace/service_package_gen.go +++ b/internal/service/finspace/service_package_gen.go @@ -24,7 +24,15 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac } func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { - return []*types.ServicePackageSDKResource{} + return []*types.ServicePackageSDKResource{ + { + Factory: ResourceKxDatabase, + TypeName: "aws_finspace_kx_database", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, + }, + } } func (p *servicePackage) ServicePackageName() string { From b966536e29d851092f352bbe0ded41dad4bf1275 Mon Sep 17 00:00:00 2001 From: Kavan Bansal Date: Wed, 7 Jun 2023 01:37:38 -0400 Subject: [PATCH 03/20] Formatting fixes for database --- internal/service/finspace/kx_database_test.go | 16 ++++++++-------- .../docs/r/finspace_kx_database.html.markdown | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index 2bc57207136..b7539966ee8 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -230,12 +230,12 @@ resource "aws_kms_key" "test" { resource "aws_finspace_kx_environment" "test" { name = %[1]q - kms_key_id =aws_kms_key.test.arn + kms_key_id = aws_kms_key.test.arn } resource "aws_finspace_kx_database" "test" { name = %[1]q - environment_id =aws_finspace_kx_environment.test.id + environment_id = aws_finspace_kx_environment.test.id } `, rName) } @@ -249,12 +249,12 @@ resource "aws_kms_key" "test" { resource "aws_finspace_kx_environment" "test" { name = %[1]q - kms_key_id =aws_kms_key.test.arn + kms_key_id = aws_kms_key.test.arn } resource "aws_finspace_kx_database" "test" { name = %[1]q - environment_id =aws_finspace_kx_environment.test.id + environment_id = aws_finspace_kx_environment.test.id description = %[2]q } `, rName, description) @@ -269,12 +269,12 @@ resource "aws_kms_key" "test" { resource "aws_finspace_kx_environment" "test" { name = %[1]q - kms_key_id =aws_kms_key.test.arn + kms_key_id = aws_kms_key.test.arn } resource "aws_finspace_kx_database" "test" { name = %[1]q - environment_id =aws_finspace_kx_environment.test.id + environment_id = aws_finspace_kx_environment.test.id tags = { %[2]q = %[3]q } @@ -291,12 +291,12 @@ resource "aws_kms_key" "test" { resource "aws_finspace_kx_environment" "test" { name = %[1]q - kms_key_id =aws_kms_key.test.arn + kms_key_id = aws_kms_key.test.arn } resource "aws_finspace_kx_database" "test" { name = %[1]q - environment_id =aws_finspace_kx_environment.test.id + environment_id = aws_finspace_kx_environment.test.id tags = { %[2]q = %[3]q %[4]q = %[5]q diff --git a/website/docs/r/finspace_kx_database.html.markdown b/website/docs/r/finspace_kx_database.html.markdown index 01288e004af..f11b6c9d90d 100644 --- a/website/docs/r/finspace_kx_database.html.markdown +++ b/website/docs/r/finspace_kx_database.html.markdown @@ -21,14 +21,14 @@ resource "aws_kms_key" "example" { } resource "aws_finspace_kx_environment" "example" { - name = "my-tf-kx-environment" - kms_key_id =aws_kms_key.example.arn + name = "my-tf-kx-environment" + kms_key_id = aws_kms_key.example.arn } resource "aws_finspace_kx_database" "example" { environment_id = aws_finspace_kx_environment.example.id - name = "my-tf-kx-database" - description = "Example database description" + name = "my-tf-kx-database" + description = "Example database description" } ``` From 17b26568f4ce258ea63184f91f9506801997dc8c Mon Sep 17 00:00:00 2001 From: Kavan Bansal Date: Wed, 7 Jun 2023 10:56:28 -0400 Subject: [PATCH 04/20] Formatting fixes to database tests --- internal/service/finspace/kx_database_test.go | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index b7539966ee8..cd132455e57 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -224,18 +224,18 @@ func testAccCheckKxDatabaseExists(name string, kxdatabase *finspace.GetKxDatabas func testAccKxDatabaseConfig_basic(rName string) string { return fmt.Sprintf(` resource "aws_kms_key" "test" { - description = %[1]q - deletion_window_in_days = 7 + description = %[1]q + deletion_window_in_days = 7 } resource "aws_finspace_kx_environment" "test" { - name = %[1]q - kms_key_id = aws_kms_key.test.arn + name = %[1]q + kms_key_id = aws_kms_key.test.arn } resource "aws_finspace_kx_database" "test" { - name = %[1]q - environment_id = aws_finspace_kx_environment.test.id + name = %[1]q + environment_id = aws_finspace_kx_environment.test.id } `, rName) } @@ -248,14 +248,14 @@ resource "aws_kms_key" "test" { } resource "aws_finspace_kx_environment" "test" { - name = %[1]q - kms_key_id = aws_kms_key.test.arn + name = %[1]q + kms_key_id = aws_kms_key.test.arn } resource "aws_finspace_kx_database" "test" { - name = %[1]q - environment_id = aws_finspace_kx_environment.test.id - description = %[2]q + name = %[1]q + environment_id = aws_finspace_kx_environment.test.id + description = %[2]q } `, rName, description) } @@ -273,8 +273,8 @@ resource "aws_finspace_kx_environment" "test" { } resource "aws_finspace_kx_database" "test" { - name = %[1]q - environment_id = aws_finspace_kx_environment.test.id + name = %[1]q + environment_id = aws_finspace_kx_environment.test.id tags = { %[2]q = %[3]q } @@ -290,16 +290,16 @@ resource "aws_kms_key" "test" { } resource "aws_finspace_kx_environment" "test" { - name = %[1]q - kms_key_id = aws_kms_key.test.arn + name = %[1]q + kms_key_id = aws_kms_key.test.arn } resource "aws_finspace_kx_database" "test" { - name = %[1]q - environment_id = aws_finspace_kx_environment.test.id + name = %[1]q + environment_id = aws_finspace_kx_environment.test.id tags = { %[2]q = %[3]q - %[4]q = %[5]q + %[4]q = %[5]q } } `, rName, tagKey1, tagValue1, tagKey2, tagValue2) From ace1bd783fd67d9569156c5bc933cf2f095e541d Mon Sep 17 00:00:00 2001 From: Kavan Bansal Date: Wed, 7 Jun 2023 12:24:40 -0400 Subject: [PATCH 05/20] Minor corrections to test formatting --- internal/service/finspace/kx_database_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index cd132455e57..dd012991ae8 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -229,8 +229,8 @@ resource "aws_kms_key" "test" { } resource "aws_finspace_kx_environment" "test" { - name = %[1]q - kms_key_id = aws_kms_key.test.arn + name = %[1]q + kms_key_id = aws_kms_key.test.arn } resource "aws_finspace_kx_database" "test" { @@ -248,7 +248,7 @@ resource "aws_kms_key" "test" { } resource "aws_finspace_kx_environment" "test" { - name = %[1]q + name = %[1]q kms_key_id = aws_kms_key.test.arn } @@ -268,8 +268,8 @@ resource "aws_kms_key" "test" { } resource "aws_finspace_kx_environment" "test" { - name = %[1]q - kms_key_id = aws_kms_key.test.arn + name = %[1]q + kms_key_id = aws_kms_key.test.arn } resource "aws_finspace_kx_database" "test" { @@ -290,7 +290,7 @@ resource "aws_kms_key" "test" { } resource "aws_finspace_kx_environment" "test" { - name = %[1]q + name = %[1]q kms_key_id = aws_kms_key.test.arn } From 941efa7e8b36ca64836e65452f2a671d2ccb1b0d Mon Sep 17 00:00:00 2001 From: Kavan Bansal <124836223+kavan-aws@users.noreply.github.com> Date: Wed, 7 Jun 2023 16:17:49 -0400 Subject: [PATCH 06/20] Update kx_database_test.go --- internal/service/finspace/kx_database_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index dd012991ae8..e5ccde41325 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -229,7 +229,7 @@ resource "aws_kms_key" "test" { } resource "aws_finspace_kx_environment" "test" { - name = %[1]q + name. = %[1]q kms_key_id = aws_kms_key.test.arn } @@ -255,7 +255,7 @@ resource "aws_finspace_kx_environment" "test" { resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id - description = %[2]q + description = %[2]q } `, rName, description) } From 408aca307e38c63014d9e9ae998738e09cca12d7 Mon Sep 17 00:00:00 2001 From: Kavan Bansal <124836223+kavan-aws@users.noreply.github.com> Date: Wed, 7 Jun 2023 16:18:11 -0400 Subject: [PATCH 07/20] Update kx_database_test.go --- internal/service/finspace/kx_database_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index e5ccde41325..1da33f5c681 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -229,7 +229,7 @@ resource "aws_kms_key" "test" { } resource "aws_finspace_kx_environment" "test" { - name. = %[1]q + name = %[1]q kms_key_id = aws_kms_key.test.arn } From d96c734e7346b2674ee4e7cd9cb2143f36bdc306 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 7 Jun 2023 20:52:31 -0400 Subject: [PATCH 08/20] r/aws_finspace_kx_database: alphabetize attributes --- internal/service/finspace/kx_database.go | 27 ++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/internal/service/finspace/kx_database.go b/internal/service/finspace/kx_database.go index 4129b8fe8af..2cf2611271a 100644 --- a/internal/service/finspace/kx_database.go +++ b/internal/service/finspace/kx_database.go @@ -46,15 +46,10 @@ func ResourceKxDatabase() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "last_modified_timestamp": { - Type: schema.TypeString, - Computed: true, - }, - "name": { + "description": { Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringLenBetween(3, 63), + Optional: true, + ValidateFunc: validation.StringLenBetween(1, 1000), }, "environment_id": { Type: schema.TypeString, @@ -62,14 +57,20 @@ func ResourceKxDatabase() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringLenBetween(1, 32), }, - "description": { + "last_modified_timestamp": { + Type: schema.TypeString, + Computed: true, + }, + "name": { Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 1000), + Required: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(3, 63), }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, + CustomizeDiff: verify.SetTagsDiff, } } From 0efbe5b2016561af13abc5a0d165dbf6c02e0dde Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 7 Jun 2023 20:58:32 -0400 Subject: [PATCH 09/20] r/aws_finspace_kx_database: crud handlers return diags --- internal/service/finspace/kx_database.go | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/internal/service/finspace/kx_database.go b/internal/service/finspace/kx_database.go index 2cf2611271a..e2002b4e5e3 100644 --- a/internal/service/finspace/kx_database.go +++ b/internal/service/finspace/kx_database.go @@ -80,6 +80,7 @@ const ( ) func resourceKxDatabaseCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).FinSpaceClient() in := &finspace.CreateKxDatabaseInput{ @@ -95,19 +96,20 @@ func resourceKxDatabaseCreate(ctx context.Context, d *schema.ResourceData, meta out, err := conn.CreateKxDatabase(ctx, in) if err != nil { - return create.DiagError(names.FinSpace, create.ErrActionCreating, ResNameKxDatabase, d.Get("name").(string), err) + return append(diags, create.DiagError(names.FinSpace, create.ErrActionCreating, ResNameKxDatabase, d.Get("name").(string), err)...) } if out == nil || out.DatabaseArn == nil { - return create.DiagError(names.FinSpace, create.ErrActionCreating, ResNameKxDatabase, d.Get("name").(string), errors.New("empty output")) + return append(diags, create.DiagError(names.FinSpace, create.ErrActionCreating, ResNameKxDatabase, d.Get("name").(string), errors.New("empty output"))...) } d.SetId(aws.ToString(out.EnvironmentId) + "," + aws.ToString(out.DatabaseName)) - return resourceKxDatabaseRead(ctx, d, meta) + return append(diags, resourceKxDatabaseRead(ctx, d, meta)...) } func resourceKxDatabaseRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).FinSpaceClient() out, err := findKxDatabaseByName(ctx, conn, d.Get("name").(string), d.Get("environment_id").(string)) @@ -115,11 +117,11 @@ func resourceKxDatabaseRead(ctx context.Context, d *schema.ResourceData, meta in if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] FinSpace KxDatabase (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.FinSpace, create.ErrActionReading, ResNameKxDatabase, d.Id(), err) + return append(diags, create.DiagError(names.FinSpace, create.ErrActionReading, ResNameKxDatabase, d.Id(), err)...) } d.Set("arn", out.DatabaseArn) @@ -129,10 +131,11 @@ func resourceKxDatabaseRead(ctx context.Context, d *schema.ResourceData, meta in d.Set("created_timestamp", out.CreatedTimestamp.String()) d.Set("last_modified_timestamp", out.LastModifiedTimestamp.String()) - return nil + return diags } func resourceKxDatabaseUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).FinSpaceClient() update := false @@ -148,19 +151,20 @@ func resourceKxDatabaseUpdate(ctx context.Context, d *schema.ResourceData, meta } if !update { - return nil + return diags } log.Printf("[DEBUG] Updating FinSpace KxDatabase (%s): %#v", d.Id(), in) _, err := conn.UpdateKxDatabase(ctx, in) if err != nil { - return create.DiagError(names.FinSpace, create.ErrActionUpdating, ResNameKxDatabase, d.Id(), err) + return append(diags, create.DiagError(names.FinSpace, create.ErrActionUpdating, ResNameKxDatabase, d.Id(), err)...) } - return resourceKxDatabaseRead(ctx, d, meta) + return append(diags, resourceKxDatabaseRead(ctx, d, meta)...) } func resourceKxDatabaseDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).FinSpaceClient() log.Printf("[INFO] Deleting FinSpace KxDatabase %s", d.Id()) @@ -173,13 +177,13 @@ func resourceKxDatabaseDelete(ctx context.Context, d *schema.ResourceData, meta if err != nil { var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.FinSpace, create.ErrActionDeleting, ResNameKxDatabase, d.Id(), err) + return append(diags, create.DiagError(names.FinSpace, create.ErrActionDeleting, ResNameKxDatabase, d.Id(), err)...) } - return nil + return diags } func findKxDatabaseByName(ctx context.Context, conn *finspace.Client, name string, environmentId string) (*finspace.GetKxDatabaseOutput, error) { From 860716d820a4b2fc391bcd1c9baaf103172359c0 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 7 Jun 2023 21:00:42 -0400 Subject: [PATCH 10/20] r/aws_finspace_kx_database: simplify update --- internal/service/finspace/kx_database.go | 27 ++++++++---------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/internal/service/finspace/kx_database.go b/internal/service/finspace/kx_database.go index e2002b4e5e3..37515a6fb70 100644 --- a/internal/service/finspace/kx_database.go +++ b/internal/service/finspace/kx_database.go @@ -138,26 +138,17 @@ func resourceKxDatabaseUpdate(ctx context.Context, d *schema.ResourceData, meta var diags diag.Diagnostics conn := meta.(*conns.AWSClient).FinSpaceClient() - update := false - - in := &finspace.UpdateKxDatabaseInput{ - EnvironmentId: aws.String(d.Get("environment_id").(string)), - DatabaseName: aws.String(d.Get("name").(string)), - } - if d.HasChanges("description") { - in.Description = aws.String(d.Get("description").(string)) - update = true - } - - if !update { - return diags - } + in := &finspace.UpdateKxDatabaseInput{ + EnvironmentId: aws.String(d.Get("environment_id").(string)), + DatabaseName: aws.String(d.Get("name").(string)), + Description: aws.String(d.Get("description").(string)), + } - log.Printf("[DEBUG] Updating FinSpace KxDatabase (%s): %#v", d.Id(), in) - _, err := conn.UpdateKxDatabase(ctx, in) - if err != nil { - return append(diags, create.DiagError(names.FinSpace, create.ErrActionUpdating, ResNameKxDatabase, d.Id(), err)...) + _, err := conn.UpdateKxDatabase(ctx, in) + if err != nil { + return append(diags, create.DiagError(names.FinSpace, create.ErrActionUpdating, ResNameKxDatabase, d.Id(), err)...) + } } return append(diags, resourceKxDatabaseRead(ctx, d, meta)...) From 43b406d25aa90e630c4c7339bb33bc065019109b Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 7 Jun 2023 21:11:48 -0400 Subject: [PATCH 11/20] r/aws_finspace_kx_database: find by id to support import --- internal/service/finspace/kx_database.go | 29 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/internal/service/finspace/kx_database.go b/internal/service/finspace/kx_database.go index 37515a6fb70..84ac4238ef3 100644 --- a/internal/service/finspace/kx_database.go +++ b/internal/service/finspace/kx_database.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -77,6 +78,8 @@ func ResourceKxDatabase() *schema.Resource { const ( ResNameKxDatabase = "Kx Database" + + kxDatabaseIDPartCount = 2 ) func resourceKxDatabaseCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -103,7 +106,16 @@ func resourceKxDatabaseCreate(ctx context.Context, d *schema.ResourceData, meta return append(diags, create.DiagError(names.FinSpace, create.ErrActionCreating, ResNameKxDatabase, d.Get("name").(string), errors.New("empty output"))...) } - d.SetId(aws.ToString(out.EnvironmentId) + "," + aws.ToString(out.DatabaseName)) + idParts := []string{ + aws.ToString(out.EnvironmentId), + aws.ToString(out.DatabaseName), + } + id, err := flex.FlattenResourceId(idParts, kxDatabaseIDPartCount, false) + if err != nil { + return append(diags, create.DiagError(names.FinSpace, create.ErrActionFlatteningResourceId, ResNameKxDatabase, d.Get("name").(string), err)...) + } + + d.SetId(id) return append(diags, resourceKxDatabaseRead(ctx, d, meta)...) } @@ -112,8 +124,7 @@ func resourceKxDatabaseRead(ctx context.Context, d *schema.ResourceData, meta in var diags diag.Diagnostics conn := meta.(*conns.AWSClient).FinSpaceClient() - out, err := findKxDatabaseByName(ctx, conn, d.Get("name").(string), d.Get("environment_id").(string)) - + out, err := findKxDatabaseByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] FinSpace KxDatabase (%s) not found, removing from state", d.Id()) d.SetId("") @@ -177,11 +188,17 @@ func resourceKxDatabaseDelete(ctx context.Context, d *schema.ResourceData, meta return diags } -func findKxDatabaseByName(ctx context.Context, conn *finspace.Client, name string, environmentId string) (*finspace.GetKxDatabaseOutput, error) { +func findKxDatabaseByID(ctx context.Context, conn *finspace.Client, id string) (*finspace.GetKxDatabaseOutput, error) { + parts, err := flex.ExpandResourceId(id, kxDatabaseIDPartCount, false) + if err != nil { + return nil, err + } + in := &finspace.GetKxDatabaseInput{ - DatabaseName: aws.String(name), - EnvironmentId: aws.String(environmentId), + EnvironmentId: aws.String(parts[0]), + DatabaseName: aws.String(parts[1]), } + out, err := conn.GetKxDatabase(ctx, in) if err != nil { var nfe *types.ResourceNotFoundException From ee043174501ef23ba53c8ce353b45ffe50f8500c Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 7 Jun 2023 21:14:21 -0400 Subject: [PATCH 12/20] r/aws_finspace_kx_database(test): terrafmt --- internal/service/finspace/kx_database_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index 1da33f5c681..0c4c340cf35 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -255,7 +255,7 @@ resource "aws_finspace_kx_environment" "test" { resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id - description = %[2]q + description = %[2]q } `, rName, description) } @@ -275,6 +275,7 @@ resource "aws_finspace_kx_environment" "test" { resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id + tags = { %[2]q = %[3]q } @@ -297,6 +298,7 @@ resource "aws_finspace_kx_environment" "test" { resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id + tags = { %[2]q = %[3]q %[4]q = %[5]q From b33a2c43a64706f3d141c80030bec93ad94573bf Mon Sep 17 00:00:00 2001 From: Kavan Bansal <124836223+kavan-aws@users.noreply.github.com> Date: Wed, 7 Jun 2023 23:25:52 -0400 Subject: [PATCH 13/20] Update kx_database_test.go --- internal/service/finspace/kx_database_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index 0c4c340cf35..d4cdebd0ba3 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -255,7 +255,7 @@ resource "aws_finspace_kx_environment" "test" { resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id - description = %[2]q + description. = %[2]q } `, rName, description) } From 03e1a67fc5ab43fe10ac8f4e88a0178b19e24141 Mon Sep 17 00:00:00 2001 From: Kavan Bansal <124836223+kavan-aws@users.noreply.github.com> Date: Wed, 7 Jun 2023 23:26:20 -0400 Subject: [PATCH 14/20] Update kx_database_test.go --- internal/service/finspace/kx_database_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index d4cdebd0ba3..cd9f1956e69 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -255,7 +255,7 @@ resource "aws_finspace_kx_environment" "test" { resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id - description. = %[2]q + description = %[2]q } `, rName, description) } From 10e7dcea7703b6a18f73bdda68ddaaaef8e919a1 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 8 Jun 2023 10:26:11 -0400 Subject: [PATCH 15/20] r/aws_finspace_kx_database(docs): add import section, document id attribute --- website/docs/r/finspace_kx_database.html.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/website/docs/r/finspace_kx_database.html.markdown b/website/docs/r/finspace_kx_database.html.markdown index f11b6c9d90d..0ecfabe41f1 100644 --- a/website/docs/r/finspace_kx_database.html.markdown +++ b/website/docs/r/finspace_kx_database.html.markdown @@ -50,6 +50,7 @@ In addition to all arguments above, the following attributes are exported: * `arn` - Amazon Resource Name (ARN) identifier of the KX database. * `created_timestamp` - Timestamp at which the databse is created in FinSpace. Value determined as epoch time in seconds. For example, the value for Monday, November 1, 2021 12:00:00 PM UTC is specified as 1635768000. +* `id` - A comma-delimited string joining environment ID and database name. * `last_modified_timestamp` - Last timestamp at which the database was updated in FinSpace. Value determined as epoch time in seconds. For example, the value for Monday, November 1, 2021 12:00:00 PM UTC is specified as 1635768000. * `tags_all` - Map of tags assigned to the resource. @@ -60,3 +61,11 @@ In addition to all arguments above, the following attributes are exported: * `create` - (Default `30m`) * `update` - (Default `30m`) * `delete` - (Default `30m`) + +## Import + +An AWS FinSpace Kx Database can be imported using the `id` (environment ID and database name, comma-delimited), e.g., + +``` +$ terraform import aws_finspace_kx_database.example n3ceo7wqxoxcti5tujqwzs,my-tf-kx-database +``` From 3a31e134d081c8dba7b9a61ee00ffa63e74046d1 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 8 Jun 2023 10:27:34 -0400 Subject: [PATCH 16/20] r/aws_finspace_kx_database(docs): use standard tags/tags_all descriptions --- website/docs/r/finspace_kx_database.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/finspace_kx_database.html.markdown b/website/docs/r/finspace_kx_database.html.markdown index 0ecfabe41f1..a9458eea0e6 100644 --- a/website/docs/r/finspace_kx_database.html.markdown +++ b/website/docs/r/finspace_kx_database.html.markdown @@ -36,13 +36,13 @@ resource "aws_finspace_kx_database" "example" { The following arguments are required: -* `name` - (Required) Name of the KX database. * `environment_id` - (Required) Unique identifier for the KX environment. +* `name` - (Required) Name of the KX database. The following arguments are optional: * `description` - (Optional) Description of the KX database. -* `tags` - (Optional) List of key-value pairs to label the KX database. +* `tags` - (Optional) Key-value mapping of resource tags. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ## Attributes Reference @@ -52,7 +52,7 @@ In addition to all arguments above, the following attributes are exported: * `created_timestamp` - Timestamp at which the databse is created in FinSpace. Value determined as epoch time in seconds. For example, the value for Monday, November 1, 2021 12:00:00 PM UTC is specified as 1635768000. * `id` - A comma-delimited string joining environment ID and database name. * `last_modified_timestamp` - Last timestamp at which the database was updated in FinSpace. Value determined as epoch time in seconds. For example, the value for Monday, November 1, 2021 12:00:00 PM UTC is specified as 1635768000. -* `tags_all` - Map of tags assigned to the resource. +* `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block). ## Timeouts From ddae2fe5d1413109fee936aabb465f84e26ba866 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 8 Jun 2023 10:30:37 -0400 Subject: [PATCH 17/20] r/aws_finspace_kx_database: import support --- internal/service/finspace/kx_database.go | 4 ++++ internal/service/finspace/kx_database_test.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/internal/service/finspace/kx_database.go b/internal/service/finspace/kx_database.go index 84ac4238ef3..76d16c7d165 100644 --- a/internal/service/finspace/kx_database.go +++ b/internal/service/finspace/kx_database.go @@ -32,6 +32,10 @@ func ResourceKxDatabase() *schema.Resource { UpdateWithoutTimeout: resourceKxDatabaseUpdate, DeleteWithoutTimeout: resourceKxDatabaseDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), Update: schema.DefaultTimeout(30 * time.Minute), diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index cd9f1956e69..cae43ad0b88 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -45,6 +45,11 @@ func TestAccFinSpaceKxDatabase_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "name", rName), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } From 56b7260d103ed48089bfa1fc3ddf76f17decbd70 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 8 Jun 2023 10:38:38 -0400 Subject: [PATCH 18/20] r/aws_finspace_kx_database(test): add base config --- internal/service/finspace/kx_database_test.go | 59 +++++++------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index cae43ad0b88..6d89e86ed0e 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -226,10 +226,9 @@ func testAccCheckKxDatabaseExists(name string, kxdatabase *finspace.GetKxDatabas } } -func testAccKxDatabaseConfig_basic(rName string) string { +func testAccKxDatabaseConfigBase(rName string) string { return fmt.Sprintf(` resource "aws_kms_key" "test" { - description = %[1]q deletion_window_in_days = 7 } @@ -237,46 +236,36 @@ resource "aws_finspace_kx_environment" "test" { name = %[1]q kms_key_id = aws_kms_key.test.arn } +`, rName) +} +func testAccKxDatabaseConfig_basic(rName string) string { + return acctest.ConfigCompose( + testAccKxDatabaseConfigBase(rName), + fmt.Sprintf(` resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id } -`, rName) +`, rName)) } func testAccKxDatabaseConfig_description(rName, description string) string { - return fmt.Sprintf(` -resource "aws_kms_key" "test" { - description = %[1]q - deletion_window_in_days = 7 -} - -resource "aws_finspace_kx_environment" "test" { - name = %[1]q - kms_key_id = aws_kms_key.test.arn -} - + return acctest.ConfigCompose( + testAccKxDatabaseConfigBase(rName), + fmt.Sprintf(` resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id description = %[2]q } -`, rName, description) +`, rName, description)) } func testAccKxDatabaseConfig_tags1(rName, tagKey1, tagValue1 string) string { - return fmt.Sprintf(` -resource "aws_kms_key" "test" { - description = %[1]q - deletion_window_in_days = 7 -} - -resource "aws_finspace_kx_environment" "test" { - name = %[1]q - kms_key_id = aws_kms_key.test.arn -} - + return acctest.ConfigCompose( + testAccKxDatabaseConfigBase(rName), + fmt.Sprintf(` resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id @@ -285,21 +274,13 @@ resource "aws_finspace_kx_database" "test" { %[2]q = %[3]q } } -`, rName, tagKey1, tagValue1) +`, rName, tagKey1, tagValue1)) } func testAccKxDatabaseConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return fmt.Sprintf(` -resource "aws_kms_key" "test" { - description = %[1]q - deletion_window_in_days = 7 -} - -resource "aws_finspace_kx_environment" "test" { - name = %[1]q - kms_key_id = aws_kms_key.test.arn -} - + return acctest.ConfigCompose( + testAccKxDatabaseConfigBase(rName), + fmt.Sprintf(` resource "aws_finspace_kx_database" "test" { name = %[1]q environment_id = aws_finspace_kx_environment.test.id @@ -309,5 +290,5 @@ resource "aws_finspace_kx_database" "test" { %[4]q = %[5]q } } -`, rName, tagKey1, tagValue1, tagKey2, tagValue2) +`, rName, tagKey1, tagValue1, tagKey2, tagValue2)) } From 3568a4dadaf559e1237f7f0ea44cf0481bbca151 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 8 Jun 2023 11:15:46 -0400 Subject: [PATCH 19/20] chore: changelog --- .changelog/31803.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/31803.txt diff --git a/.changelog/31803.txt b/.changelog/31803.txt new file mode 100644 index 00000000000..88d9e8aa57f --- /dev/null +++ b/.changelog/31803.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_finspace_kx_database +``` From 6073c27ceff305c4d8475d20818861392cafd912 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 8 Jun 2023 11:17:02 -0400 Subject: [PATCH 20/20] r/aws_finspace_kx_database(test): add ctx to check funcs --- internal/service/finspace/kx_database_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/service/finspace/kx_database_test.go b/internal/service/finspace/kx_database_test.go index 6d89e86ed0e..5dc02834ac0 100644 --- a/internal/service/finspace/kx_database_test.go +++ b/internal/service/finspace/kx_database_test.go @@ -41,7 +41,7 @@ func TestAccFinSpaceKxDatabase_basic(t *testing.T) { { Config: testAccKxDatabaseConfig_basic(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + testAccCheckKxDatabaseExists(ctx, resourceName, &kxdatabase), resource.TestCheckResourceAttr(resourceName, "name", rName), ), }, @@ -76,7 +76,7 @@ func TestAccFinSpaceKxDatabase_disappears(t *testing.T) { { Config: testAccKxDatabaseConfig_basic(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + testAccCheckKxDatabaseExists(ctx, resourceName, &kxdatabase), acctest.CheckResourceDisappears(ctx, acctest.Provider, tffinspace.ResourceKxDatabase(), resourceName), ), ExpectNonEmptyPlan: true, @@ -107,14 +107,14 @@ func TestAccFinSpaceKxDatabase_description(t *testing.T) { { Config: testAccKxDatabaseConfig_description(rName, "description 1"), Check: resource.ComposeTestCheckFunc( - testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + testAccCheckKxDatabaseExists(ctx, resourceName, &kxdatabase), resource.TestCheckResourceAttr(resourceName, "description", "description 1"), ), }, { Config: testAccKxDatabaseConfig_description(rName, "description 2"), Check: resource.ComposeTestCheckFunc( - testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + testAccCheckKxDatabaseExists(ctx, resourceName, &kxdatabase), resource.TestCheckResourceAttr(resourceName, "description", "description 2"), ), }, @@ -144,7 +144,7 @@ func TestAccFinSpaceKxDatabase_tags(t *testing.T) { { Config: testAccKxDatabaseConfig_tags1(rName, "key1", "value1"), Check: resource.ComposeTestCheckFunc( - testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + testAccCheckKxDatabaseExists(ctx, resourceName, &kxdatabase), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), ), @@ -152,7 +152,7 @@ func TestAccFinSpaceKxDatabase_tags(t *testing.T) { { Config: testAccKxDatabaseConfig_tags2(rName, "key1", "value1", "key2", "value2"), Check: resource.ComposeTestCheckFunc( - testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + testAccCheckKxDatabaseExists(ctx, resourceName, &kxdatabase), resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), @@ -161,7 +161,7 @@ func TestAccFinSpaceKxDatabase_tags(t *testing.T) { { Config: testAccKxDatabaseConfig_tags1(rName, "key2", "value2"), Check: resource.ComposeTestCheckFunc( - testAccCheckKxDatabaseExists(resourceName, &kxdatabase), + testAccCheckKxDatabaseExists(ctx, resourceName, &kxdatabase), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), ), @@ -198,7 +198,7 @@ func testAccCheckKxDatabaseDestroy(s *terraform.State) error { return nil } -func testAccCheckKxDatabaseExists(name string, kxdatabase *finspace.GetKxDatabaseOutput) resource.TestCheckFunc { +func testAccCheckKxDatabaseExists(ctx context.Context, name string, kxdatabase *finspace.GetKxDatabaseOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -210,7 +210,6 @@ func testAccCheckKxDatabaseExists(name string, kxdatabase *finspace.GetKxDatabas } conn := acctest.Provider.Meta().(*conns.AWSClient).FinSpaceClient() - ctx := context.Background() resp, err := conn.GetKxDatabase(ctx, &finspace.GetKxDatabaseInput{ DatabaseName: aws.String(rs.Primary.Attributes["name"]), EnvironmentId: aws.String(rs.Primary.Attributes["environment_id"]),