@@ -6,10 +6,12 @@ package finspace
6
6
import (
7
7
"context"
8
8
"errors"
9
+ "fmt"
9
10
"log"
10
11
"time"
11
12
12
13
"github.com/aws/aws-sdk-go-v2/aws"
14
+ "github.com/aws/aws-sdk-go-v2/aws/arn"
13
15
"github.com/aws/aws-sdk-go-v2/service/finspace"
14
16
"github.com/aws/aws-sdk-go-v2/service/finspace/types"
15
17
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -140,22 +142,25 @@ func resourceKxDataviewCreate(ctx context.Context, d *schema.ResourceData, meta
140
142
var diags diag.Diagnostics
141
143
conn := meta .(* conns.AWSClient ).FinSpaceClient (ctx )
142
144
145
+ environmentID := d .Get ("environment_id" ).(string )
146
+ databaseName := d .Get ("database_name" ).(string )
147
+ name := d .Get ("name" ).(string )
148
+
143
149
idParts := []string {
144
- d . Get ( "environment_id" ).( string ) ,
145
- d . Get ( "database_name" ).( string ) ,
146
- d . Get ( " name" ).( string ) ,
150
+ environmentID ,
151
+ databaseName ,
152
+ name ,
147
153
}
148
-
149
154
rId , err := flex .FlattenResourceId (idParts , kxDataviewIdPartCount , false )
150
155
if err != nil {
151
156
return create .AppendDiagError (diags , names .FinSpace , create .ErrActionFlatteningResourceId , ResNameKxDataview , d .Get ("name" ).(string ), err )
152
157
}
153
158
d .SetId (rId )
154
159
155
160
in := & finspace.CreateKxDataviewInput {
156
- DatabaseName : aws .String (d . Get ( "database_name" ).( string ) ),
157
- DataviewName : aws .String (d . Get ( " name" ).( string ) ),
158
- EnvironmentId : aws .String (d . Get ( "environment_id" ).( string ) ),
161
+ DatabaseName : aws .String (databaseName ),
162
+ DataviewName : aws .String (name ),
163
+ EnvironmentId : aws .String (environmentID ),
159
164
AutoUpdate : d .Get ("auto_update" ).(bool ),
160
165
AzMode : types .KxAzMode (d .Get ("az_mode" ).(string )),
161
166
ClientToken : aws .String (id .UniqueId ()),
@@ -190,17 +195,6 @@ func resourceKxDataviewCreate(ctx context.Context, d *schema.ResourceData, meta
190
195
return create .AppendDiagError (diags , names .FinSpace , create .ErrActionWaitingForCreation , ResNameKxDataview , d .Get ("name" ).(string ), err )
191
196
}
192
197
193
- // The CreateKxDataview API currently fails to tag the Dataview when the
194
- // Tags field is set. Until the API is fixed, tag after creation instead.
195
- //
196
- // TODO: the identifier passed to createTags here likely needs to be an ARN, but this attribute
197
- // is not returned from the create or describe APIs. The ARN may need to be manually constructed
198
- // in order for tag after create to function.
199
- //
200
- // if err := createTags(ctx, conn, aws.ToString(out.DataviewName), getTagsIn(ctx)); err != nil {
201
- // return create.AppendDiagError(diags, names.FinSpace, create.ErrActionCreating, ResNameKxDataview, d.Id(), err)
202
- // }
203
-
204
198
return append (diags , resourceKxDataviewRead (ctx , d , meta )... )
205
199
}
206
200
@@ -233,6 +227,19 @@ func resourceKxDataviewRead(ctx context.Context, d *schema.ResourceData, meta in
233
227
return create .AppendDiagError (diags , names .FinSpace , create .ErrActionReading , ResNameKxDataview , d .Id (), err )
234
228
}
235
229
230
+ // Manually construct the dataview ARN, which is not returned from the
231
+ // Create or Describe APIs.
232
+ //
233
+ // Ref: https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonfinspace.html#amazonfinspace-resources-for-iam-policies
234
+ dataviewARN := arn.ARN {
235
+ Partition : meta .(* conns.AWSClient ).Partition ,
236
+ Region : meta .(* conns.AWSClient ).Region ,
237
+ Service : names .FinSpace ,
238
+ AccountID : meta .(* conns.AWSClient ).AccountID ,
239
+ Resource : fmt .Sprintf ("kxEnvironment/%s/kxDatabase/%s/kxDataview/%s" , aws .ToString (out .EnvironmentId ), aws .ToString (out .DatabaseName ), aws .ToString (out .DataviewName )),
240
+ }.String ()
241
+ d .Set ("arn" , dataviewARN )
242
+
236
243
return diags
237
244
}
238
245
0 commit comments