Skip to content

Commit ceb839f

Browse files
committed
r/aws_finspace_kx_dataview: compose syntheric arn on read
Properly setting the arn attribute will allow transparent tagging to properly list tags on the underlying data view during read operations. This should fix persistent diffs when setting tags for this resource.
1 parent 24cb0c3 commit ceb839f

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

.changelog/34998.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_finspace_kx_dataview: Properly set `arn` attribute on read, resolving persistent differences when `tags` are configured
3+
```

internal/service/finspace/kx_dataview.go

+25-18
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ package finspace
66
import (
77
"context"
88
"errors"
9+
"fmt"
910
"log"
1011
"time"
1112

1213
"github.com/aws/aws-sdk-go-v2/aws"
14+
"github.com/aws/aws-sdk-go-v2/aws/arn"
1315
"github.com/aws/aws-sdk-go-v2/service/finspace"
1416
"github.com/aws/aws-sdk-go-v2/service/finspace/types"
1517
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -140,22 +142,25 @@ func resourceKxDataviewCreate(ctx context.Context, d *schema.ResourceData, meta
140142
var diags diag.Diagnostics
141143
conn := meta.(*conns.AWSClient).FinSpaceClient(ctx)
142144

145+
environmentID := d.Get("environment_id").(string)
146+
databaseName := d.Get("database_name").(string)
147+
name := d.Get("name").(string)
148+
143149
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,
147153
}
148-
149154
rId, err := flex.FlattenResourceId(idParts, kxDataviewIdPartCount, false)
150155
if err != nil {
151156
return create.AppendDiagError(diags, names.FinSpace, create.ErrActionFlatteningResourceId, ResNameKxDataview, d.Get("name").(string), err)
152157
}
153158
d.SetId(rId)
154159

155160
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),
159164
AutoUpdate: d.Get("auto_update").(bool),
160165
AzMode: types.KxAzMode(d.Get("az_mode").(string)),
161166
ClientToken: aws.String(id.UniqueId()),
@@ -190,17 +195,6 @@ func resourceKxDataviewCreate(ctx context.Context, d *schema.ResourceData, meta
190195
return create.AppendDiagError(diags, names.FinSpace, create.ErrActionWaitingForCreation, ResNameKxDataview, d.Get("name").(string), err)
191196
}
192197

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-
204198
return append(diags, resourceKxDataviewRead(ctx, d, meta)...)
205199
}
206200

@@ -233,6 +227,19 @@ func resourceKxDataviewRead(ctx context.Context, d *schema.ResourceData, meta in
233227
return create.AppendDiagError(diags, names.FinSpace, create.ErrActionReading, ResNameKxDataview, d.Id(), err)
234228
}
235229

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+
236243
return diags
237244
}
238245

0 commit comments

Comments
 (0)