Skip to content

Commit 6c33c55

Browse files
committed
r/aws_cloudfront_trust_store: Add 'tags'.
1 parent 9ea541d commit 6c33c55

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed

internal/service/cloudfront/service_package_gen.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/cloudfront/trust_store.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ import (
2929
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
3030
"github.com/hashicorp/terraform-provider-aws/internal/retry"
3131
"github.com/hashicorp/terraform-provider-aws/internal/smerr"
32+
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
3233
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
3334
"github.com/hashicorp/terraform-provider-aws/names"
3435
)
3536

3637
// @FrameworkResource("aws_cloudfront_trust_store", name="Trust Store")
38+
// @Tags(identifierAttribute="arn")
39+
// @Testing(tagsTest=false)
3740
func newTrustStoreResource(_ context.Context) (resource.ResourceWithConfigure, error) {
3841
r := &trustStoreResource{}
3942

@@ -67,6 +70,8 @@ func (r *trustStoreResource) Schema(ctx context.Context, req resource.SchemaRequ
6770
"number_of_ca_certificates": schema.Int32Attribute{
6871
Computed: true,
6972
},
73+
names.AttrTags: tftags.TagsAttribute(),
74+
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
7075
},
7176
Blocks: map[string]schema.Block{
7277
"ca_certificates_bundle_source": schema.ListNestedBlock{
@@ -128,6 +133,13 @@ func (r *trustStoreResource) Create(ctx context.Context, req resource.CreateRequ
128133
return
129134
}
130135

136+
// Additional fields.
137+
if tags := getTagsIn(ctx); len(tags) > 0 {
138+
input.Tags = &awstypes.Tags{
139+
Items: tags,
140+
}
141+
}
142+
131143
outCTS, err := conn.CreateTrustStore(ctx, &input)
132144
if err != nil {
133145
smerr.AddError(ctx, &resp.Diagnostics, err, smerr.ID, name)
@@ -348,6 +360,8 @@ type trustStoreResourceModel struct {
348360
ID types.String `tfsdk:"id"`
349361
Name types.String `tfsdk:"name"`
350362
NumberOfCACertificates types.Int32 `tfsdk:"number_of_ca_certificates"`
363+
Tags tftags.Map `tfsdk:"tags"`
364+
TagsAll tftags.Map `tfsdk:"tags_all"`
351365
Timeouts timeouts.Value `tfsdk:"timeouts"`
352366
}
353367

internal/service/cloudfront/trust_store_test.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestAccCloudFrontTrustStore_basic(t *testing.T) {
5555
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrARN), tfknownvalue.GlobalARNRegexp("cloudfront", regexache.MustCompile(`trust-store/.+`))),
5656
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("etag"), knownvalue.NotNull()),
5757
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("number_of_ca_certificates"), knownvalue.Int32Exact(1)),
58+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()),
5859
},
5960
},
6061
{
@@ -195,6 +196,83 @@ func TestAccCloudFrontTrustStore_update(t *testing.T) {
195196
})
196197
}
197198

