Skip to content

Commit 68c79cf

Browse files
authored
Merge pull request #43630 from hashicorp/f-aws_s3_access_point.tags
S3 Access Point tags
2 parents a089506 + 63745eb commit 68c79cf

File tree

8 files changed

+114
-5
lines changed

8 files changed

+114
-5
lines changed

.changelog/43630.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/aws_s3_access_point: Add `tags` argument and `tags_all` attribute. This functionality requires the `s3:ListTagsForResource`, `s3:TagResource`, and `s3:UntagResource` IAM permissions
3+
```
4+
5+
```release-note:enhancement
6+
data-source/aws_s3_access_point: Add `tags` attribute. This functionality requires the `s3:ListTagsForResource` IAM permission
7+
```

internal/service/s3control/access_point.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2323
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
2424
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
25+
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
2526
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
2627
"github.com/hashicorp/terraform-provider-aws/internal/verify"
2728
"github.com/hashicorp/terraform-provider-aws/names"
2829
)
2930

3031
// @SDKResource("aws_s3_access_point, name="Access Point")
32+
// @Tags(identifierAttribute="arn")
3133
func resourceAccessPoint() *schema.Resource {
3234
return &schema.Resource{
3335
CreateWithoutTimeout: resourceAccessPointCreate,
@@ -128,6 +130,8 @@ func resourceAccessPoint() *schema.Resource {
128130
},
129131
},
130132
},
133+
names.AttrTags: tftags.TagsSchema(),
134+
names.AttrTagsAll: tftags.TagsSchemaComputed(),
131135
names.AttrVPCConfiguration: {
132136
Type: schema.TypeList,
133137
Optional: true,
@@ -162,6 +166,7 @@ func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta
162166
AccountId: aws.String(accountID),
163167
Bucket: aws.String(d.Get(names.AttrBucket).(string)),
164168
Name: aws.String(name),
169+
Tags: getTagsIn(ctx),
165170
}
166171

167172
if v, ok := d.GetOk("bucket_account_id"); ok {

internal/service/s3control/access_point_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import (
1515
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
1616
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
1717
fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators"
18+
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
1819
"github.com/hashicorp/terraform-provider-aws/names"
1920
)
2021

2122
// @FrameworkDataSource("aws_s3_access_point", name="Access Point")
23+
// @Tags(identifierAttribute="arn")
2224
func newAccessPointDataSource(context.Context) (datasource.DataSourceWithConfigure, error) {
2325
return &accessPointDataSource{}, nil
2426
}
@@ -67,6 +69,7 @@ func (d *accessPointDataSource) Schema(ctx context.Context, request datasource.S
6769
Computed: true,
6870
},
6971
"public_access_block_configuration": framework.DataSourceComputedListOfObjectAttribute[publicAccessBlockConfigurationModel](ctx),
72+
names.AttrTags: tftags.TagsAttributeComputedOnly(),
7073
names.AttrVPCConfiguration: framework.DataSourceComputedListOfObjectAttribute[vpcConfigurationModel](ctx),
7174
},
7275
}
@@ -117,6 +120,7 @@ type accessPointDataSourceModel struct {
117120
Name types.String `tfsdk:"name"`
118121
NetworkOrigin types.String `tfsdk:"network_origin"`
119122
PublicAccessBlockConfiguration fwtypes.ListNestedObjectValueOf[publicAccessBlockConfigurationModel] `tfsdk:"public_access_block_configuration"`
123+
Tags tftags.Map `tfsdk:"tags"`
120124
VPCConfiguration fwtypes.ListNestedObjectValueOf[vpcConfigurationModel] `tfsdk:"vpc_configuration"`
121125
}
122126

internal/service/s3control/access_point_data_source_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestAccS3ControlAccessPointDataSource_basic(t *testing.T) {
3333
resource.TestCheckResourceAttrPair(resourceName, names.AttrBucket, dataSourceName, names.AttrBucket),
3434
resource.TestCheckResourceAttrPair(resourceName, "bucket_account_id", dataSourceName, "bucket_account_id"),
3535
resource.TestCheckResourceAttrPair(resourceName, names.AttrName, dataSourceName, names.AttrName),
36+
resource.TestCheckResourceAttrPair(resourceName, acctest.CtTagsPercent, dataSourceName, acctest.CtTagsPercent),
3637
resource.TestCheckResourceAttrPair(resourceName, "network_origin", dataSourceName, "network_origin"),
3738
),
3839
},
@@ -41,7 +42,7 @@ func TestAccS3ControlAccessPointDataSource_basic(t *testing.T) {
4142
}
4243

4344
func testAccAccessPointDataSourceConfig_basic(bucketName, accessPointName string) string {
44-
return acctest.ConfigCompose(testAccAccessPointConfig_basic(bucketName, accessPointName), `
45+
return acctest.ConfigCompose(testAccAccessPointConfig_tags1(bucketName, accessPointName, acctest.CtKey1, acctest.CtValue1), `
4546
data "aws_s3_access_point" "test" {
4647
name = aws_s3_access_point.test.name
4748
}

internal/service/s3control/access_point_test.go

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestAccS3ControlAccessPoint_basic(t *testing.T) {
4040
Steps: []resource.TestStep{
4141
{
4242
Config: testAccAccessPointConfig_basic(bucketName, accessPointName),
43-
Check: resource.ComposeTestCheckFunc(
43+
Check: resource.ComposeAggregateTestCheckFunc(
4444
testAccCheckAccessPointExists(ctx, resourceName, &v),
4545
acctest.CheckResourceAttrAccountID(ctx, resourceName, names.AttrAccountID),
4646
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-points-alias.html:
@@ -59,6 +59,7 @@ func TestAccS3ControlAccessPoint_basic(t *testing.T) {
5959
resource.TestCheckResourceAttr(resourceName, "public_access_block_configuration.0.block_public_policy", acctest.CtTrue),
6060
resource.TestCheckResourceAttr(resourceName, "public_access_block_configuration.0.ignore_public_acls", acctest.CtTrue),
6161
resource.TestCheckResourceAttr(resourceName, "public_access_block_configuration.0.restrict_public_buckets", acctest.CtTrue),
62+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
6263
resource.TestCheckResourceAttr(resourceName, "vpc_configuration.#", "0"),
6364
),
6465
},
@@ -359,6 +360,53 @@ func TestAccS3ControlAccessPoint_directoryBucket_basic(t *testing.T) {
359360
})
360361
}
361362

363+
func TestAccS3ControlAccessPoint_tags(t *testing.T) {
364+
ctx := acctest.Context(t)
365+
var v s3control.GetAccessPointOutput
366+
bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
367+
accessPointName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
368+
resourceName := "aws_s3_access_point.test"
369+
370+
resource.ParallelTest(t, resource.TestCase{
371+
PreCheck: func() { acctest.PreCheck(ctx, t) },
372+
ErrorCheck: acctest.ErrorCheck(t, names.S3ControlServiceID),
373+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
374+
CheckDestroy: testAccCheckAccessPointDestroy(ctx),
375+
Steps: []resource.TestStep{
376+
{
377+
Config: testAccAccessPointConfig_tags1(bucketName, accessPointName, acctest.CtKey1, acctest.CtValue1),
378+
Check: resource.ComposeTestCheckFunc(
379+
testAccCheckAccessPointExists(ctx, resourceName, &v),
380+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"),
381+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1),
382+
),
383+
},
384+
{
385+
ResourceName: resourceName,
386+
ImportState: true,
387+
ImportStateVerify: true,
388+
},
389+
{
390+
Config: testAccAccessPointConfig_tags2(bucketName, accessPointName, acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2),
391+
Check: resource.ComposeTestCheckFunc(
392+
testAccCheckAccessPointExists(ctx, resourceName, &v),
393+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "2"),
394+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated),
395+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2),
396+
),
397+
},
398+
{
399+
Config: testAccAccessPointConfig_tags1(bucketName, accessPointName, acctest.CtKey2, acctest.CtValue2),
400+
Check: resource.ComposeTestCheckFunc(
401+
testAccCheckAccessPointExists(ctx, resourceName, &v),
402+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"),
403+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2),
404+
),
405+
},
406+
},
407+
})
408+
}
409+
362410
func testAccCheckAccessPointDestroy(ctx context.Context) resource.TestCheckFunc {
363411
return func(s *terraform.State) error {
364412
conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx)
@@ -676,3 +724,38 @@ resource "aws_s3_access_point" "test" {
676724
}
677725
`, rName))
678726
}
727+
728+
func testAccAccessPointConfig_tags1(bucketName, accessPointName, tagKey1, tagValue1 string) string {
729+
return fmt.Sprintf(`
730+
resource "aws_s3_bucket" "test" {
731+
bucket = %[1]q
732+
}
733+
734+
resource "aws_s3_access_point" "test" {
735+
bucket = aws_s3_bucket.test.bucket
736+
name = %[2]q
737+
738+
tags = {
739+
%[3]q = %[4]q
740+
}
741+
}
742+
`, bucketName, accessPointName, tagKey1, tagValue1)
743+
}
744+
745+
func testAccAccessPointConfig_tags2(bucketName, accessPointName, tagKey1, tagValue1, tagKey2, tagValue2 string) string {
746+
return fmt.Sprintf(`
747+
resource "aws_s3_bucket" "test" {
748+
bucket = %[1]q
749+
}
750+
751+
resource "aws_s3_access_point" "test" {
752+
bucket = aws_s3_bucket.test.bucket
753+
name = %[2]q
754+
755+
tags = {
756+
%[3]q = %[4]q
757+
%[5]q = %[6]q
758+
}
759+
}
760+
`, bucketName, accessPointName, tagKey1, tagValue1, tagKey2, tagValue2)
761+
}

