diff --git a/internal/service/route53profiles/association.go b/internal/service/route53profiles/association.go index 6210a31f03f..d361d35dde2 100644 --- a/internal/service/route53profiles/association.go +++ b/internal/service/route53profiles/association.go @@ -101,49 +101,49 @@ func (r *resourceAssociation) Schema(ctx context.Context, req resource.SchemaReq func (r *resourceAssociation) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { conn := r.Meta().Route53ProfilesClient(ctx) - var plan associationResourceModel - resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + var state associationResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return } input := &route53profiles.AssociateProfileInput{} - resp.Diagnostics.Append(flex.Expand(ctx, plan, input)...) + resp.Diagnostics.Append(flex.Expand(ctx, state, input)...) out, err := conn.AssociateProfile(ctx, input) if err != nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionCreating, ResNameAssociation, plan.Name.String(), err), + create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionCreating, ResNameAssociation, state.Name.String(), err), err.Error(), ) return } if out == nil || out.ProfileAssociation == nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionCreating, ResNameAssociation, plan.Name.String(), nil), + create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionCreating, ResNameAssociation, state.Name.String(), nil), errors.New("empty output").Error(), ) return } - plan.ID = flex.StringToFramework(ctx, out.ProfileAssociation.Id) + state.ID = flex.StringToFramework(ctx, out.ProfileAssociation.Id) - createTimeout := r.CreateTimeout(ctx, plan.Timeouts) - profileAssociation, err := waitAssociationCreated(ctx, conn, plan.ID.ValueString(), createTimeout) + createTimeout := r.CreateTimeout(ctx, state.Timeouts) + profileAssociation, err := waitAssociationCreated(ctx, conn, state.ID.ValueString(), createTimeout) if err != nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionWaitingForCreation, ResNameAssociation, plan.Name.String(), err), + create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionWaitingForCreation, ResNameAssociation, state.Name.String(), err), err.Error(), ) return } - if profileAssociation != nil { - plan.OwnerId = flex.StringToFramework(ctx, profileAssociation.OwnerId) - plan.Status = fwtypes.StringEnumValue[awstypes.ProfileStatus](profileAssociation.Status) - plan.StatusMessage = flex.StringToFramework(ctx, profileAssociation.StatusMessage) + + resp.Diagnostics.Append(flex.Flatten(ctx, profileAssociation, &state)...) + if resp.Diagnostics.HasError() { + return } - resp.Diagnostics.Append(resp.State.Set(ctx, plan)...) + resp.Diagnostics.Append(resp.State.Set(ctx, state)...) } func (r *resourceAssociation) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { diff --git a/internal/service/route53profiles/profile.go b/internal/service/route53profiles/profile.go index 292f73c16f0..a52f7e9b2f8 100644 --- a/internal/service/route53profiles/profile.go +++ b/internal/service/route53profiles/profile.go @@ -131,18 +131,18 @@ func (r *resourceProfile) Create(ctx context.Context, req resource.CreateRequest data.ID = fwflex.StringToFramework(ctx, output.Profile.Id) - profileOutput, err := waitProfileCreated(ctx, conn, data.ID.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) + profile, err := waitProfileCreated(ctx, conn, data.ID.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) if err != nil { resp.Diagnostics.AddError(fmt.Sprintf("waiting for route53 profile (%s) created", name), err.Error()) return } - if profileOutput != nil { - data.ARN = fwflex.StringToFramework(ctx, profileOutput.Arn) - data.OwnerId = fwflex.StringToFramework(ctx, profileOutput.OwnerId) - data.ShareStatus = fwtypes.StringEnumValue(profileOutput.ShareStatus) - data.Status = fwtypes.StringEnumValue(profileOutput.Status) - data.StatusMessage = fwflex.StringToFramework(ctx, profileOutput.StatusMessage) + if profile != nil { + data.ARN = fwflex.StringToFramework(ctx, profile.Arn) + data.OwnerId = fwflex.StringToFramework(ctx, profile.OwnerId) + data.ShareStatus = fwtypes.StringEnumValue(profile.ShareStatus) + data.Status = fwtypes.StringEnumValue(profile.Status) + data.StatusMessage = fwflex.StringToFramework(ctx, profile.StatusMessage) } resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) diff --git a/internal/service/route53profiles/profile_test.go b/internal/service/route53profiles/profile_test.go index 7d8c60419dc..aee4d182c8a 100644 --- a/internal/service/route53profiles/profile_test.go +++ b/internal/service/route53profiles/profile_test.go @@ -116,7 +116,7 @@ func TestAccRoute53ProfilesProfile_tags(t *testing.T) { ), }, { - Config: testAccProfileConfig_tags1(rName, acctest.CtTagsKey2, acctest.CtValue2), + Config: testAccProfileConfig_tags1(rName, acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( testAccCheckProfileExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct1), diff --git a/internal/service/route53profiles/resource_association.go b/internal/service/route53profiles/resource_association.go index 236afeb8048..54511470f30 100644 --- a/internal/service/route53profiles/resource_association.go +++ b/internal/service/route53profiles/resource_association.go @@ -11,13 +11,13 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/route53profiles" awstypes "github.com/aws/aws-sdk-go-v2/service/route53profiles/types" + "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/create" @@ -26,7 +26,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/framework" "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" - fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -83,10 +82,8 @@ func (r *resourceResourceAssociation) Schema(ctx context.Context, req resource.S }, }, "resource_properties": schema.StringAttribute{ - Optional: true, - Validators: []validator.String{ - fwvalidators.JSON(), - }, + CustomType: jsontypes.NormalizedType{}, + Optional: true, }, names.AttrResourceType: schema.StringAttribute{ Computed: true, @@ -112,51 +109,49 @@ func (r *resourceResourceAssociation) Schema(ctx context.Context, req resource.S func (r *resourceResourceAssociation) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { conn := r.Meta().Route53ProfilesClient(ctx) - var plan resourceAssociationResourceModel - resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + var state resourceAssociationResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return } input := &route53profiles.AssociateResourceToProfileInput{} - resp.Diagnostics.Append(flex.Expand(ctx, plan, input)...) + resp.Diagnostics.Append(flex.Expand(ctx, state, input)...) out, err := conn.AssociateResourceToProfile(ctx, input) if err != nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionCreating, ResNameResourceAssociation, plan.Name.String(), err), + create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionCreating, ResNameResourceAssociation, state.Name.String(), err), err.Error(), ) return } if out == nil || out.ProfileResourceAssociation == nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionCreating, ResNameResourceAssociation, plan.Name.String(), nil), + create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionCreating, ResNameResourceAssociation, state.Name.String(), nil), errors.New("empty output").Error(), ) return } - plan.ID = flex.StringToFramework(ctx, out.ProfileResourceAssociation.Id) + state.ID = flex.StringToFramework(ctx, out.ProfileResourceAssociation.Id) - createTimeout := r.CreateTimeout(ctx, plan.Timeouts) - resourceAssociation, err := waitResourceAssociationCreated(ctx, conn, plan.ID.ValueString(), createTimeout) + createTimeout := r.CreateTimeout(ctx, state.Timeouts) + resourceAssociation, err := waitResourceAssociationCreated(ctx, conn, state.ID.ValueString(), createTimeout) if err != nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionWaitingForCreation, ResNameResourceAssociation, plan.Name.String(), err), + create.ProblemStandardMessage(names.Route53Profiles, create.ErrActionWaitingForCreation, ResNameResourceAssociation, state.Name.String(), err), err.Error(), ) return } - if resourceAssociation != nil { - plan.OwnerId = flex.StringToFramework(ctx, resourceAssociation.OwnerId) - plan.ResourceProperties = flex.StringToFramework(ctx, resourceAssociation.ResourceProperties) - plan.ResourceType = flex.StringToFramework(ctx, resourceAssociation.ResourceType) - plan.Status = fwtypes.StringEnumValue[awstypes.ProfileStatus](resourceAssociation.Status) - plan.StatusMessage = flex.StringToFramework(ctx, resourceAssociation.StatusMessage) + + resp.Diagnostics.Append(flex.Flatten(ctx, resourceAssociation, &state)...) + if resp.Diagnostics.HasError() { + return } - resp.Diagnostics.Append(resp.State.Set(ctx, plan)...) + resp.Diagnostics.Append(resp.State.Set(ctx, state)...) } func (r *resourceResourceAssociation) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { @@ -309,7 +304,7 @@ type resourceAssociationResourceModel struct { OwnerId types.String `tfsdk:"owner_id"` ProfileID types.String `tfsdk:"profile_id"` ResourceArn types.String `tfsdk:"resource_arn"` - ResourceProperties types.String `tfsdk:"resource_properties"` + ResourceProperties jsontypes.Normalized `tfsdk:"resource_properties"` ResourceType types.String `tfsdk:"resource_type"` Status fwtypes.StringEnum[awstypes.ProfileStatus] `tfsdk:"status"` StatusMessage types.String `tfsdk:"status_message"` diff --git a/website/docs/d/route53profiles_profiles.html.markdown b/website/docs/d/route53profiles_profiles.html.markdown index 185c861a3e3..6b113086ad1 100644 --- a/website/docs/d/route53profiles_profiles.html.markdown +++ b/website/docs/d/route53profiles_profiles.html.markdown @@ -26,9 +26,8 @@ There are no arguments available for this data source. This data source exports the following attributes: - * `profiles` - List of Profiles. * `arn` - The ARN of the Profile. * `id` - The ID of the Profile. * `name` - The name of the Profile. - * `share_status` - The share status of the Profile. Valid values [AWS docs](https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53profiles_Profile.html) \ No newline at end of file + * `share_status` - The share status of the Profile. Valid values [AWS docs](https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53profiles_Profile.html)