199+
func TestAccCloudFrontTrustStore_tags(t *testing.T) {
200+
ctx := acctest.Context(t)
201+
var truststore cloudfront.GetTrustStoreOutput
202+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
203+
resourceName := "aws_cloudfront_trust_store.test"
204+
objectKey := "ca-bundle.pem"
205+
206+
resource.ParallelTest(t, resource.TestCase{
207+
PreCheck: func() {
208+
acctest.PreCheck(ctx, t)
209+
acctest.PreCheckPartitionHasService(t, names.CloudFrontEndpointID)
210+
},
211+
ErrorCheck: acctest.ErrorCheck(t, names.CloudFrontServiceID),
212+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
213+
CheckDestroy: testAccCheckTrustStoreDestroy(ctx),
214+
Steps: []resource.TestStep{
215+
{
216+
Config: testAccTrustStoreConfig_tags1(rName, objectKey, acctest.CtKey1, acctest.CtValue1),
217+
Check: resource.ComposeTestCheckFunc(
218+
testAccCheckTrustStoreExists(ctx, resourceName, &truststore),
219+
),
220+
ConfigPlanChecks: resource.ConfigPlanChecks{
221+
PreApply: []plancheck.PlanCheck{
222+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
223+
},
224+
},
225+
ConfigStateChecks: []statecheck.StateCheck{
226+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{
227+
acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1),
228+
})),
229+
},
230+
},
231+
{
232+
ResourceName: resourceName,
233+
ImportState: true,
234+
ImportStateVerify: true,
235+
ImportStateVerifyIgnore: []string{
236+
"ca_certificates_bundle_source",
237+
},
238+
},
239+
{
240+
Config: testAccTrustStoreConfig_tags2(rName, objectKey, acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2),
241+
Check: resource.ComposeTestCheckFunc(
242+
testAccCheckTrustStoreExists(ctx, resourceName, &truststore),
243+
),
244+
ConfigPlanChecks: resource.ConfigPlanChecks{
245+
PreApply: []plancheck.PlanCheck{
246+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
247+
},
248+
},
249+
ConfigStateChecks: []statecheck.StateCheck{
250+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{
251+
acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated),
252+
acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2),
253+
})),
254+
},
255+
},
256+
{
257+
Config: testAccTrustStoreConfig_tags1(rName, objectKey, acctest.CtKey2, acctest.CtValue2),
258+
Check: resource.ComposeTestCheckFunc(
259+
testAccCheckTrustStoreExists(ctx, resourceName, &truststore),
260+
),
261+
ConfigPlanChecks: resource.ConfigPlanChecks{
262+
PreApply: []plancheck.PlanCheck{
263+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
264+
},
265+
},
266+
ConfigStateChecks: []statecheck.StateCheck{
267+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{
268+
acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2),
269+
})),
270+
},
271+
},
272+
},
273+
})
274+
}
275+
198276
func testAccCheckTrustStoreDestroy(ctx context.Context) resource.TestCheckFunc {
199277
return func(s *terraform.State) error {
200278
conn := acctest.Provider.Meta().(*conns.AWSClient).CloudFrontClient(ctx)
@@ -363,3 +441,60 @@ resource "aws_cloudfront_trust_store" "test" {
363441
}
364442
`, rName, key, testAccTrustStoreCertificateContent))
365443
}
444+
445+
func testAccTrustStoreConfig_tags1(rName, key, tagKey1, tagValue1 string) string {
446+
return acctest.ConfigCompose(testAccTrustStoreConfig_base(rName), fmt.Sprintf(`
447+
resource "aws_s3_object" "test" {
448+
bucket = aws_s3_bucket.test.id
449+
key = %[2]q
450+
content = <<-EOT
451+
%[3]s
452+
EOT
453+
}
454+
455+
resource "aws_cloudfront_trust_store" "test" {
456+
name = %[1]q
457+
458+
ca_certificates_bundle_source {
459+
ca_certificates_bundle_s3_location {
460+
bucket = aws_s3_bucket.test.id
461+
key = aws_s3_object.test.key
462+
region = data.aws_region.current.name
463+
}
464+
}
465+
466+
tags = {
467+
%[4]q = %[5]q
468+
}
469+
}
470+
`, rName, key, testAccTrustStoreCertificateContent, tagKey1, tagValue1))
471+
}
472+
473+
func testAccTrustStoreConfig_tags2(rName, key, tagKey1, tagValue1, tagKey2, tagValue2 string) string {
474+
return acctest.ConfigCompose(testAccTrustStoreConfig_base(rName), fmt.Sprintf(`
475+
resource "aws_s3_object" "test" {
476+
bucket = aws_s3_bucket.test.id
477+
key = %[2]q
478+
content = <<-EOT
479+
%[3]s
480+
EOT
481+
}
482+
483+
resource "aws_cloudfront_trust_store" "test" {
484+
name = %[1]q
485+
486+
ca_certificates_bundle_source {
487+
ca_certificates_bundle_s3_location {
488+
bucket = aws_s3_bucket.test.id
489+
key = aws_s3_object.test.key
490+
region = data.aws_region.current.name
491+
}
492+
}
493+
494+
tags = {
495+
%[4]q = %[5]q
496+
%[6]q = %[7]q
497+
}
498+
}
499+
`, rName, key, testAccTrustStoreCertificateContent, tagKey1, tagValue1, tagKey2, tagValue2))
500+
}

website/docs/r/cloudfront_trust_store.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ The following arguments are required:
5252
* `name` - (Required) Name of the trust store. Changing this forces a new resource to be created.
5353
* `ca_certificates_bundle_source` - (Required) Configuration block for the CA certificates bundle source. See [`ca_certificates_bundle_source`](#ca_certificates_bundle_source) below.
5454

55+
The following arguments are optional:
56+
57+
* `tags` - (Optional) Key-value tags for the place index. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
58+
5559
### ca_certificates_bundle_source
5660

5761
* `ca_certificates_bundle_s3_location` - (Required) Configuration block for the S3 location of the CA certificates bundle. See [`ca_certificates_bundle_s3_location`](#ca_certificates_bundle_s3_location) below.
@@ -71,6 +75,7 @@ This resource exports the following attributes in addition to the arguments abov
7175
* `etag` - ETag of the trust store.
7276
* `id` - ID of the trust store.
7377
* `number_of_ca_certificates` - Number of CA certificates in the trust store.
78+
* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).
7479

7580
## Timeouts
7681

0 commit comments

Comments
 (0)