internal/service/s3control/service_package_gen.go

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/docs/d/s3_access_point.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ This data source exports the following attributes in addition to the arguments a
4343
* `block_public_policy` - Whether Amazon S3 blocks public bucket policies for buckets in this account.
4444
* `ignore_public_acls` - Whether Amazon S3 ignores public ACLs for buckets in this account.
4545
* `restrict_public_buckets` - Whether Amazon S3 restricts public bucket policies for buckets in this account.
46+
* `tags` - Tags assigned to the access point.
4647
* `vpc_configuration` - VPC configuration for the access point.
4748
* `vpc_id` - Access point will only allow connections from this VPC.

website/docs/r/s3_access_point.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ The following arguments are required:
8282

8383
The following arguments are optional:
8484

85-
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
8685
* `account_id` - (Optional) AWS account ID for the owner of the bucket for which you want to create an access point. Defaults to automatically determined account ID of the Terraform AWS provider.
8786
* `bucket_account_id` - (Optional) AWS account ID associated with the S3 bucket associated with this access point.
8887
* `policy` - (Optional) Valid JSON document that specifies the policy that you want to apply to this access point. Removing `policy` from your configuration or setting `policy` to null or an empty string (i.e., `policy = ""`) _will not_ delete the policy since it could have been set by `aws_s3control_access_point_policy`. To remove the `policy`, set it to `"{}"` (an empty JSON document).
8988
* `public_access_block_configuration` - (Optional) Configuration block to manage the `PublicAccessBlock` configuration that you want to apply to this Amazon S3 bucket. You can enable the configuration options in any combination. Detailed below.
89+
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
90+
* `tags` - (Optional) Map of tags to assign to the bucket. 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.
9091
* `vpc_configuration` - (Optional) Configuration block to restrict access to this access point to requests from the specified Virtual Private Cloud (VPC). Required for S3 on Outposts. Detailed below.
9192

9293
### public_access_block_configuration Configuration Block
@@ -122,6 +123,7 @@ Note: S3 access points only support secure access by HTTPS. HTTP isn't supported
122123
* `has_public_access_policy` - Indicates whether this access point currently has a policy that allows public access.
123124
* `id` - For Access Point of an AWS Partition S3 Bucket, the AWS account ID and access point name separated by a colon (`:`). For S3 on Outposts Bucket, the ARN of the Access Point.
124125
* `network_origin` - Indicates whether this access point allows access from the public Internet. Values are `VPC` (the access point doesn't allow access from the public Internet) and `Internet` (the access point allows access from the public Internet, subject to the access point and bucket access policies).
126+
* `tags_all` - 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).
125127

126128
## Import
127129

0 commit comments

Comments
 (0)