@@ -12,6 +12,7 @@ import (
1212 "github.com/hashicorp/terraform-plugin-framework/resource"
1313 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
1414 "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
15+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
1516 "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1617 "github.com/hashicorp/terraform-plugin-framework/schema/validator"
1718 "github.com/hashicorp/terraform-plugin-framework/types"
@@ -27,6 +28,7 @@ type resourceAWSAccountModel struct {
2728 ID types.String `tfsdk:"id"`
2829 StackID types.String `tfsdk:"stack_id"`
2930 ResourceID types.String `tfsdk:"resource_id"`
31+ Name types.String `tfsdk:"name"`
3032 RoleARN types.String `tfsdk:"role_arn"`
3133 Regions types.Set `tfsdk:"regions"`
3234}
@@ -90,6 +92,12 @@ func (r resourceAWSAccount) Schema(ctx context.Context, req resource.SchemaReque
9092 stringplanmodifier .UseStateForUnknown (),
9193 },
9294 },
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+ },
93101 "role_arn" : schema.StringAttribute {
94102 Description : "An IAM Role ARN string to represent with this AWS Account resource." ,
95103 Required : true ,
@@ -134,6 +142,7 @@ func (r resourceAWSAccount) ImportState(ctx context.Context, req resource.Import
134142 ID : types .StringValue (req .ID ),
135143 StackID : types .StringValue (stackID ),
136144 ResourceID : types .StringValue (resourceID ),
145+ Name : types .StringValue (account .Name ),
137146 RoleARN : types .StringValue (account .RoleARN ),
138147 Regions : regions ,
139148 })
@@ -149,6 +158,7 @@ func (r resourceAWSAccount) Create(ctx context.Context, req resource.CreateReque
149158
150159 accountData := cloudproviderapi.AWSAccount {}
151160 accountData .RoleARN = data .RoleARN .ValueString ()
161+ accountData .Name = data .Name .ValueString ()
152162 diags = data .Regions .ElementsAs (ctx , & accountData .Regions , false )
153163 resp .Diagnostics .Append (diags ... )
154164 if resp .Diagnostics .HasError () {
@@ -168,6 +178,7 @@ func (r resourceAWSAccount) Create(ctx context.Context, req resource.CreateReque
168178 ID : types .StringValue (resourceAWSAccountTerraformID .Make (data .StackID .ValueString (), account .ID )),
169179 StackID : data .StackID ,
170180 ResourceID : types .StringValue (account .ID ),
181+ Name : data .Name ,
171182 RoleARN : data .RoleARN ,
172183 Regions : data .Regions ,
173184 })
@@ -196,6 +207,11 @@ func (r resourceAWSAccount) Read(ctx context.Context, req resource.ReadRequest,
196207 if resp .Diagnostics .HasError () {
197208 return
198209 }
210+ diags = resp .State .SetAttribute (ctx , path .Root ("name" ), account .Name )
211+ resp .Diagnostics .Append (diags ... )
212+ if resp .Diagnostics .HasError () {
213+ return
214+ }
199215 diags = resp .State .SetAttribute (ctx , path .Root ("regions" ), account .Regions )
200216 resp .Diagnostics .Append (diags ... )
201217 if resp .Diagnostics .HasError () {
@@ -213,6 +229,7 @@ func (r *resourceAWSAccount) Update(ctx context.Context, req resource.UpdateRequ
213229
214230 accountData := cloudproviderapi.AWSAccount {}
215231 accountData .RoleARN = planData .RoleARN .ValueString ()
232+ accountData .Name = planData .Name .ValueString ()
216233 diags = planData .Regions .ElementsAs (ctx , & accountData .Regions , false )
217234 resp .Diagnostics .Append (diags ... )
218235 if resp .Diagnostics .HasError () {
@@ -234,6 +251,11 @@ func (r *resourceAWSAccount) Update(ctx context.Context, req resource.UpdateRequ
234251 if resp .Diagnostics .HasError () {
235252 return
236253 }
254+ diags = resp .State .SetAttribute (ctx , path .Root ("name" ), account .Name )
255+ resp .Diagnostics .Append (diags ... )
256+ if resp .Diagnostics .HasError () {
257+ return
258+ }
237259 diags = resp .State .SetAttribute (ctx , path .Root ("regions" ), account .Regions )
238260 resp .Diagnostics .Append (diags ... )
239261 if resp .Diagnostics .HasError () {
0 commit comments