@@ -12,13 +12,15 @@ import (
12
12
"github.com/aws/aws-sdk-go/service/lakeformation"
13
13
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
14
14
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
15
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
15
16
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
16
17
"github.com/hashicorp/terraform-provider-aws/internal/conns"
17
18
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
19
+ "github.com/hashicorp/terraform-provider-aws/internal/tfresource"
18
20
"github.com/hashicorp/terraform-provider-aws/internal/verify"
19
21
)
20
22
21
- // @SDKResource("aws_lakeformation_resource")
23
+ // @SDKResource("aws_lakeformation_resource", name="Resource" )
22
24
func ResourceResource () * schema.Resource {
23
25
return & schema.Resource {
24
26
CreateWithoutTimeout : resourceResourceCreate ,
@@ -32,6 +34,12 @@ func ResourceResource() *schema.Resource {
32
34
ForceNew : true ,
33
35
ValidateFunc : verify .ValidARN ,
34
36
},
37
+ "hybrid_access_enabled" : {
38
+ Type : schema .TypeBool ,
39
+ Optional : true ,
40
+ Computed : true ,
41
+ ForceNew : true ,
42
+ },
35
43
"last_modified" : {
36
44
Type : schema .TypeString ,
37
45
Computed : true ,
@@ -43,14 +51,15 @@ func ResourceResource() *schema.Resource {
43
51
ForceNew : true ,
44
52
ValidateFunc : verify .ValidARN ,
45
53
},
46
- "with_federation " : {
54
+ "use_service_linked_role " : {
47
55
Type : schema .TypeBool ,
48
56
Optional : true ,
49
- Computed : true ,
57
+ ForceNew : true ,
50
58
},
51
- "use_service_linked_role " : {
59
+ "with_federation " : {
52
60
Type : schema .TypeBool ,
53
61
Optional : true ,
62
+ Computed : true ,
54
63
ForceNew : true ,
55
64
},
56
65
},
@@ -60,10 +69,14 @@ func ResourceResource() *schema.Resource {
60
69
func resourceResourceCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
61
70
var diags diag.Diagnostics
62
71
conn := meta .(* conns.AWSClient ).LakeFormationConn (ctx )
63
- resourceArn := d .Get ("arn" ).(string )
64
72
73
+ resourceARN := d .Get ("arn" ).(string )
65
74
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 ))
67
80
}
68
81
69
82
if v , ok := d .GetOk ("role_arn" ); ok {
@@ -72,78 +85,95 @@ func resourceResourceCreate(ctx context.Context, d *schema.ResourceData, meta in
72
85
input .UseServiceLinkedRole = aws .Bool (true )
73
86
}
74
87
75
- if v , ok := d .GetOk ("with_federation" ); ok {
76
- input .WithFederation = aws .Bool (v .(bool ))
77
- }
78
-
79
88
if v , ok := d .GetOk ("use_service_linked_role" ); ok {
80
89
input .UseServiceLinkedRole = aws .Bool (v .(bool ))
81
90
}
82
91
92
+ if v , ok := d .GetOk ("with_federation" ); ok {
93
+ input .WithFederation = aws .Bool (v .(bool ))
94
+ }
95
+
83
96
_ , err := conn .RegisterResourceWithContext (ctx , input )
84
97
85
98
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 )
87
100
} 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 )
89
102
}
90
103
91
- d .SetId (resourceArn )
104
+ d .SetId (resourceARN )
105
+
92
106
return append (diags , resourceResourceRead (ctx , d , meta )... )
93
107
}
94
108
95
109
func resourceResourceRead (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
96
110
var diags diag.Diagnostics
97
111
conn := meta .(* conns.AWSClient ).LakeFormationConn (ctx )
98
- resourceArn := d .Get ("arn" ).(string )
99
112
100
- input := & lakeformation.DescribeResourceInput {
101
- ResourceArn : aws .String (resourceArn ),
102
- }
113
+ resource , err := FindResourceByARN (ctx , conn , d .Id ())
103
114
104
- output , err := conn .DescribeResourceWithContext (ctx , input )
105
-
106
- if ! d .IsNewResource () && tfawserr .ErrCodeEquals (err , lakeformation .ErrCodeEntityNotFoundException ) {
115
+ if ! d .IsNewResource () && tfresource .NotFound (err ) {
107
116
log .Printf ("[WARN] Resource Lake Formation Resource (%s) not found, removing from state" , d .Id ())
108
117
d .SetId ("" )
109
118
return diags
110
119
}
111
120
112
121
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 )
118
123
}
119
124
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 ))
126
129
}
130
+ d .Set ("role_arn" , resource .RoleArn )
131
+ d .Set ("with_federation" , resource .WithFederation )
127
132
128
133
return diags
129
134
}
130
135
131
136
func resourceResourceDelete (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
132
137
var diags diag.Diagnostics
133
138
conn := meta .(* conns.AWSClient ).LakeFormationConn (ctx )
134
- resourceArn := d .Get ("arn" ).(string )
135
139
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
+ })
139
144
140
- _ , err := conn .DeregisterResourceWithContext (ctx , input )
141
145
if tfawserr .ErrCodeEquals (err , lakeformation .ErrCodeEntityNotFoundException ) {
142
146
return diags
143
147
}
148
+
144
149
if err != nil {
145
150
return sdkdiag .AppendErrorf (diags , "deregistering Lake Formation Resource (%s): %s" , d .Id (), err )
146
151
}
147
152
148
153
return diags
149
154
}
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