Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_lakeformation_resource: add use_service_linked_role argument #35284

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/35284.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_lakeformation_resource: Add `use_service_linked_role` argument
```
12 changes: 12 additions & 0 deletions internal/service/lakeformation/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func ResourceResource() *schema.Resource {
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
"use_service_linked_role": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
},
}
}
Expand All @@ -62,6 +67,10 @@ func resourceResourceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.UseServiceLinkedRole = aws.Bool(true)
}

if v, ok := d.GetOk("use_service_linked_role"); ok {
input.UseServiceLinkedRole = aws.Bool(v.(bool))
}

_, err := conn.RegisterResourceWithContext(ctx, input)

if tfawserr.ErrCodeEquals(err, lakeformation.ErrCodeAlreadyExistsException) {
Expand Down Expand Up @@ -118,6 +127,9 @@ func resourceResourceDelete(ctx context.Context, d *schema.ResourceData, meta in
}

_, err := conn.DeregisterResourceWithContext(ctx, input)
if tfawserr.ErrCodeEquals(err, lakeformation.ErrCodeEntityNotFoundException) {
return diags
}
if err != nil {
return sdkdiag.AppendErrorf(diags, "deregistering Lake Formation Resource (%s): %s", d.Id(), err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/service/lakeformation/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ resource "aws_s3_bucket" "test" {
}

resource "aws_lakeformation_resource" "test" {
arn = aws_s3_bucket.test.arn
arn = aws_s3_bucket.test.arn
use_service_linked_role = true
}
`, rName)
}
17 changes: 13 additions & 4 deletions website/docs/r/lakeformation_resource.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ description: |-

Registers a Lake Formation resource (e.g., S3 bucket) as managed by the Data Catalog. In other words, the S3 path is added to the data lake.

Choose a role that has read/write access to the chosen Amazon S3 path or use the service-linked role. When you register the S3 path, the service-linked role and a new inline policy are created on your behalf. Lake Formation adds the first path to the inline policy and attaches it to the service-linked role. When you register subsequent paths, Lake Formation adds the path to the existing policy.
Choose a role that has read/write access to the chosen Amazon S3 path or use the service-linked role.
When you register the S3 path, the service-linked role and a new inline policy are created on your behalf.
Lake Formation adds the first path to the inline policy and attaches it to the service-linked role.
When you register subsequent paths, Lake Formation adds the path to the existing policy.

## Example Usage

Expand All @@ -26,13 +29,19 @@ resource "aws_lakeformation_resource" "example" {

## Argument Reference

* `arn` – (Required) Amazon Resource Name (ARN) of the resource, an S3 path.
* `role_arn` – (Optional) Role that has read/write access to the resource. If not provided, the Lake Formation service-linked role must exist and is used.
The following arguments are required:

* `arn` – (Required) Amazon Resource Name (ARN) of the resource.

The following arguments are optional:

* `role_arn` – (Optional) Role that has read/write access to the resource.
* `use_service_linked_role` - (Optional) Designates an AWS Identity and Access Management (IAM) service-linked role by registering this role with the Data Catalog.

~> **NOTE:** AWS does not support registering an S3 location with an IAM role and subsequently updating the S3 location registration to a service-linked role.

## Attribute Reference

This resource exports the following attributes in addition to the arguments above:

* `last_modified` - (Optional) The date and time the resource was last modified in [RFC 3339 format](https://tools.ietf.org/html/rfc3339#section-5.8).
* `last_modified` - Date and time the resource was last modified in [RFC 3339 format](https://tools.ietf.org/html/rfc3339#section-5.8).
Loading