Skip to content

Commit b30a437

Browse files
committed
Cosmetics.
1 parent c5f29c2 commit b30a437

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

internal/service/backup/logically_air_gapped_vault.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ func (r *logicallyAirGappedVaultResource) Schema(ctx context.Context, request re
5858
response.Schema = schema.Schema{
5959
Attributes: map[string]schema.Attribute{
6060
names.AttrARN: framework.ARNAttributeComputedOnly(),
61-
names.AttrID: framework.IDAttribute(),
61+
"encryption_key_arn": schema.StringAttribute{
62+
CustomType: fwtypes.ARNType,
63+
Optional: true,
64+
Computed: true,
65+
PlanModifiers: []planmodifier.String{
66+
stringplanmodifier.RequiresReplace(),
67+
},
68+
},
69+
names.AttrID: framework.IDAttribute(),
6270
"max_retention_days": schema.Int64Attribute{
6371
Required: true,
6472
PlanModifiers: []planmodifier.Int64{
@@ -74,14 +82,6 @@ func (r *logicallyAirGappedVaultResource) Schema(ctx context.Context, request re
7482
int64planmodifier.RequiresReplace(),
7583
},
7684
},
77-
"encryption_key_arn": schema.StringAttribute{
78-
CustomType: fwtypes.ARNType,
79-
Optional: true,
80-
Computed: true,
81-
PlanModifiers: []planmodifier.String{
82-
stringplanmodifier.RequiresReplace(),
83-
},
84-
},
8585
names.AttrName: schema.StringAttribute{
8686
Required: true,
8787
Validators: []validator.String{
@@ -111,9 +111,9 @@ func (r *logicallyAirGappedVaultResource) Create(ctx context.Context, request re
111111

112112
conn := r.Meta().BackupClient(ctx)
113113

114-
name := data.BackupVaultName.ValueString()
115-
input := &backup.CreateLogicallyAirGappedBackupVaultInput{}
116-
response.Diagnostics.Append(fwflex.Expand(ctx, data, input)...)
114+
name := fwflex.StringValueFromFramework(ctx, data.BackupVaultName)
115+
var input backup.CreateLogicallyAirGappedBackupVaultInput
116+
response.Diagnostics.Append(fwflex.Expand(ctx, data, &input)...)
117117
if response.Diagnostics.HasError() {
118118
return
119119
}
@@ -122,7 +122,7 @@ func (r *logicallyAirGappedVaultResource) Create(ctx context.Context, request re
122122
input.BackupVaultTags = getTagsIn(ctx)
123123
input.CreatorRequestId = aws.String(sdkid.UniqueId())
124124

125-
output, err := conn.CreateLogicallyAirGappedBackupVault(ctx, input)
125+
output, err := conn.CreateLogicallyAirGappedBackupVault(ctx, &input)
126126

127127
if err != nil {
128128
response.Diagnostics.AddError(fmt.Sprintf("creating Backup Logically Air Gapped Vault (%s)", name), err.Error())
@@ -132,12 +132,12 @@ func (r *logicallyAirGappedVaultResource) Create(ctx context.Context, request re
132132

133133
// Set values for unknowns.
134134
data.BackupVaultARN = fwflex.StringToFramework(ctx, output.BackupVaultArn)
135-
data.ID = fwflex.StringToFramework(ctx, output.BackupVaultName)
135+
data.ID = fwflex.StringValueToFramework(ctx, name)
136136

137-
vault, err := waitLogicallyAirGappedVaultCreated(ctx, conn, data.ID.ValueString(), r.CreateTimeout(ctx, data.Timeouts))
137+
vault, err := waitLogicallyAirGappedVaultCreated(ctx, conn, name, r.CreateTimeout(ctx, data.Timeouts))
138138
if err != nil {
139139
response.State.SetAttribute(ctx, path.Root(names.AttrID), data.ID) // Set 'id' so as to taint the resource.
140-
response.Diagnostics.AddError(fmt.Sprintf("waiting for Backup Logically Air Gapped Vault (%s) create", data.ID.ValueString()), err.Error())
140+
response.Diagnostics.AddError(fmt.Sprintf("waiting for Backup Logically Air Gapped Vault (%s) create", name), err.Error())
141141

142142
return
143143
}
@@ -159,7 +159,8 @@ func (r *logicallyAirGappedVaultResource) Read(ctx context.Context, request reso
159159

160160
conn := r.Meta().BackupClient(ctx)
161161

162-
output, err := findLogicallyAirGappedBackupVaultByName(ctx, conn, data.ID.ValueString())
162+
name := fwflex.StringValueFromFramework(ctx, data.ID)
163+
output, err := findLogicallyAirGappedBackupVaultByName(ctx, conn, name)
163164

164165
if tfresource.NotFound(err) {
165166
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
@@ -169,7 +170,7 @@ func (r *logicallyAirGappedVaultResource) Read(ctx context.Context, request reso
169170
}
170171

171172
if err != nil {
172-
response.Diagnostics.AddError(fmt.Sprintf("reading Backup Logically Air Gapped Vault (%s)", data.ID.ValueString()), err.Error())
173+
response.Diagnostics.AddError(fmt.Sprintf("reading Backup Logically Air Gapped Vault (%s)", name), err.Error())
173174

174175
return
175176
}
@@ -192,8 +193,9 @@ func (r *logicallyAirGappedVaultResource) Delete(ctx context.Context, request re
192193

193194
conn := r.Meta().BackupClient(ctx)
194195

196+
name := fwflex.StringValueFromFramework(ctx, data.ID)
195197
input := backup.DeleteBackupVaultInput{
196-
BackupVaultName: fwflex.StringFromFramework(ctx, data.ID),
198+
BackupVaultName: aws.String(name),
197199
}
198200
_, err := conn.DeleteBackupVault(ctx, &input)
199201

@@ -202,7 +204,7 @@ func (r *logicallyAirGappedVaultResource) Delete(ctx context.Context, request re
202204
}
203205

204206
if err != nil {
205-
response.Diagnostics.AddError(fmt.Sprintf("deleting Backup Logically Air Gapped Vault (%s)", data.ID.ValueString()), err.Error())
207+
response.Diagnostics.AddError(fmt.Sprintf("deleting Backup Logically Air Gapped Vault (%s)", name), err.Error())
206208

207209
return
208210
}
@@ -212,10 +214,10 @@ type logicallyAirGappedVaultResourceModel struct {
212214
framework.WithRegionModel
213215
BackupVaultARN types.String `tfsdk:"arn"`
214216
BackupVaultName types.String `tfsdk:"name"`
217+
EncryptionKeyARN fwtypes.ARN `tfsdk:"encryption_key_arn"`
215218
ID types.String `tfsdk:"id"`
216219
MaxRetentionDays types.Int64 `tfsdk:"max_retention_days"`
217220
MinRetentionDays types.Int64 `tfsdk:"min_retention_days"`
218-
EncryptionKeyArn fwtypes.ARN `tfsdk:"encryption_key_arn"`
219221
Tags tftags.Map `tfsdk:"tags"`
220222
TagsAll tftags.Map `tfsdk:"tags_all"`
221223
Timeouts timeouts.Value `tfsdk:"timeouts"`
@@ -261,7 +263,6 @@ func waitLogicallyAirGappedVaultCreated(ctx context.Context, conn *backup.Client
261263
}
262264

263265
outputRaw, err := stateConf.WaitForStateContext(ctx)
264-
265266
if output, ok := outputRaw.(*backup.DescribeBackupVaultOutput); ok {
266267
return output, err
267268
}

internal/service/backup/logically_air_gapped_vault_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/aws/aws-sdk-go-v2/service/backup"
12+
"github.com/hashicorp/terraform-plugin-testing/compare"
1213
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1314
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1415
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
@@ -88,7 +89,7 @@ func TestAccBackupLogicallyAirGappedVault_disappears(t *testing.T) {
8889
})
8990
}
9091

91-
func TestAccBackupLogicallyAirGappedVault_encryptionKeyArn(t *testing.T) {
92+
func TestAccBackupLogicallyAirGappedVault_encryptionKeyARN(t *testing.T) {
9293
ctx := acctest.Context(t)
9394
var v backup.DescribeBackupVaultOutput
9495
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
@@ -106,10 +107,12 @@ func TestAccBackupLogicallyAirGappedVault_encryptionKeyArn(t *testing.T) {
106107
CheckDestroy: testAccCheckLogicallyAirGappedVaultDestroy(ctx),
107108
Steps: []resource.TestStep{
108109
{
109-
Config: testAccLogicallyAirGappedVaultConfig_encryptionKeyArn(rName),
110+
Config: testAccLogicallyAirGappedVaultConfig_encryptionKeyARN(rName),
111+
ConfigStateChecks: []statecheck.StateCheck{
112+
statecheck.CompareValuePairs(resourceName, tfjsonpath.New("encryption_key_arn"), kmsKeyResourceName, tfjsonpath.New(names.AttrARN), compare.ValuesSame()),
113+
},
110114
Check: resource.ComposeTestCheckFunc(
111115
testAccCheckLogicallyAirGappedVaultExists(ctx, resourceName, &v),
112-
resource.TestCheckResourceAttrPair(resourceName, "encryption_key_arn", kmsKeyResourceName, names.AttrARN),
113116
),
114117
},
115118
{
@@ -235,7 +238,7 @@ resource "aws_backup_logically_air_gapped_vault" "test" {
235238
`, rName)
236239
}
237240

238-
func testAccLogicallyAirGappedVaultConfig_encryptionKeyArn(rName string) string {
241+
func testAccLogicallyAirGappedVaultConfig_encryptionKeyARN(rName string) string {
239242
return fmt.Sprintf(`
240243
resource "aws_kms_key" "test" {
241244
description = %[1]q

internal/service/backup/vault.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ func findBackupVaultByName(ctx context.Context, conn *backup.Client, name string
218218
}
219219

220220
func findVaultByName(ctx context.Context, conn *backup.Client, name string) (*backup.DescribeBackupVaultOutput, error) {
221-
input := &backup.DescribeBackupVaultInput{
221+
input := backup.DescribeBackupVaultInput{
222222
BackupVaultName: aws.String(name),
223223
}
224224

225-
output, err := findVault(ctx, conn, input)
225+
output, err := findVault(ctx, conn, &input)
226226

227227
if err != nil {
228228
return nil, err

0 commit comments

Comments
 (0)