diff --git a/.changelog/36534.txt b/.changelog/36534.txt new file mode 100644 index 00000000000..065a0469664 --- /dev/null +++ b/.changelog/36534.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_cloudfrontkeyvaluestore_key +``` \ No newline at end of file diff --git a/.github/labeler-pr-triage.yml b/.github/labeler-pr-triage.yml index 5eedd44408f..d36d7553506 100644 --- a/.github/labeler-pr-triage.yml +++ b/.github/labeler-pr-triage.yml @@ -214,7 +214,7 @@ service/cloudfront: - 'website/**/cloudfront_*' service/cloudfrontkeyvaluestore: - 'internal/service/cloudfrontkeyvaluestore/**/*' - - 'website/**/cloudfront_keyvaluestore_*' + - 'website/**/cloudfrontkeyvaluestore_*' service/cloudhsmv2: - 'internal/service/cloudhsmv2/**/*' - 'website/**/cloudhsm*' diff --git a/internal/errs/fwdiag/diags.go b/internal/errs/fwdiag/diags.go index b90ccd941c8..a71d1d38519 100644 --- a/internal/errs/fwdiag/diags.go +++ b/internal/errs/fwdiag/diags.go @@ -44,3 +44,7 @@ func NewResourceNotFoundWarningDiagnostic(err error) diag.Diagnostic { "Automatically removing from Terraform State instead of returning the error, which may trigger resource recreation. Original error: "+err.Error(), ) } + +func AsErr[T any](x T, diags diag.Diagnostics) (T, error) { + return x, DiagnosticsError(diags) +} diff --git a/internal/errs/fwdiag/must.go b/internal/errs/fwdiag/must.go index 65d5b743692..448089b7553 100644 --- a/internal/errs/fwdiag/must.go +++ b/internal/errs/fwdiag/must.go @@ -14,5 +14,5 @@ import ( // [1]: https://pkg.go.dev/text/template#Must // [2]: https://pkg.go.dev/regexp#MustCompile func Must[T any](x T, diags diag.Diagnostics) T { - return errs.Must(x, DiagnosticsError(diags)) + return errs.Must(AsErr(x, diags)) } diff --git a/internal/service/cloudfrontkeyvaluestore/exports_test.go b/internal/service/cloudfrontkeyvaluestore/exports_test.go new file mode 100644 index 00000000000..0fd75747401 --- /dev/null +++ b/internal/service/cloudfrontkeyvaluestore/exports_test.go @@ -0,0 +1,11 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package cloudfrontkeyvaluestore + +// Exports for use in tests only. +var ( + ResourceKey = newKeyResource + + FindKeyByTwoPartKey = findKeyByTwoPartKey +) diff --git a/internal/service/cloudfrontkeyvaluestore/key.go b/internal/service/cloudfrontkeyvaluestore/key.go new file mode 100644 index 00000000000..6709e9ed240 --- /dev/null +++ b/internal/service/cloudfrontkeyvaluestore/key.go @@ -0,0 +1,319 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package cloudfrontkeyvaluestore + +import ( + "context" + "fmt" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudfrontkeyvaluestore" + awstypes "github.com/aws/aws-sdk-go-v2/service/cloudfrontkeyvaluestore/types" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" + "github.com/hashicorp/terraform-provider-aws/internal/flex" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// @FrameworkResource(name="Key") +func newKeyResource(_ context.Context) (resource.ResourceWithConfigure, error) { + r := &keyResource{} + + return r, nil +} + +type keyResource struct { + framework.ResourceWithConfigure + framework.WithImportByID +} + +func (*keyResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { + response.TypeName = "aws_cloudfrontkeyvaluestore_key" +} + +func (r *keyResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { + response.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + names.AttrID: framework.IDAttribute(), + "key": schema.StringAttribute{ + Required: true, + MarkdownDescription: "The key to put.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "key_value_store_arn": schema.StringAttribute{ + CustomType: fwtypes.ARNType, + Required: true, + MarkdownDescription: "The Amazon Resource Name (ARN) of the Key Value Store.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "total_size_in_bytes": schema.Int64Attribute{ + Computed: true, + MarkdownDescription: "Total size of the Key Value Store in bytes.", + }, + "value": schema.StringAttribute{ + Required: true, + MarkdownDescription: "The value to put.", + }, + }, + } +} + +func (r *keyResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + var data keyResourceModel + response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().CloudFrontKeyValueStoreClient(ctx) + + etag, err := findETagByARN(ctx, conn, data.KvsARN.ValueString()) + + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("reading CloudFront KeyValueStore ETag (%s)", data.KvsARN.ValueString()), err.Error()) + + return + } + + input := &cloudfrontkeyvaluestore.PutKeyInput{} + response.Diagnostics.Append(fwflex.Expand(ctx, data, input)...) + if response.Diagnostics.HasError() { + return + } + + // Additional fields. + input.IfMatch = etag + + output, err := conn.PutKey(ctx, input) + + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("creating CloudFront KeyValueStore (%s) Key (%s)", data.KvsARN.ValueString(), data.Key.ValueString()), err.Error()) + + return + } + + // Set values for unknowns. + data.TotalSizeInBytes = fwflex.Int64ToFramework(ctx, output.TotalSizeInBytes) + data.setID() + + response.Diagnostics.Append(response.State.Set(ctx, data)...) +} + +func (r *keyResource) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + var data keyResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + if err := data.InitFromID(); err != nil { + response.Diagnostics.AddError("parsing resource ID", err.Error()) + + return + } + + conn := r.Meta().CloudFrontKeyValueStoreClient(ctx) + + output, err := findKeyByTwoPartKey(ctx, conn, data.KvsARN.ValueString(), data.Key.ValueString()) + + if tfresource.NotFound(err) { + response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) + response.State.RemoveResource(ctx) + + return + } + + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("reading CloudFront KeyValueStore Key (%s)", data.ID.ValueString()), err.Error()) + + return + } + + // Set attributes for import. + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data)...) + if response.Diagnostics.HasError() { + return + } + + response.Diagnostics.Append(response.State.Set(ctx, &data)...) +} + +func (r *keyResource) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { + var old, new keyResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &old)...) + if response.Diagnostics.HasError() { + return + } + response.Diagnostics.Append(request.Plan.Get(ctx, &new)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().CloudFrontKeyValueStoreClient(ctx) + + if !new.Value.Equal(old.Value) { + etag, err := findETagByARN(ctx, conn, new.KvsARN.ValueString()) + + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("reading CloudFront KeyValueStore ETag (%s)", new.KvsARN.ValueString()), err.Error()) + + return + } + + input := &cloudfrontkeyvaluestore.PutKeyInput{} + response.Diagnostics.Append(fwflex.Expand(ctx, new, input)...) + if response.Diagnostics.HasError() { + return + } + + // Additional fields. + input.IfMatch = etag + + output, err := conn.PutKey(ctx, input) + + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("updating CloudFront KeyValueStore (%s) Key (%s)", new.KvsARN.ValueString(), new.Key.ValueString()), err.Error()) + + return + } + + // Set values for unknowns. + new.TotalSizeInBytes = fwflex.Int64ToFramework(ctx, output.TotalSizeInBytes) + } + + response.Diagnostics.Append(response.State.Set(ctx, &new)...) +} + +func (r *keyResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { + var data keyResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().CloudFrontKeyValueStoreClient(ctx) + + etag, err := findETagByARN(ctx, conn, data.KvsARN.ValueString()) + + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("reading CloudFront KeyValueStore ETag (%s)", data.KvsARN.ValueString()), err.Error()) + + return + } + + _, err = conn.DeleteKey(ctx, &cloudfrontkeyvaluestore.DeleteKeyInput{ + IfMatch: etag, + Key: fwflex.StringFromFramework(ctx, data.Key), + KvsARN: fwflex.StringFromFramework(ctx, data.KvsARN), + }) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return + } + + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("deleting CloudFront KeyValueStore Key (%s)", data.ID.ValueString()), err.Error()) + + return + } +} + +func findKeyByTwoPartKey(ctx context.Context, conn *cloudfrontkeyvaluestore.Client, kvsARN, key string) (*cloudfrontkeyvaluestore.GetKeyOutput, error) { + input := &cloudfrontkeyvaluestore.GetKeyInput{ + Key: aws.String(key), + KvsARN: aws.String(kvsARN), + } + + output, err := conn.GetKey(ctx, input) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || output.Key == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return output, nil +} + +func findETagByARN(ctx context.Context, conn *cloudfrontkeyvaluestore.Client, arn string) (*string, error) { + input := &cloudfrontkeyvaluestore.DescribeKeyValueStoreInput{ + KvsARN: aws.String(arn), + } + + output, err := conn.DescribeKeyValueStore(ctx, input) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || output.ETag == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return output.ETag, nil +} + +type keyResourceModel struct { + ID types.String `tfsdk:"id"` + Key types.String `tfsdk:"key"` + KvsARN fwtypes.ARN `tfsdk:"key_value_store_arn"` + TotalSizeInBytes types.Int64 `tfsdk:"total_size_in_bytes"` + Value types.String `tfsdk:"value"` +} + +const ( + keyResourceIDPartCount = 2 +) + +func (data *keyResourceModel) InitFromID() error { + id := data.ID.ValueString() + parts, err := flex.ExpandResourceId(id, keyResourceIDPartCount, false) + if err != nil { + return err + } + + v, err := fwdiag.AsErr(fwtypes.ARNValue(parts[0])) + if err != nil { + return err + } + + data.KvsARN = v + data.Key = types.StringValue(parts[1]) + + return nil +} + +func (data *keyResourceModel) setID() { + data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.KvsARN.ValueString(), data.Key.ValueString()}, keyResourceIDPartCount, false))) +} diff --git a/internal/service/cloudfrontkeyvaluestore/key_test.go b/internal/service/cloudfrontkeyvaluestore/key_test.go new file mode 100644 index 00000000000..4e4da7288cf --- /dev/null +++ b/internal/service/cloudfrontkeyvaluestore/key_test.go @@ -0,0 +1,184 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package cloudfrontkeyvaluestore_test + +import ( + "context" + "fmt" + "testing" + + 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" + tfcloudfrontkeyvaluestore "github.com/hashicorp/terraform-provider-aws/internal/service/cloudfrontkeyvaluestore" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccCloudFrontKeyValueStoreKey_basic(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + value := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_cloudfrontkeyvaluestore_key.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.CloudFront) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CloudFront), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKeyDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccKeyConfig_basic(rName, value), + Check: resource.ComposeTestCheckFunc( + testAccCheckKeyExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "key", rName), + resource.TestCheckResourceAttrSet(resourceName, "key_value_store_arn"), + resource.TestCheckResourceAttrSet(resourceName, "id"), + resource.TestCheckResourceAttrSet(resourceName, "total_size_in_bytes"), + resource.TestCheckResourceAttr(resourceName, "value", value), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccCloudFrontKeyValueStoreKey_value(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + value1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + value2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resourceName := "aws_cloudfrontkeyvaluestore_key.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.CloudFront) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CloudFront), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKeyDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccKeyConfig_basic(rName, value1), + Check: resource.ComposeTestCheckFunc( + testAccCheckKeyExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "key", rName), + resource.TestCheckResourceAttrSet(resourceName, "key_value_store_arn"), + resource.TestCheckResourceAttrSet(resourceName, "id"), + resource.TestCheckResourceAttrSet(resourceName, "total_size_in_bytes"), + resource.TestCheckResourceAttr(resourceName, "value", value1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccKeyConfig_basic(rName, value2), + Check: resource.ComposeTestCheckFunc( + testAccCheckKeyExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "key", rName), + resource.TestCheckResourceAttrSet(resourceName, "key_value_store_arn"), + resource.TestCheckResourceAttrSet(resourceName, "id"), + resource.TestCheckResourceAttrSet(resourceName, "total_size_in_bytes"), + resource.TestCheckResourceAttr(resourceName, "value", value2), + ), + }, + }, + }) +} + +func TestAccCloudFrontKeyValueStoreKey_disappears(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + value := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_cloudfrontkeyvaluestore_key.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.CloudFront) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CloudFront), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKeyDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccKeyConfig_basic(rName, value), + Check: resource.ComposeTestCheckFunc( + testAccCheckKeyExists(ctx, resourceName), + acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfcloudfrontkeyvaluestore.ResourceKey, resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testAccCheckKeyDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).CloudFrontKeyValueStoreClient(ctx) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_cloudfrontkeyvaluestore_key" { + continue + } + + _, err := tfcloudfrontkeyvaluestore.FindKeyByTwoPartKey(ctx, conn, rs.Primary.Attributes["key_value_store_arn"], rs.Primary.Attributes["key"]) + + if tfresource.NotFound(err) { + return nil + } + + if err != nil { + return err + } + + return fmt.Errorf("CloudFront KeyValueStore Key %s still exists", rs.Primary.ID) + } + + return nil + } +} + +func testAccCheckKeyExists(ctx context.Context, n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).CloudFrontKeyValueStoreClient(ctx) + + _, err := tfcloudfrontkeyvaluestore.FindKeyByTwoPartKey(ctx, conn, rs.Primary.Attributes["key_value_store_arn"], rs.Primary.Attributes["key"]) + + return err + } +} + +func testAccKeyConfig_basic(rName, value string) string { + return fmt.Sprintf(` +resource "aws_cloudfront_key_value_store" "test" { + name = %[1]q +} + +resource "aws_cloudfrontkeyvaluestore_key" "test" { + key = %[1]q + key_value_store_arn = aws_cloudfront_key_value_store.test.arn + value = %[2]q +} +`, rName, value) +} diff --git a/internal/service/cloudfrontkeyvaluestore/service_package_gen.go b/internal/service/cloudfrontkeyvaluestore/service_package_gen.go index 0688c5f8aef..e2fd3132ab7 100644 --- a/internal/service/cloudfrontkeyvaluestore/service_package_gen.go +++ b/internal/service/cloudfrontkeyvaluestore/service_package_gen.go @@ -19,7 +19,12 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv } func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { - return []*types.ServicePackageFrameworkResource{} + return []*types.ServicePackageFrameworkResource{ + { + Factory: newKeyResource, + Name: "Key", + }, + } } func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { diff --git a/names/data/names_data.csv b/names/data/names_data.csv index 2fb03065013..ca8e77bc4d1 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -62,7 +62,7 @@ servicediscovery,servicediscovery,servicediscovery,servicediscovery,,servicedisc cloud9,cloud9,cloud9,cloud9,,cloud9,,,Cloud9,Cloud9,,,2,,aws_cloud9_,,cloud9_,Cloud9,AWS,,,,,,,Cloud9,ListEnvironments,, cloudformation,cloudformation,cloudformation,cloudformation,,cloudformation,,,CloudFormation,CloudFormation,,1,,,aws_cloudformation_,,cloudformation_,CloudFormation,AWS,,,,,,,CloudFormation,ListStackInstances,, cloudfront,cloudfront,cloudfront,cloudfront,,cloudfront,,,CloudFront,CloudFront,,1,2,,aws_cloudfront_,,cloudfront_,CloudFront,Amazon,,,,,,,CloudFront,ListDistributions,, -cloudfront-keyvaluestore,cloudfrontkeyvaluestore,,cloudfrontkeyvaluestore,,cloudfrontkeyvaluestore,,,CloudFrontKeyValueStore,CloudFrontKeyValueStore,,,2,,aws_cloudfrontkeyvaluestore_,,cloudfront_keyvaluestore_,CloudFront KeyValueStore,Amazon,,,,,,,CloudFront KeyValueStore,ListKeys,"KvsARN: aws_sdkv2.String(""arn:aws:cloudfront::111122223333:key-value-store/MaxAge"")", +cloudfront-keyvaluestore,cloudfrontkeyvaluestore,,cloudfrontkeyvaluestore,,cloudfrontkeyvaluestore,,,CloudFrontKeyValueStore,CloudFrontKeyValueStore,,,2,,aws_cloudfrontkeyvaluestore_,,cloudfrontkeyvaluestore_,CloudFront KeyValueStore,Amazon,,,,,,,CloudFront KeyValueStore,ListKeys,"KvsARN: aws_sdkv2.String(""arn:aws:cloudfront::111122223333:key-value-store/MaxAge"")", cloudhsm,cloudhsm,cloudhsm,cloudhsm,,,,,,,,,,,,,,CloudHSM,AWS,x,,,,,,,,,Legacy cloudhsmv2,cloudhsmv2,cloudhsmv2,cloudhsmv2,,cloudhsmv2,,cloudhsm,CloudHSMV2,CloudHSMV2,x,,2,aws_cloudhsm_v2_,aws_cloudhsmv2_,,cloudhsm,CloudHSM,AWS,,,,,,,CloudHSM V2,DescribeClusters,, cloudsearch,cloudsearch,cloudsearch,cloudsearch,,cloudsearch,,,CloudSearch,CloudSearch,,,2,,aws_cloudsearch_,,cloudsearch_,CloudSearch,Amazon,,,,,,,CloudSearch,ListDomainNames,, diff --git a/website/docs/r/cloudfrontkeyvaluestore_key.html.markdown b/website/docs/r/cloudfrontkeyvaluestore_key.html.markdown new file mode 100644 index 00000000000..d8b18821b9e --- /dev/null +++ b/website/docs/r/cloudfrontkeyvaluestore_key.html.markdown @@ -0,0 +1,60 @@ +--- +subcategory: "CloudFront KeyValueStore" +layout: "aws" +page_title: "AWS: aws_cloudfrontkeyvaluestore_key" +description: |- + Terraform resource for managing an AWS CloudFront KeyValueStore Key. +--- + +# Resource: aws_cloudfrontkeyvaluestore_key + +Terraform resource for managing an AWS CloudFront KeyValueStore Key. + +## Example Usage + +### Basic Usage + +```terraform +resource "aws_cloudfront_key_value_store" "example" { + name = "ExampleKeyValueStore" + comment = "This is an example key value store" +} + +resource "aws_cloudfrontkeyvaluestore_key" "example" { + key_value_store_arn = aws_cloudfront_key_value_store.example.arn + key = "Test Key" + value = "Test Value" +} +``` + +## Argument Reference + +The following arguments are required: + +* `key` - (Required) Key to put. +* `key_value_store_arn` - (Required) Amazon Resource Name (ARN) of the Key Value Store. +* `value` - (Required) Value to put. + +## Attribute Reference + +This resource exports the following attributes in addition to the arguments above: + +* `id` - Combination of attributes separated by a `,` to create a unique id: `key_value_store_arn`,`key` +* `total_size_in_bytes` - Total size of the Key Value Store in bytes. + +## Import + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import CloudFront KeyValueStore Key using the `example_id_arg`. For example: + +```terraform +import { + to = aws_cloudfrontkeyvaluestore_key.example + id = "arn:aws:cloudfront::111111111111:key-value-store/8562g61f-caba-2845-9d99-b97diwae5d3c,someKey" +} +``` + +Using `terraform import`, import CloudFront KeyValueStore Key using the `id`. For example: + +```console +% terraform import aws_cloudfrontkeyvaluestore_key.example arn:aws:cloudfront::111111111111:key-value-store/8562g61f-caba-2845-9d99-b97diwae5d3c,someKey +```