Skip to content

Commit 191165a

Browse files
authored
Merge pull request #35571 from prithvi514/f-lakeformation-resource-parameter
r/aws_lakeformation_resource: add hybrid_access_enabled argument
2 parents 28a70c6 + 40f8d83 commit 191165a

File tree

6 files changed

+158
-101
lines changed

6 files changed

+158
-101
lines changed

.changelog/35154.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
```release-note:enhancement
2-
resource/aws_lakeformation_resource: Add with_federation argument
2+
resource/aws_lakeformation_resource: Add `with_federation` argument
33
```

.changelog/35571.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_lakeformation_resource: Add `hybrid_access_enabled` argument
3+
```

internal/service/lakeformation/resource.go

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212
"github.com/aws/aws-sdk-go/service/lakeformation"
1313
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
15+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1516
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1617
"github.com/hashicorp/terraform-provider-aws/internal/conns"
1718
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
19+
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
1820
"github.com/hashicorp/terraform-provider-aws/internal/verify"
1921
)
2022

21-
// @SDKResource("aws_lakeformation_resource")
23+
// @SDKResource("aws_lakeformation_resource", name="Resource")
2224
func ResourceResource() *schema.Resource {
2325
return &schema.Resource{
2426
CreateWithoutTimeout: resourceResourceCreate,
@@ -32,6 +34,12 @@ func ResourceResource() *schema.Resource {
3234
ForceNew: true,
3335
ValidateFunc: verify.ValidARN,
3436
},
37+
"hybrid_access_enabled": {
38+
Type: schema.TypeBool,
39+
Optional: true,
40+
Computed: true,
41+
ForceNew: true,
42+
},
3543
"last_modified": {
3644
Type: schema.TypeString,
3745
Computed: true,
@@ -43,14 +51,15 @@ func ResourceResource() *schema.Resource {
4351
ForceNew: true,
4452
ValidateFunc: verify.ValidARN,
4553
},
46-
"with_federation": {
54+
"use_service_linked_role": {
4755
Type: schema.TypeBool,
4856
Optional: true,
49-
Computed: true,
57+
ForceNew: true,
5058
},
51-
"use_service_linked_role": {
59+
"with_federation": {
5260
Type: schema.TypeBool,
5361
Optional: true,
62+
Computed: true,
5463
ForceNew: true,
5564
},
5665
},
@@ -60,10 +69,14 @@ func ResourceResource() *schema.Resource {
6069
func resourceResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
6170
var diags diag.Diagnostics
6271
conn := meta.(*conns.AWSClient).LakeFormationConn(ctx)
63-
resourceArn := d.Get("arn").(string)
6472

73+
resourceARN := d.Get("arn").(string)
6574
input := &lakeformation.RegisterResourceInput{
66-
ResourceArn: aws.String(resourceArn),
75+
ResourceArn: aws.String(resourceARN),
76+
}
77+
78+
if v, ok := d.GetOk("hybrid_access_enabled"); ok {
79+
input.HybridAccessEnabled = aws.Bool(v.(bool))
6780
}
6881

6982
if v, ok := d.GetOk("role_arn"); ok {
@@ -72,78 +85,95 @@ func resourceResourceCreate(ctx context.Context, d *schema.ResourceData, meta in
7285
input.UseServiceLinkedRole = aws.Bool(true)
7386
}
7487

75-
if v, ok := d.GetOk("with_federation"); ok {
76-
input.WithFederation = aws.Bool(v.(bool))
77-
}
78-
7988
if v, ok := d.GetOk("use_service_linked_role"); ok {
8089
input.UseServiceLinkedRole = aws.Bool(v.(bool))
8190
}
8291

92+
if v, ok := d.GetOk("with_federation"); ok {
93+
input.WithFederation = aws.Bool(v.(bool))
94+
}
95+
8396
_, err := conn.RegisterResourceWithContext(ctx, input)
8497

8598
if tfawserr.ErrCodeEquals(err, lakeformation.ErrCodeAlreadyExistsException) {
86-
log.Printf("[WARN] Lake Formation Resource (%s) already exists", resourceArn)
99+
log.Printf("[WARN] Lake Formation Resource (%s) already exists", resourceARN)
87100
} else if err != nil {
88-
return sdkdiag.AppendErrorf(diags, "registering Lake Formation Resource (%s): %s", resourceArn, err)
101+
return sdkdiag.AppendErrorf(diags, "registering Lake Formation Resource (%s): %s", resourceARN, err)
89102
}
90103

91-
d.SetId(resourceArn)
104+
d.SetId(resourceARN)
105+
92106
return append(diags, resourceResourceRead(ctx, d, meta)...)
93107
}
94108

95109
func resourceResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
96110
var diags diag.Diagnostics
97111
conn := meta.(*conns.AWSClient).LakeFormationConn(ctx)
98-
resourceArn := d.Get("arn").(string)
99112

100-
input := &lakeformation.DescribeResourceInput{
101-
ResourceArn: aws.String(resourceArn),
102-
}
113+
resource, err := FindResourceByARN(ctx, conn, d.Id())
103114

104-
output, err := conn.DescribeResourceWithContext(ctx, input)
105-
106-
if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, lakeformation.ErrCodeEntityNotFoundException) {
115+
if !d.IsNewResource() && tfresource.NotFound(err) {
107116
log.Printf("[WARN] Resource Lake Formation Resource (%s) not found, removing from state", d.Id())
108117
d.SetId("")
109118
return diags
110119
}
111120

112121
if err != nil {
113-
return sdkdiag.AppendErrorf(diags, "reading resource Lake Formation Resource (%s): %s", d.Id(), err)
114-
}
115-
116-
if output == nil || output.ResourceInfo == nil {
117-
return sdkdiag.AppendErrorf(diags, "reading resource Lake Formation Resource (%s): empty response", d.Id())
122+
return sdkdiag.AppendErrorf(diags, "reading Lake Formation Resource (%s): %s", d.Id(), err)
118123
}
119124

120-
d.Set("with_federation", output.ResourceInfo.WithFederation)
121-
122-
// d.Set("arn", output.ResourceInfo.ResourceArn) // output not including resource arn currently
123-
d.Set("role_arn", output.ResourceInfo.RoleArn)
124-
if output.ResourceInfo.LastModified != nil { // output not including last modified currently
125-
d.Set("last_modified", output.ResourceInfo.LastModified.Format(time.RFC3339))
125+
d.Set("arn", d.Id())
126+
d.Set("hybrid_access_enabled", resource.HybridAccessEnabled)
127+
if v := resource.LastModified; v != nil { // output not including last modified currently
128+
d.Set("last_modified", v.Format(time.RFC3339))
126129
}
130+
d.Set("role_arn", resource.RoleArn)
131+
d.Set("with_federation", resource.WithFederation)
127132

128133
return diags
129134
}
130135

131136
func resourceResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
132137
var diags diag.Diagnostics
133138
conn := meta.(*conns.AWSClient).LakeFormationConn(ctx)
134-
resourceArn := d.Get("arn").(string)
135139

136-
input := &lakeformation.DeregisterResourceInput{
137-
ResourceArn: aws.String(resourceArn),
138-
}
140+
log.Printf("[INFO] Deleting Lake Formation Resource: %s", d.Id())
141+
_, err := conn.DeregisterResourceWithContext(ctx, &lakeformation.DeregisterResourceInput{
142+
ResourceArn: aws.String(d.Id()),
143+
})
139144

140-
_, err := conn.DeregisterResourceWithContext(ctx, input)
141145
if tfawserr.ErrCodeEquals(err, lakeformation.ErrCodeEntityNotFoundException) {
142146
return diags
143147
}
148+
144149
if err != nil {
145150
return sdkdiag.AppendErrorf(diags, "deregistering Lake Formation Resource (%s): %s", d.Id(), err)
146151
}
147152

148153
return diags
149154
}
155+
156+
func FindResourceByARN(ctx context.Context, conn *lakeformation.LakeFormation, arn string) (*lakeformation.ResourceInfo, error) {
157+
input := &lakeformation.DescribeResourceInput{
158+
ResourceArn: aws.String(arn),
159+
}
160+
161+
output, err := conn.DescribeResourceWithContext(ctx, input)
162+
163+
if tfawserr.ErrCodeEquals(err, lakeformation.ErrCodeEntityNotFoundException) {
164+
return nil, &retry.NotFoundError{
165+
LastError: err,
166+
LastRequest: input,
167+
}
168+
}
169+
170+
if err != nil {
171+
return nil, err
172+
}
173+
174+
if output == nil || output.ResourceInfo == nil {
175+
return nil, tfresource.NewEmptyResultError(input)
176+
}
177+
178+
return output.ResourceInfo, nil
179+
}

0 commit comments

Comments
 (0)