@@ -12,6 +12,7 @@ import (
12
12
"github.com/hashicorp/terraform-plugin-framework/resource"
13
13
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
14
14
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
15
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
15
16
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
16
17
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
17
18
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -27,6 +28,7 @@ type resourceAWSAccountModel struct {
27
28
ID types.String `tfsdk:"id"`
28
29
StackID types.String `tfsdk:"stack_id"`
29
30
ResourceID types.String `tfsdk:"resource_id"`
31
+ Name types.String `tfsdk:"name"`
30
32
RoleARN types.String `tfsdk:"role_arn"`
31
33
Regions types.Set `tfsdk:"regions"`
32
34
}
@@ -90,6 +92,12 @@ func (r resourceAWSAccount) Schema(ctx context.Context, req resource.SchemaReque
90
92
stringplanmodifier .UseStateForUnknown (),
91
93
},
92
94
},
95
+ "name" : schema.StringAttribute {
96
+ Description : "An optional human-readable name for this AWS Account resource." ,
97
+ Optional : true ,
98
+ Computed : true , // used to complete the default "" if the resource existed before this field was introduced
99
+ Default : stringdefault .StaticString ("" ),
100
+ },
93
101
"role_arn" : schema.StringAttribute {
94
102
Description : "An IAM Role ARN string to represent with this AWS Account resource." ,
95
103
Required : true ,
@@ -134,6 +142,7 @@ func (r resourceAWSAccount) ImportState(ctx context.Context, req resource.Import
134
142
ID : types .StringValue (req .ID ),
135
143
StackID : types .StringValue (stackID ),
136
144
ResourceID : types .StringValue (resourceID ),
145
+ Name : types .StringValue (account .Name ),
137
146
RoleARN : types .StringValue (account .RoleARN ),
138
147
Regions : regions ,
139
148
})
@@ -149,6 +158,7 @@ func (r resourceAWSAccount) Create(ctx context.Context, req resource.CreateReque
149
158
150
159
accountData := cloudproviderapi.AWSAccount {}
151
160
accountData .RoleARN = data .RoleARN .ValueString ()
161
+ accountData .Name = data .Name .ValueString ()
152
162
diags = data .Regions .ElementsAs (ctx , & accountData .Regions , false )
153
163
resp .Diagnostics .Append (diags ... )
154
164
if resp .Diagnostics .HasError () {
@@ -168,6 +178,7 @@ func (r resourceAWSAccount) Create(ctx context.Context, req resource.CreateReque
168
178
ID : types .StringValue (resourceAWSAccountTerraformID .Make (data .StackID .ValueString (), account .ID )),
169
179
StackID : data .StackID ,
170
180
ResourceID : types .StringValue (account .ID ),
181
+ Name : data .Name ,
171
182
RoleARN : data .RoleARN ,
172
183
Regions : data .Regions ,
173
184
})
@@ -196,6 +207,11 @@ func (r resourceAWSAccount) Read(ctx context.Context, req resource.ReadRequest,
196
207
if resp .Diagnostics .HasError () {
197
208
return
198
209
}
210
+ diags = resp .State .SetAttribute (ctx , path .Root ("name" ), account .Name )
211
+ resp .Diagnostics .Append (diags ... )
212
+ if resp .Diagnostics .HasError () {
213
+ return
214
+ }
199
215
diags = resp .State .SetAttribute (ctx , path .Root ("regions" ), account .Regions )
200
216
resp .Diagnostics .Append (diags ... )
201
217
if resp .Diagnostics .HasError () {
@@ -213,6 +229,7 @@ func (r *resourceAWSAccount) Update(ctx context.Context, req resource.UpdateRequ
213
229
214
230
accountData := cloudproviderapi.AWSAccount {}
215
231
accountData .RoleARN = planData .RoleARN .ValueString ()
232
+ accountData .Name = planData .Name .ValueString ()
216
233
diags = planData .Regions .ElementsAs (ctx , & accountData .Regions , false )
217
234
resp .Diagnostics .Append (diags ... )
218
235
if resp .Diagnostics .HasError () {
@@ -234,6 +251,11 @@ func (r *resourceAWSAccount) Update(ctx context.Context, req resource.UpdateRequ
234
251
if resp .Diagnostics .HasError () {
235
252
return
236
253
}
254
+ diags = resp .State .SetAttribute (ctx , path .Root ("name" ), account .Name )
255
+ resp .Diagnostics .Append (diags ... )
256
+ if resp .Diagnostics .HasError () {
257
+ return
258
+ }
237
259
diags = resp .State .SetAttribute (ctx , path .Root ("regions" ), account .Regions )
238
260
resp .Diagnostics .Append (diags ... )
239
261
if resp .Diagnostics .HasError () {
0 commit comments