From 5c237a6ab255a6d43b5aadb51d3216af327d941e Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Fri, 26 Jul 2024 16:50:05 -0400 Subject: [PATCH 01/36] Added CRUD operations for datazone environment project --- .../service/datazone/environment_profile.go | 321 ++++++++++++++++++ .../datazone/environment_profile_test.go | 279 +++++++++++++++ internal/service/datazone/exports_test.go | 1 + .../service/datazone/service_package_gen.go | 4 + .../datazone_enviroment_profile.html.markdown | 89 +++++ 5 files changed, 694 insertions(+) create mode 100644 internal/service/datazone/environment_profile.go create mode 100644 internal/service/datazone/environment_profile_test.go create mode 100644 website/docs/r/datazone_enviroment_profile.html.markdown diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go new file mode 100644 index 00000000000..4ded953decc --- /dev/null +++ b/internal/service/datazone/environment_profile.go @@ -0,0 +1,321 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package datazone + +import ( + "context" + "errors" + "fmt" + "strings" + + "github.com/YakDriver/regexache" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/datazone" + awstypes "github.com/aws/aws-sdk-go-v2/service/datazone/types" + "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "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/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" + "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// @FrameworkResource("aws_datazone_environment_profile", name="Environment Profile") +func newResourceEnvironmentProfile(_ context.Context) (resource.ResourceWithConfigure, error) { + r := &resourceEnvironmentProfile{} + return r, nil +} + +const ( + ResNameEnvironmentProfile = "Environment Profile" +) + +type resourceEnvironmentProfile struct { + framework.ResourceWithConfigure + framework.WithTimeouts +} + +func (r *resourceEnvironmentProfile) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = "aws_datazone_environment_profile" +} + +func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "aws_account_id": schema.StringAttribute{ + Optional: true, + Computed: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexache.MustCompile("^\\d{12}$"), "must match ^\\d{12}$"), + }, + }, + "aws_account_region": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexache.MustCompile("^[a-z]{2}-[a-z]{4,10}-\\d$"), "must match ^[a-z]{2}-[a-z]{4,10}-\\d$"), + }, + }, + "environment_blueprint_identifier": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexache.MustCompile("^[a-zA-Z0-9_-]{1,36}$"), "must match ^[a-zA-Z0-9_-]{1,36}$"), + }, + }, + names.AttrDescription: schema.StringAttribute{ + Optional: true, + Computed: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(0, 2048), + }, + }, + names.AttrID: schema.StringAttribute{ + Computed: true, + /* + Validators: []validator.String{ + stringvalidator.RegexMatches(regexache.MustCompile("^[a-zA-Z0-9_-]{1,36}$"), "must match ^[a-zA-Z0-9_-]{1,36}$"), + }, + */ + }, + names.AttrName: schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexache.MustCompile("^[\\w -]+$"), "must match ^[\\w -]+$"), + stringvalidator.LengthBetween(1, 64), + }, + }, + "project_identifier": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexache.MustCompile("^[a-zA-Z0-9_-]{1,36}$"), "must match ^[a-zA-Z0-9_-]{1,36}$"), + }, + }, + names.AttrCreatedAt: schema.StringAttribute{ + CustomType: timetypes.RFC3339Type{}, + Computed: true, + }, + "created_by": schema.StringAttribute{ + Computed: true, + }, + "domain_identifier": schema.StringAttribute{ + Required: true, + }, + "updated_at": schema.StringAttribute{ + CustomType: timetypes.RFC3339Type{}, + Computed: true, + }, + }, + /* + Blocks: map[string]schema.Block{ + "user_parameters": schema.SetNestedBlock{ + CustomType: fwtypes.NewSetNestedObjectTypeOf[dUserParameters](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Optional: true, + }, + "value": schema.StringAttribute{ + Optional: true, + }, + }, + }, + }, + }, + */ + } +} + +func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + conn := r.Meta().DataZoneClient(ctx) + + var plan dEnvProfile + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + in := &datazone.CreateEnvironmentProfileInput{} + resp.Diagnostics.Append(flex.Expand(ctx, &plan, in)...) + if resp.Diagnostics.HasError() { + return + } + in.Name = plan.Name.ValueStringPointer() + in.EnvironmentBlueprintIdentifier = plan.EnvironmentBlueprintIdentifier.ValueStringPointer() + in.AwsAccountId = plan.AwsAccountId.ValueStringPointer() + + out, err := conn.CreateEnvironmentProfile(ctx, in) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.DataZone, create.ErrActionCreating, ResNameEnvironmentProfile, plan.Name.String(), err), + err.Error(), + ) + return + } + if out == nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.DataZone, create.ErrActionCreating, ResNameEnvironmentProfile, plan.Name.String(), nil), + errors.New("empty output").Error(), + ) + return + } + + resp.Diagnostics.Append(flex.Flatten(ctx, out, &plan)...) + if resp.Diagnostics.HasError() { + return + } + resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) +} + +func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + conn := r.Meta().DataZoneClient(ctx) + o := flex.AutoFlexOptions{} + o.AddIgnoredField("user_parameters") + + // TIP: -- 2. Fetch the state + var state dEnvProfile + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + out, err := findEnvironmentProfileByID(ctx, conn, state.Id.ValueString(), state.DomainIdentifier.ValueString()) + if tfresource.NotFound(err) { + resp.State.RemoveResource(ctx) + return + } + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.DataZone, create.ErrActionSetting, ResNameEnvironmentProfile, state.Id.String(), err), + err.Error(), + ) + return + } + + resp.Diagnostics.Append(flex.Flatten(ctx, out, &state)...) + if resp.Diagnostics.HasError() { + return + } + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) +} + +func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + conn := r.Meta().DataZoneClient(ctx) + + var plan, state dEnvProfile + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + if plan.EnvironmentBlueprintIdentifier.Equal(state.EnvironmentBlueprintIdentifier) && + plan.ProjectIdentifier.Equal(state.ProjectIdentifier) && plan.DomainIdentifier.Equal(state.DomainIdentifier) { + in := datazone.UpdateEnvironmentProfileInput{} + + resp.Diagnostics.Append(flex.Expand(ctx, plan, in)...) + if resp.Diagnostics.HasError() { + return + } + out, err := conn.UpdateEnvironmentProfile(ctx, &in) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.DataZone, create.ErrActionSetting, ResNameEnvironmentProfile, state.Id.ValueString(), err), + err.Error(), + ) + return + } + resp.Diagnostics.Append(flex.Flatten(ctx, out, &plan)...) + if resp.Diagnostics.HasError() { + return + } + } + resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) +} + +func (r *resourceEnvironmentProfile) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + conn := r.Meta().DataZoneClient(ctx) + var state dEnvProfile + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + + _, err := conn.DeleteEnvironmentProfile(ctx, &datazone.DeleteEnvironmentProfileInput{ + DomainIdentifier: state.DomainIdentifier.ValueStringPointer(), + Identifier: state.Id.ValueStringPointer(), + }) + + if err != nil && !errs.IsA[*awstypes.ResourceNotFoundException](err) { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.DataZone, create.ErrActionSetting, ResNameEnvironmentProfile, state.Id.ValueString(), err), + err.Error(), + ) + return + } +} + +func (r *resourceEnvironmentProfile) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + parts := strings.Split(req.ID, ":") + + if len(parts) != 4 { + resp.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "DomainIdentifier:Id"`, req.ID)) + } + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("domain_identifier"), parts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), parts[1])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("environment_blueprint_identifier"), parts[2])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_identifier"), parts[3])...) +} + +func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id string, domain_id string) (*datazone.GetEnvironmentProfileOutput, error) { + in := &datazone.GetEnvironmentProfileInput{ + Identifier: aws.String(id), + DomainIdentifier: aws.String(domain_id), + } + + out, err := conn.GetEnvironmentProfile(ctx, in) + if err != nil { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + return nil, err + } + + if out == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + return out, nil +} + +type dEnvProfile struct { + // entered and or computed + AwsAccountId types.String `tfsdk:"aws_account_id"` + AwsAccountRegion types.String `tfsdk:"aws_account_region"` + Description types.String `tfsdk:"description"` + Id types.String `tfsdk:"id"` + EnvironmentBlueprintIdentifier types.String `tfsdk:"environment_blueprint_identifier"` + //UserParameters fwtypes.SetNestedObjectValueOf[dUserParameters] `tfsdk:"user_parameters"` + + Name types.String `tfsdk:"name"` + ProjectIdentifier types.String `tfsdk:"project_identifier"` + + // computed + CreatedAt timetypes.RFC3339 `tfsdk:"created_at"` + CreatedBy types.String `tfsdk:"created_by"` + DomainIdentifier types.String `tfsdk:"domain_identifier"` + UpdatedAt timetypes.RFC3339 `tfsdk:"updated_at"` +} + +type dUserParameters struct { + // entered + Name types.String `tfsdk:"name"` + Value types.String `tfsdk:"value"` +} diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go new file mode 100644 index 00000000000..ccf7b055658 --- /dev/null +++ b/internal/service/datazone/environment_profile_test.go @@ -0,0 +1,279 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package datazone_test + +import ( + "context" + "errors" + "fmt" + "strings" + "testing" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/datazone" + "github.com/aws/aws-sdk-go-v2/service/datazone/types" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" + tfdatazone "github.com/hashicorp/terraform-provider-aws/internal/service/datazone" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var environmentprofile datazone.GetEnvironmentProfileOutput + epName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + pName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + envProfName := "aws_datazone_environment_profile.test" + domainName := "aws_datazone_domain_profile.test" + callName := "data.aws_caller_identity.test" + projectName := "aws_datazone_project.test" + regionName := "data.aws_region.test" + blueName := "data.aws_datazone_environment_blueprint.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.DataZoneEndpointID) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.DataZoneServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckEnvironmentProfileDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccEnvironmentProfileConfig_basic(epName, dName, pName), + Check: resource.ComposeTestCheckFunc( + testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), + resource.TestCheckResourceAttrPair(envProfName, "aws_account_id", callName, "account_id"), + resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, "name"), + resource.TestCheckResourceAttrSet(envProfName, "created_at"), + resource.TestCheckResourceAttrSet(envProfName, "created_by"), + resource.TestCheckResourceAttr(envProfName, "description", "desc"), + resource.TestCheckResourceAttrSet(envProfName, "user_parameters"), + resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), + resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, "id"), + resource.TestCheckResourceAttrSet(envProfName, names.AttrID), + resource.TestCheckResourceAttr(envProfName, names.AttrName, epName), + resource.TestCheckResourceAttrPair(envProfName, "project_identifier", projectName, "id"), + ), + }, + { + ResourceName: envProfName, + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(envProfName), + ImportStateVerifyIgnore: []string{"apply_immediately", "user"}, + }, + { + Config: testAccEnvironmentProfileConfig_update(epName, dName, pName), + Check: resource.ComposeTestCheckFunc( + testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), + resource.TestCheckResourceAttrPair(envProfName, "aws_account_id", callName, "account_id"), + resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, "name"), + resource.TestCheckResourceAttrSet(envProfName, "created_at"), + resource.TestCheckResourceAttrSet(envProfName, "created_by"), + resource.TestCheckResourceAttr(envProfName, "description", "description"), + resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), + resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, "id"), + resource.TestCheckResourceAttrSet(envProfName, names.AttrID), + resource.TestCheckResourceAttr(envProfName, names.AttrName, epName), + resource.TestCheckResourceAttrPair(envProfName, "project_identifier", projectName, "id"), + resource.TestCheckResourceAttrSet(envProfName, "updated_at"), + ), + }, + { + ResourceName: envProfName, + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(envProfName), + ImportStateVerifyIgnore: []string{"apply_immediately", "user"}, + }, + }, + }) +} + +func TestAccDataZoneEnvironmentProfile_disappears(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var environmentprofile datazone.GetEnvironmentProfileOutput + epName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + pName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + envProfName := "aws_datazone_environment_profile.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.DataZoneEndpointID) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.DataZoneServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckEnvironmentProfileDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccEnvironmentProfileConfig_basic(epName, dName, pName), + Check: resource.ComposeTestCheckFunc( + testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), + acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfdatazone.ResourceEnvironmentProfile, envProfName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testAccCheckEnvironmentProfileDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).DataZoneClient(ctx) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_datazone_environment_profile" { + continue + } + + t := rs.Primary.Attributes["domain_identifier"] + + _, err := conn.GetEnvironmentProfile(ctx, &datazone.GetEnvironmentProfileInput{ + DomainIdentifier: &t, + Identifier: aws.String(rs.Primary.ID), + }) + + if errs.IsA[*types.ResourceNotFoundException](err) || errs.IsA[*types.AccessDeniedException](err) { + return nil + } + if err != nil { + return create.Error(names.DataZone, create.ErrActionCheckingDestroyed, tfdatazone.ResNameEnvironmentProfile, rs.Primary.ID, err) + } + + return create.Error(names.DataZone, create.ErrActionCheckingDestroyed, tfdatazone.ResNameEnvironmentProfile, rs.Primary.ID, errors.New("not destroyed")) + } + + return nil + } +} + +func testAccCheckEnvironmentProfileExists(ctx context.Context, name string, environmentprofile *datazone.GetEnvironmentProfileOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return create.Error(names.DataZone, create.ErrActionCheckingExistence, tfdatazone.ResNameEnvironmentProfile, name, errors.New("not found")) + } + + if rs.Primary.ID == "" { + return create.Error(names.DataZone, create.ErrActionCheckingExistence, tfdatazone.ResNameEnvironmentProfile, name, errors.New("not set")) + } + + t := rs.Primary.Attributes["domain_identifier"] + conn := acctest.Provider.Meta().(*conns.AWSClient).DataZoneClient(ctx) + resp, err := conn.GetEnvironmentProfile(ctx, &datazone.GetEnvironmentProfileInput{ + DomainIdentifier: &t, + Identifier: &rs.Primary.ID, + }) + + if err != nil { + return create.Error(names.DataZone, create.ErrActionCheckingExistence, tfdatazone.ResNameEnvironmentProfile, rs.Primary.ID, err) + } + + *environmentprofile = *resp + + return nil + } +} + +/* +func envProfTestAccPreCheck(ctx context.Context, t *testing.T) { + conn := acctest.Provider.Meta().(*conns.AWSClient).DataZoneClient(ctx) + + input := &datazone.ListEnvironmentProfilesInput{} + _, err := conn.ListEnvironmentProfiles(ctx, input) + + if acctest.PreCheckSkipError(err) { + t.Skipf("skipping acceptance testing: %s", err) + } + if err != nil { + t.Fatalf("unexpected PreCheck error: %s", err) + } +} +*/ + +func testAccAuthorizerEnvProfImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("Not found: %s", resourceName) + } + + //return fmt.Sprintf("%s:%s", (rs.Primary.Attributes["domain_identifier"] , rs.Primary.ID, rs.Primary.Attributes["environment_blueprint_identifier"], rs.Primary.Attributes["project_identifier"])), nil + + return strings.Join([]string{rs.Primary.Attributes["domain_identifier"], rs.Primary.ID, rs.Primary.Attributes["environment_blueprint_identifier"], rs.Primary.Attributes["project_identifier"]}, ":"), nil + } +} + +func testAccEnvironmentProfileConfig_base(domainName, projectName string) string { + return acctest.ConfigCompose(testAccProjectConfig_basic(projectName, domainName), fmt.Sprint(` +data "aws_caller_identity" "test" {} +data "aws_region" "test" {} + +data "aws_datazone_environment_blueprint" "test" { + domain_id = aws_datazone_domain.test.id + name = "DefaultDataLake" + managed = true +} + +resource "aws_datazone_environment_blueprint_configuration" "test" { + domain_id = aws_datazone_domain.test.id + environment_blueprint_id = data.aws_datazone_environment_blueprint.test.id + provisioning_role_arn = aws_iam_role.domain_execution_role.arn + enabled_regions = [data.aws_region.test.name] +} + `)) +} + +func testAccEnvironmentProfileConfig_basic(rName, domainName, projectName string) string { + return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` + + +resource "aws_datazone_environment_profile" "test" { + aws_account_id = data.aws_caller_identity.test.account_id + aws_account_region = data.aws_region.test.name + environment_blueprint_identifier = data.aws_datazone_environment_blueprint.test.id + description = "desc" + name = %[1]q + project_identifier = aws_datazone_project.test.id + domain_identifier = aws_datazone_domain.test.id +} +`, rName)) +} + +func testAccEnvironmentProfileConfig_update(rName, domainName, projectName string) string { + return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` + + +resource "aws_datazone_environment_profile" "test" { + aws_account_id = data.aws_caller_identity.test.account_id + aws_account_region = data.aws_region.test.name + description = "description" + environment_blueprint_identifier = data.aws_datazone_environment_blueprint.test.id + name = %[1]q + project_identifier = aws_datazone_project.test.id + domain_identifier = aws_datazone_domain.test.id +} +`, rName)) +} diff --git a/internal/service/datazone/exports_test.go b/internal/service/datazone/exports_test.go index 58f3e4834fd..25bfe480106 100644 --- a/internal/service/datazone/exports_test.go +++ b/internal/service/datazone/exports_test.go @@ -9,4 +9,5 @@ var ( ResourceEnvironmentBlueprintConfiguration = newResourceEnvironmentBlueprintConfiguration IsResourceMissing = isResourceMissing ResourceProject = newResourceProject + ResourceEnvironmentProfile = newResourceEnvironmentProfile ) diff --git a/internal/service/datazone/service_package_gen.go b/internal/service/datazone/service_package_gen.go index a2745588aad..a2669494464 100644 --- a/internal/service/datazone/service_package_gen.go +++ b/internal/service/datazone/service_package_gen.go @@ -36,6 +36,10 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic Factory: newResourceEnvironmentBlueprintConfiguration, Name: "Environment Blueprint Configuration", }, + { + Factory: newResourceEnvironmentProfile, + Name: "Environment Profile", + }, { Factory: newResourceProject, Name: "Project", diff --git a/website/docs/r/datazone_enviroment_profile.html.markdown b/website/docs/r/datazone_enviroment_profile.html.markdown new file mode 100644 index 00000000000..b6b1d10e59e --- /dev/null +++ b/website/docs/r/datazone_enviroment_profile.html.markdown @@ -0,0 +1,89 @@ +--- +subcategory: "DataZone" +layout: "aws" +page_title: "AWS: aws_datazone_environment_profile" +description: |- + Terraform resource for managing an AWS DataZone Environment Profile. +--- +` +# Resource: aws_datazone_environment_profile + +Terraform resource for managing an AWS DataZone Environment Profile. + +## Example Usage + +### Basic Usage + +```terraform +resource "aws_datazone_environment_profile" "example" { + aws_account_id = data.aws_caller_identity.example.account_id + aws_account_region = data.aws_region.example.name + environment_blueprint_identifier = data.aws_datazone_environment_blueprint.example.id + description = "desc" + name = "name" + project_identifier = aws_datazone_project.example.id + domain_identifier = aws_datazone_domain.example.i + +} +``` + +## Argument Reference + +The following arguments are required: + +* `aws_account_Id` - (Required) - Id of the AWS account being used. Must follow regex of ^\d{12}$. +* `aws_account_region` - (Required) - Desired region for environment profile. Must follow regex of ^[a-z]{2}-[a-z]{4,10}-\d$. +* `domain_identifier` - (Required) - Domain Identifier for environment profile. +* `name` - (Required) - Name of the environment profile. Must follow regex of ^[\w -]+$ and have the length between 1 and 64. +* `environment_blueprint_identifier` - (Required) - ID of the blueprint which the environment will be created with. Must follow regex of ^[a-zA-Z0-9_-]{1,36}$. +* `project_identifier` - (Required) - Project identifier for environment profile. Must follow regex of ^[a-zA-Z0-9_-]{1,36}$. + +The following arguments are optional: + +* `description` - (Optional) Description of environment profile. Must be between the length of 0 and 2048. +* `aws_account_Id` - (Optional) - Id of the AWS account being used. Must follow regex of ^\d{12}$ +* `user_parameters` - (Optional) - Array of user parameters of the environment profile with the following attributes: + * `name` - (Required) - Name of the environment profile parameter. + * `value` - (Required) - Value of the environment profile parameter. + +## Attribute Reference + +This resource exports the following attributes in addition to the arguments above: + +* `created_at` - Creation time of environment profile. +* `created_by` - Creator of environment profile. +* `id` - ID of environment profile. +* `updated_at` - Time of last update to environment profile. +* `user_parameters` - Array of user parameters of the environment profile with the following attributes: + * `field_type` - Filed type of the parameter. + * `key_name` - Key name of the parameter. + * `default_value` - Default value of the parameter. + * `description` - Description of the parameter. + * `is_editable` - Bool that specifies if the parameter is editable. + * `is_optional` - Bool that specifies if the parameter is editable. + +## Timeouts + +## Import + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import DataZone Environment Profile using the `example_id_arg`. For example: + +```terraform +import { + to = aws_datazone_environment_profile.example + id = "environment_profile-id-12345678" +} +``` + +Using `terraform import`, import DataZone Environment Profile using the `example_id_arg`. For example: + +```console +% terraform import aws_datazone_environment_profile.example environment_profile-id-12345678 +``` From 4186a2400dbca98e19f1cb94b55e1e2890eee327 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 12:27:26 -0400 Subject: [PATCH 02/36] Passes tests now. --- .../service/datazone/environment_profile.go | 92 +++++++++++++------ .../datazone/environment_profile_test.go | 14 ++- 2 files changed, 78 insertions(+), 28 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 4ded953decc..d7733dc8aaa 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -18,6 +18,8 @@ import ( "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/setplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -25,6 +27,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs" "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" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -113,29 +116,32 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc Computed: true, }, }, - /* - Blocks: map[string]schema.Block{ - "user_parameters": schema.SetNestedBlock{ - CustomType: fwtypes.NewSetNestedObjectTypeOf[dUserParameters](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Optional: true, - }, - "value": schema.StringAttribute{ - Optional: true, - }, + Blocks: map[string]schema.Block{ + "user_parameters": schema.SetNestedBlock{ + PlanModifiers: []planmodifier.Set{ + setplanmodifier.RequiresReplace(), + setplanmodifier.RequiresReplaceIfConfigured(), + }, + CustomType: fwtypes.NewSetNestedObjectTypeOf[dUserParameters](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Optional: true, + Computed: false, + }, + "value": schema.StringAttribute{ + Optional: true, + Computed: false, }, }, }, }, - */ + }, } } func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { conn := r.Meta().DataZoneClient(ctx) - var plan dEnvProfile resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) if resp.Diagnostics.HasError() { @@ -167,7 +173,18 @@ func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.Cr return } - resp.Diagnostics.Append(flex.Flatten(ctx, out, &plan)...) + plan.AwsAccountId = flex.StringToFramework(ctx, out.AwsAccountId) + plan.AwsAccountRegion = flex.StringToFramework(ctx, out.AwsAccountRegion) + plan.CreatedAt = flex.TimeToFramework(ctx, out.CreatedAt) + plan.CreatedBy = flex.StringToFramework(ctx, out.CreatedBy) + plan.Description = flex.StringToFramework(ctx, out.Description) + plan.DomainIdentifier = flex.StringToFramework(ctx, out.DomainId) + plan.EnvironmentBlueprintIdentifier = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) + plan.Id = flex.StringToFramework(ctx, out.Id) + plan.Name = flex.StringToFramework(ctx, out.Name) + plan.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) + plan.UpdatedAt = flex.TimeToFramework(ctx, out.UpdatedAt) + if resp.Diagnostics.HasError() { return } @@ -199,7 +216,18 @@ func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.Read return } - resp.Diagnostics.Append(flex.Flatten(ctx, out, &state)...) + state.AwsAccountId = flex.StringToFramework(ctx, out.AwsAccountId) + state.AwsAccountRegion = flex.StringToFramework(ctx, out.AwsAccountRegion) + state.CreatedAt = flex.TimeToFramework(ctx, out.CreatedAt) + state.CreatedBy = flex.StringToFramework(ctx, out.CreatedBy) + state.Description = flex.StringToFramework(ctx, out.Description) + state.DomainIdentifier = flex.StringToFramework(ctx, out.DomainId) + state.EnvironmentBlueprintIdentifier = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) + state.Id = flex.StringToFramework(ctx, out.Id) + state.Name = flex.StringToFramework(ctx, out.Name) + state.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) + state.UpdatedAt = flex.TimeToFramework(ctx, out.UpdatedAt) + if resp.Diagnostics.HasError() { return } @@ -217,13 +245,14 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up } if plan.EnvironmentBlueprintIdentifier.Equal(state.EnvironmentBlueprintIdentifier) && plan.ProjectIdentifier.Equal(state.ProjectIdentifier) && plan.DomainIdentifier.Equal(state.DomainIdentifier) { - in := datazone.UpdateEnvironmentProfileInput{} + in := &datazone.UpdateEnvironmentProfileInput{} resp.Diagnostics.Append(flex.Expand(ctx, plan, in)...) if resp.Diagnostics.HasError() { return } - out, err := conn.UpdateEnvironmentProfile(ctx, &in) + in.Identifier = state.Id.ValueStringPointer() + out, err := conn.UpdateEnvironmentProfile(ctx, in) if err != nil { resp.Diagnostics.AddError( create.ProblemStandardMessage(names.DataZone, create.ErrActionSetting, ResNameEnvironmentProfile, state.Id.ValueString(), err), @@ -231,7 +260,18 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up ) return } - resp.Diagnostics.Append(flex.Flatten(ctx, out, &plan)...) + plan.AwsAccountId = flex.StringToFramework(ctx, out.AwsAccountId) + plan.AwsAccountRegion = flex.StringToFramework(ctx, out.AwsAccountRegion) + plan.CreatedAt = flex.TimeToFramework(ctx, out.CreatedAt) + plan.CreatedBy = flex.StringToFramework(ctx, out.CreatedBy) + plan.Description = flex.StringToFramework(ctx, out.Description) + plan.DomainIdentifier = flex.StringToFramework(ctx, out.DomainId) + plan.EnvironmentBlueprintIdentifier = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) + plan.Id = flex.StringToFramework(ctx, out.Id) + plan.Name = flex.StringToFramework(ctx, out.Name) + plan.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) + plan.UpdatedAt = flex.TimeToFramework(ctx, out.UpdatedAt) + if resp.Diagnostics.HasError() { return } @@ -265,7 +305,7 @@ func (r *resourceEnvironmentProfile) ImportState(ctx context.Context, req resour resp.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "DomainIdentifier:Id"`, req.ID)) } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("domain_identifier"), parts[0])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), parts[1])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), parts[1])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("environment_blueprint_identifier"), parts[2])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_identifier"), parts[3])...) } @@ -297,12 +337,12 @@ func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id s type dEnvProfile struct { // entered and or computed - AwsAccountId types.String `tfsdk:"aws_account_id"` - AwsAccountRegion types.String `tfsdk:"aws_account_region"` - Description types.String `tfsdk:"description"` - Id types.String `tfsdk:"id"` - EnvironmentBlueprintIdentifier types.String `tfsdk:"environment_blueprint_identifier"` - //UserParameters fwtypes.SetNestedObjectValueOf[dUserParameters] `tfsdk:"user_parameters"` + AwsAccountId types.String `tfsdk:"aws_account_id"` + AwsAccountRegion types.String `tfsdk:"aws_account_region"` + Description types.String `tfsdk:"description"` + Id types.String `tfsdk:"id"` + EnvironmentBlueprintIdentifier types.String `tfsdk:"environment_blueprint_identifier"` + UserParameters fwtypes.SetNestedObjectValueOf[dUserParameters] `tfsdk:"user_parameters"` Name types.String `tfsdk:"name"` ProjectIdentifier types.String `tfsdk:"project_identifier"` diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index ccf7b055658..c9094c0a755 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -36,7 +36,7 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { pName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) envProfName := "aws_datazone_environment_profile.test" - domainName := "aws_datazone_domain_profile.test" + domainName := "aws_datazone_domain.test" callName := "data.aws_caller_identity.test" projectName := "aws_datazone_project.test" regionName := "data.aws_region.test" @@ -61,7 +61,8 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { resource.TestCheckResourceAttrSet(envProfName, "created_at"), resource.TestCheckResourceAttrSet(envProfName, "created_by"), resource.TestCheckResourceAttr(envProfName, "description", "desc"), - resource.TestCheckResourceAttrSet(envProfName, "user_parameters"), + resource.TestCheckResourceAttrSet(envProfName, "user_parameters.0.name"), + resource.TestCheckResourceAttrSet(envProfName, "user_parameters.0.value"), resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, "id"), resource.TestCheckResourceAttrSet(envProfName, names.AttrID), @@ -258,6 +259,11 @@ resource "aws_datazone_environment_profile" "test" { name = %[1]q project_identifier = aws_datazone_project.test.id domain_identifier = aws_datazone_domain.test.id + user_parameters { + name = "consumerGlueDbName" + value = "hi" + } + } `, rName)) } @@ -274,6 +280,10 @@ resource "aws_datazone_environment_profile" "test" { name = %[1]q project_identifier = aws_datazone_project.test.id domain_identifier = aws_datazone_domain.test.id + user_parameters { + name = "consumerGlueDbName" + value = "hi" + } } `, rName)) } From 65351abc21c31bf33db18bb0ba32d22178a80dc1 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 12:31:53 -0400 Subject: [PATCH 03/36] CI formatting changes --- .../service/datazone/environment_profile.go | 8 ++-- .../datazone/environment_profile_test.go | 44 ++++++++++--------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index d7733dc8aaa..684ab9582d7 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -54,7 +54,7 @@ func (r *resourceEnvironmentProfile) Metadata(_ context.Context, req resource.Me func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - "aws_account_id": schema.StringAttribute{ + names.AttrAWSAccountID: schema.StringAttribute{ Optional: true, Computed: true, Validators: []validator.String{ @@ -125,11 +125,11 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc CustomType: fwtypes.NewSetNestedObjectTypeOf[dUserParameters](ctx), NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - "name": schema.StringAttribute{ + names.AttrName: schema.StringAttribute{ Optional: true, Computed: false, }, - "value": schema.StringAttribute{ + names.AttrValue: schema.StringAttribute{ Optional: true, Computed: false, }, @@ -305,7 +305,7 @@ func (r *resourceEnvironmentProfile) ImportState(ctx context.Context, req resour resp.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "DomainIdentifier:Id"`, req.ID)) } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("domain_identifier"), parts[0])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), parts[1])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), parts[1])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("environment_blueprint_identifier"), parts[2])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_identifier"), parts[3])...) } diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index c9094c0a755..77088e7b390 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -56,18 +56,18 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { Config: testAccEnvironmentProfileConfig_basic(epName, dName, pName), Check: resource.ComposeTestCheckFunc( testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), - resource.TestCheckResourceAttrPair(envProfName, "aws_account_id", callName, "account_id"), - resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, "name"), - resource.TestCheckResourceAttrSet(envProfName, "created_at"), + resource.TestCheckResourceAttrPair(envProfName, names.AttrAWSAccountID, callName, names.AttrAccountID), + resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, names.AttrName), + resource.TestCheckResourceAttrSet(envProfName, names.AttrCreatedAt), resource.TestCheckResourceAttrSet(envProfName, "created_by"), - resource.TestCheckResourceAttr(envProfName, "description", "desc"), + resource.TestCheckResourceAttr(envProfName, names.AttrDescription, "desc"), resource.TestCheckResourceAttrSet(envProfName, "user_parameters.0.name"), resource.TestCheckResourceAttrSet(envProfName, "user_parameters.0.value"), resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), - resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, "id"), + resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, names.AttrID), resource.TestCheckResourceAttrSet(envProfName, names.AttrID), resource.TestCheckResourceAttr(envProfName, names.AttrName, epName), - resource.TestCheckResourceAttrPair(envProfName, "project_identifier", projectName, "id"), + resource.TestCheckResourceAttrPair(envProfName, "project_identifier", projectName, names.AttrID), ), }, { @@ -75,22 +75,22 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(envProfName), - ImportStateVerifyIgnore: []string{"apply_immediately", "user"}, + ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user"}, }, { Config: testAccEnvironmentProfileConfig_update(epName, dName, pName), Check: resource.ComposeTestCheckFunc( testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), - resource.TestCheckResourceAttrPair(envProfName, "aws_account_id", callName, "account_id"), - resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, "name"), - resource.TestCheckResourceAttrSet(envProfName, "created_at"), + resource.TestCheckResourceAttrPair(envProfName, names.AttrAWSAccountID, callName, names.AttrAccountID), + resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, names.AttrName), + resource.TestCheckResourceAttrSet(envProfName, names.AttrCreatedAt), resource.TestCheckResourceAttrSet(envProfName, "created_by"), - resource.TestCheckResourceAttr(envProfName, "description", "description"), + resource.TestCheckResourceAttr(envProfName, names.AttrDescription, names.AttrDescription), resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), - resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, "id"), + resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, names.AttrID), resource.TestCheckResourceAttrSet(envProfName, names.AttrID), resource.TestCheckResourceAttr(envProfName, names.AttrName, epName), - resource.TestCheckResourceAttrPair(envProfName, "project_identifier", projectName, "id"), + resource.TestCheckResourceAttrPair(envProfName, "project_identifier", projectName, names.AttrID), resource.TestCheckResourceAttrSet(envProfName, "updated_at"), ), }, @@ -99,7 +99,7 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(envProfName), - ImportStateVerifyIgnore: []string{"apply_immediately", "user"}, + ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user"}, }, }, }) @@ -228,7 +228,7 @@ func testAccAuthorizerEnvProfImportStateIdFunc(resourceName string) resource.Imp } func testAccEnvironmentProfileConfig_base(domainName, projectName string) string { - return acctest.ConfigCompose(testAccProjectConfig_basic(projectName, domainName), fmt.Sprint(` + return acctest.ConfigCompose(testAccProjectConfig_basic(projectName, domainName), (` data "aws_caller_identity" "test" {} data "aws_region" "test" {} @@ -251,6 +251,8 @@ func testAccEnvironmentProfileConfig_basic(rName, domainName, projectName string return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` + + resource "aws_datazone_environment_profile" "test" { aws_account_id = data.aws_caller_identity.test.account_id aws_account_region = data.aws_region.test.name @@ -259,9 +261,9 @@ resource "aws_datazone_environment_profile" "test" { name = %[1]q project_identifier = aws_datazone_project.test.id domain_identifier = aws_datazone_domain.test.id - user_parameters { - name = "consumerGlueDbName" - value = "hi" + user_parameters { + name = "consumerGlueDbName" + value = "hi" } } @@ -272,6 +274,8 @@ func testAccEnvironmentProfileConfig_update(rName, domainName, projectName strin return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` + + resource "aws_datazone_environment_profile" "test" { aws_account_id = data.aws_caller_identity.test.account_id aws_account_region = data.aws_region.test.name @@ -281,8 +285,8 @@ resource "aws_datazone_environment_profile" "test" { project_identifier = aws_datazone_project.test.id domain_identifier = aws_datazone_domain.test.id user_parameters { - name = "consumerGlueDbName" - value = "hi" + name = "consumerGlueDbName" + value = "hi" } } `, rName)) From 9d4f14a149e8c7a9ab937eea0f81f09d7953c340 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 12:36:46 -0400 Subject: [PATCH 04/36] Documentation changes --- .../datazone_enviroment_profile.html.markdown | 85 +++++++++++++++++-- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/website/docs/r/datazone_enviroment_profile.html.markdown b/website/docs/r/datazone_enviroment_profile.html.markdown index b6b1d10e59e..1a575b7fb7f 100644 --- a/website/docs/r/datazone_enviroment_profile.html.markdown +++ b/website/docs/r/datazone_enviroment_profile.html.markdown @@ -22,12 +22,88 @@ Terraform resource for managing an AWS DataZone Environment Profile. ### Basic Usage ```terraform + +resource "aws_iam_role" "domain_execution_role" { + name = "example-name" + assume_role_policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = ["sts:AssumeRole", "sts:TagSession"] + Effect = "Allow" + Principal = { + Service = "datazone.amazonaws.com" + } + }, + { + Action = ["sts:AssumeRole", "sts:TagSession"] + Effect = "Allow" + Principal = { + Service = "cloudformation.amazonaws.com" + } + }, + ] + }) + + inline_policy { + name = "example-name" + policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = [ + "datazone:*", + "ram:*", + "sso:*", + "kms:*", + ] + Effect = "Allow" + Resource = "*" + }, + ] + }) + } +} + +resource "aws_datazone_domain" "test" { + name = "example-name" + domain_execution_role = aws_iam_role.domain_execution_role.arn +} + +resource "aws_security_group" "test" { + name = "example-name" +} + +resource "aws_datazone_project" "test" { + domain_identifier = aws_datazone_domain.test.id + glossary_terms = ["2N8w6XJCwZf"] + name = "example-name" + description = "desc" + skip_deletion_check = true +} + +data "aws_caller_identity" "test" {} +data "aws_region" "test" {} + +data "aws_datazone_environment_blueprint" "test" { + domain_id = aws_datazone_domain.test.id + name = "DefaultDataLake" + managed = true +} + +resource "aws_datazone_environment_blueprint_configuration" "test" { + domain_id = aws_datazone_domain.test.id + environment_blueprint_id = data.aws_datazone_environment_blueprint.test.id + provisioning_role_arn = aws_iam_role.domain_execution_role.arn + enabled_regions = [data.aws_region.test.name] +} + resource "aws_datazone_environment_profile" "example" { aws_account_id = data.aws_caller_identity.example.account_id aws_account_region = data.aws_region.example.name environment_blueprint_identifier = data.aws_datazone_environment_blueprint.example.id description = "desc" - name = "name" + name = "example-name" project_identifier = aws_datazone_project.example.id domain_identifier = aws_datazone_domain.example.i @@ -61,13 +137,6 @@ This resource exports the following attributes in addition to the arguments abov * `created_by` - Creator of environment profile. * `id` - ID of environment profile. * `updated_at` - Time of last update to environment profile. -* `user_parameters` - Array of user parameters of the environment profile with the following attributes: - * `field_type` - Filed type of the parameter. - * `key_name` - Key name of the parameter. - * `default_value` - Default value of the parameter. - * `description` - Description of the parameter. - * `is_editable` - Bool that specifies if the parameter is editable. - * `is_optional` - Bool that specifies if the parameter is editable. ## Timeouts From ddd3801e3c6203bf8d5f99669e5bff29395abf69 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 12:48:04 -0400 Subject: [PATCH 05/36] ci formatting --- .../service/datazone/environment_profile_test.go | 13 ++++++++----- .../r/datazone_enviroment_profile.html.markdown | 11 ++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index 77088e7b390..eefd8f8b2ca 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -61,8 +61,8 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { resource.TestCheckResourceAttrSet(envProfName, names.AttrCreatedAt), resource.TestCheckResourceAttrSet(envProfName, "created_by"), resource.TestCheckResourceAttr(envProfName, names.AttrDescription, "desc"), - resource.TestCheckResourceAttrSet(envProfName, "user_parameters.0.name"), - resource.TestCheckResourceAttrSet(envProfName, "user_parameters.0.value"), + resource.TestCheckResourceAttr(envProfName, "user_parameters.0.name", "consumerGlueDbName"), + resource.TestCheckResourceAttr(envProfName, "user_parameters.0.value", "value"), resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, names.AttrID), resource.TestCheckResourceAttrSet(envProfName, names.AttrID), @@ -80,12 +80,15 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { { Config: testAccEnvironmentProfileConfig_update(epName, dName, pName), Check: resource.ComposeTestCheckFunc( + testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), resource.TestCheckResourceAttrPair(envProfName, names.AttrAWSAccountID, callName, names.AttrAccountID), resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, names.AttrName), resource.TestCheckResourceAttrSet(envProfName, names.AttrCreatedAt), resource.TestCheckResourceAttrSet(envProfName, "created_by"), - resource.TestCheckResourceAttr(envProfName, names.AttrDescription, names.AttrDescription), + resource.TestCheckResourceAttr(envProfName, names.AttrDescription, "description"), + resource.TestCheckResourceAttr(envProfName, "user_parameters.0.name", "consumerGlueDbName"), + resource.TestCheckResourceAttr(envProfName, "user_parameters.0.value", "value"), resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, names.AttrID), resource.TestCheckResourceAttrSet(envProfName, names.AttrID), @@ -263,7 +266,7 @@ resource "aws_datazone_environment_profile" "test" { domain_identifier = aws_datazone_domain.test.id user_parameters { name = "consumerGlueDbName" - value = "hi" + value = "value" } } @@ -286,7 +289,7 @@ resource "aws_datazone_environment_profile" "test" { domain_identifier = aws_datazone_domain.test.id user_parameters { name = "consumerGlueDbName" - value = "hi" + value = "value" } } `, rName)) diff --git a/website/docs/r/datazone_enviroment_profile.html.markdown b/website/docs/r/datazone_enviroment_profile.html.markdown index 1a575b7fb7f..2a84c77e2f2 100644 --- a/website/docs/r/datazone_enviroment_profile.html.markdown +++ b/website/docs/r/datazone_enviroment_profile.html.markdown @@ -14,7 +14,6 @@ TIP: A few guiding principles for writing documentation: 5. Use accessible and inclusive language. --->` # Resource: aws_datazone_environment_profile - Terraform resource for managing an AWS DataZone Environment Profile. ## Example Usage @@ -22,7 +21,6 @@ Terraform resource for managing an AWS DataZone Environment Profile. ### Basic Usage ```terraform - resource "aws_iam_role" "domain_execution_role" { name = "example-name" assume_role_policy = jsonencode({ @@ -99,14 +97,17 @@ resource "aws_datazone_environment_blueprint_configuration" "test" { } resource "aws_datazone_environment_profile" "example" { - aws_account_id = data.aws_caller_identity.example.account_id + aws_account_id = data.aws_caller_identity.example.account_id aws_account_region = data.aws_region.example.name environment_blueprint_identifier = data.aws_datazone_environment_blueprint.example.id description = "desc" name = "example-name" project_identifier = aws_datazone_project.example.id - domain_identifier = aws_datazone_domain.example.i - + domain_identifier = aws_datazone_domain.example.id + user_parameters { + name = "consumerGlueDbName" + value = "value" + } } ``` From 4011076f1d79d48ec5fbde73890767c64aced802 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 13:07:05 -0400 Subject: [PATCH 06/36] ci formatting changes --- .../service/datazone/environment_profile.go | 26 +++++++++---------- .../datazone/environment_profile_test.go | 6 ++--- ...atazone_environment_profile.html.markdown} | 24 +++++++---------- 3 files changed, 25 insertions(+), 31 deletions(-) rename website/docs/r/{datazone_enviroment_profile.html.markdown => datazone_environment_profile.html.markdown} (85%) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 684ab9582d7..986f5691abe 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -247,7 +247,7 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up plan.ProjectIdentifier.Equal(state.ProjectIdentifier) && plan.DomainIdentifier.Equal(state.DomainIdentifier) { in := &datazone.UpdateEnvironmentProfileInput{} - resp.Diagnostics.Append(flex.Expand(ctx, plan, in)...) + resp.Diagnostics.Append(flex.Expand(ctx, state, in)...) if resp.Diagnostics.HasError() { return } @@ -260,23 +260,23 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up ) return } - plan.AwsAccountId = flex.StringToFramework(ctx, out.AwsAccountId) - plan.AwsAccountRegion = flex.StringToFramework(ctx, out.AwsAccountRegion) - plan.CreatedAt = flex.TimeToFramework(ctx, out.CreatedAt) - plan.CreatedBy = flex.StringToFramework(ctx, out.CreatedBy) - plan.Description = flex.StringToFramework(ctx, out.Description) - plan.DomainIdentifier = flex.StringToFramework(ctx, out.DomainId) - plan.EnvironmentBlueprintIdentifier = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) - plan.Id = flex.StringToFramework(ctx, out.Id) - plan.Name = flex.StringToFramework(ctx, out.Name) - plan.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) - plan.UpdatedAt = flex.TimeToFramework(ctx, out.UpdatedAt) + state.AwsAccountId = flex.StringToFramework(ctx, out.AwsAccountId) + state.AwsAccountRegion = flex.StringToFramework(ctx, out.AwsAccountRegion) + state.CreatedAt = flex.TimeToFramework(ctx, out.CreatedAt) + state.CreatedBy = flex.StringToFramework(ctx, out.CreatedBy) + state.Description = flex.StringToFramework(ctx, out.Description) + state.DomainIdentifier = flex.StringToFramework(ctx, out.DomainId) + state.EnvironmentBlueprintIdentifier = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) + state.Id = flex.StringToFramework(ctx, out.Id) + state.Name = flex.StringToFramework(ctx, out.Name) + state.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) + state.UpdatedAt = flex.TimeToFramework(ctx, out.UpdatedAt) if resp.Diagnostics.HasError() { return } } - resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } func (r *resourceEnvironmentProfile) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index eefd8f8b2ca..960fe3dd28d 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -62,7 +62,7 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { resource.TestCheckResourceAttrSet(envProfName, "created_by"), resource.TestCheckResourceAttr(envProfName, names.AttrDescription, "desc"), resource.TestCheckResourceAttr(envProfName, "user_parameters.0.name", "consumerGlueDbName"), - resource.TestCheckResourceAttr(envProfName, "user_parameters.0.value", "value"), + resource.TestCheckResourceAttr(envProfName, "user_parameters.0.value", names.AttrValue), resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, names.AttrID), resource.TestCheckResourceAttrSet(envProfName, names.AttrID), @@ -86,9 +86,9 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, names.AttrName), resource.TestCheckResourceAttrSet(envProfName, names.AttrCreatedAt), resource.TestCheckResourceAttrSet(envProfName, "created_by"), - resource.TestCheckResourceAttr(envProfName, names.AttrDescription, "description"), + resource.TestCheckResourceAttr(envProfName, names.AttrDescription, names.AttrDescription), resource.TestCheckResourceAttr(envProfName, "user_parameters.0.name", "consumerGlueDbName"), - resource.TestCheckResourceAttr(envProfName, "user_parameters.0.value", "value"), + resource.TestCheckResourceAttr(envProfName, "user_parameters.0.value", names.AttrValue), resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, names.AttrID), resource.TestCheckResourceAttrSet(envProfName, names.AttrID), diff --git a/website/docs/r/datazone_enviroment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown similarity index 85% rename from website/docs/r/datazone_enviroment_profile.html.markdown rename to website/docs/r/datazone_environment_profile.html.markdown index 2a84c77e2f2..bd33576810e 100644 --- a/website/docs/r/datazone_enviroment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -5,15 +5,9 @@ page_title: "AWS: aws_datazone_environment_profile" description: |- Terraform resource for managing an AWS DataZone Environment Profile. --- -` + # Resource: aws_datazone_environment_profile + Terraform resource for managing an AWS DataZone Environment Profile. ## Example Usage @@ -97,13 +91,13 @@ resource "aws_datazone_environment_blueprint_configuration" "test" { } resource "aws_datazone_environment_profile" "example" { - aws_account_id = data.aws_caller_identity.example.account_id - aws_account_region = data.aws_region.example.name - environment_blueprint_identifier = data.aws_datazone_environment_blueprint.example.id - description = "desc" - name = "example-name" - project_identifier = aws_datazone_project.example.id - domain_identifier = aws_datazone_domain.example.id + aws_account_id = data.aws_caller_identity.example.account_id + aws_account_region = data.aws_region.example.name + environment_blueprint_identifier = data.aws_datazone_environment_blueprint.example.id + description = "desc" + name = "example-name" + project_identifier = aws_datazone_project.example.id + domain_identifier = aws_datazone_domain.example.id user_parameters { name = "consumerGlueDbName" value = "value" From dc9d391b39e5977a35b4d6e881487f5ae735ca7f Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 13:15:07 -0400 Subject: [PATCH 07/36] fixed update --- internal/service/datazone/environment_profile.go | 2 +- .../r/datazone_environment_profile.html.markdown | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 986f5691abe..bf319a7dd97 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -247,7 +247,7 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up plan.ProjectIdentifier.Equal(state.ProjectIdentifier) && plan.DomainIdentifier.Equal(state.DomainIdentifier) { in := &datazone.UpdateEnvironmentProfileInput{} - resp.Diagnostics.Append(flex.Expand(ctx, state, in)...) + resp.Diagnostics.Append(flex.Expand(ctx, plan, in)...) if resp.Diagnostics.HasError() { return } diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index bd33576810e..878cf19c5ee 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -90,14 +90,14 @@ resource "aws_datazone_environment_blueprint_configuration" "test" { enabled_regions = [data.aws_region.test.name] } -resource "aws_datazone_environment_profile" "example" { - aws_account_id = data.aws_caller_identity.example.account_id - aws_account_region = data.aws_region.example.name - environment_blueprint_identifier = data.aws_datazone_environment_blueprint.example.id - description = "desc" +resource "aws_datazone_environment_profile" "test" { + aws_account_id = data.aws_caller_identity.test.account_id + aws_account_region = data.aws_region.test.name + description = "description" + environment_blueprint_identifier = data.aws_datazone_environment_blueprint.test.id name = "example-name" - project_identifier = aws_datazone_project.example.id - domain_identifier = aws_datazone_domain.example.id + project_identifier = aws_datazone_project.test.id + domain_identifier = aws_datazone_domain.test.id user_parameters { name = "consumerGlueDbName" value = "value" From 407d6140e53247739365a04547d8735a32e527f7 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 13:25:37 -0400 Subject: [PATCH 08/36] added changelog --- .changelog/35603.txt | 3 +++ website/docs/r/datazone_environment_profile.html.markdown | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .changelog/35603.txt diff --git a/.changelog/35603.txt b/.changelog/35603.txt new file mode 100644 index 00000000000..206475a611a --- /dev/null +++ b/.changelog/35603.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_datazone_environment_blueprint +``` \ No newline at end of file diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 878cf19c5ee..46263a16904 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -130,7 +130,7 @@ This resource exports the following attributes in addition to the arguments abov * `created_at` - Creation time of environment profile. * `created_by` - Creator of environment profile. -* `id` - ID of environment profile. +* `id` - ID of environment profile. * `updated_at` - Time of last update to environment profile. ## Timeouts From b12da911654c7d074e3a20da4c4162ac26c2de3d Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 17:10:42 -0400 Subject: [PATCH 09/36] Update internal/service/datazone/environment_profile.go Co-authored-by: Jared Baker --- internal/service/datazone/environment_profile.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index bf319a7dd97..b0e459b5d52 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -34,8 +34,7 @@ import ( // @FrameworkResource("aws_datazone_environment_profile", name="Environment Profile") func newResourceEnvironmentProfile(_ context.Context) (resource.ResourceWithConfigure, error) { - r := &resourceEnvironmentProfile{} - return r, nil + return &resourceEnvironmentProfile{}, nil } const ( From 751352121423b4682145e8e7920568b77665cb6e Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 17:10:48 -0400 Subject: [PATCH 10/36] Update internal/service/datazone/environment_profile.go Co-authored-by: Jared Baker --- internal/service/datazone/environment_profile.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index b0e459b5d52..7769d52ef39 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -43,7 +43,6 @@ const ( type resourceEnvironmentProfile struct { framework.ResourceWithConfigure - framework.WithTimeouts } func (r *resourceEnvironmentProfile) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { From c8f021b64426969ab8dbfdbbf639f2830df416b1 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 17:10:56 -0400 Subject: [PATCH 11/36] Update internal/service/datazone/environment_profile_test.go Co-authored-by: Jared Baker --- internal/service/datazone/environment_profile_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index 960fe3dd28d..a0c7f7c30b1 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -224,7 +224,6 @@ func testAccAuthorizerEnvProfImportStateIdFunc(resourceName string) resource.Imp return "", fmt.Errorf("Not found: %s", resourceName) } - //return fmt.Sprintf("%s:%s", (rs.Primary.Attributes["domain_identifier"] , rs.Primary.ID, rs.Primary.Attributes["environment_blueprint_identifier"], rs.Primary.Attributes["project_identifier"])), nil return strings.Join([]string{rs.Primary.Attributes["domain_identifier"], rs.Primary.ID, rs.Primary.Attributes["environment_blueprint_identifier"], rs.Primary.Attributes["project_identifier"]}, ":"), nil } From 2f9a3f4a747f31b98ddc07213dd79501b34c8c91 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 17:11:01 -0400 Subject: [PATCH 12/36] Update internal/service/datazone/environment_profile_test.go Co-authored-by: Jared Baker --- internal/service/datazone/environment_profile_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index a0c7f7c30b1..90aff432427 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -251,10 +251,6 @@ resource "aws_datazone_environment_blueprint_configuration" "test" { func testAccEnvironmentProfileConfig_basic(rName, domainName, projectName string) string { return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` - - - - resource "aws_datazone_environment_profile" "test" { aws_account_id = data.aws_caller_identity.test.account_id aws_account_region = data.aws_region.test.name From 413387ef9ae7cff9e52bdb1997d1a8b85bf65057 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 17:11:13 -0400 Subject: [PATCH 13/36] Update website/docs/r/datazone_environment_profile.html.markdown Co-authored-by: Jared Baker --- website/docs/r/datazone_environment_profile.html.markdown | 2 -- 1 file changed, 2 deletions(-) diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 46263a16904..72d2b025664 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -133,8 +133,6 @@ This resource exports the following attributes in addition to the arguments abov * `id` - ID of environment profile. * `updated_at` - Time of last update to environment profile. -## Timeouts - ## Import In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import DataZone Environment Profile using the `example_id_arg`. For example: From afecfe9bb3c74ec2d96ca05a310b163220f798f8 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 17:11:18 -0400 Subject: [PATCH 14/36] Update internal/service/datazone/environment_profile_test.go Co-authored-by: Jared Baker --- internal/service/datazone/environment_profile_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index 90aff432427..38827151468 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -270,10 +270,6 @@ resource "aws_datazone_environment_profile" "test" { func testAccEnvironmentProfileConfig_update(rName, domainName, projectName string) string { return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` - - - - resource "aws_datazone_environment_profile" "test" { aws_account_id = data.aws_caller_identity.test.account_id aws_account_region = data.aws_region.test.name From fb9a1942f78a32bfac2c463e4869b39ad98feb04 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 17:11:30 -0400 Subject: [PATCH 15/36] Update internal/service/datazone/environment_profile.go Co-authored-by: Jared Baker --- internal/service/datazone/environment_profile.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 7769d52ef39..7a652d6aefd 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -125,7 +125,6 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc Attributes: map[string]schema.Attribute{ names.AttrName: schema.StringAttribute{ Optional: true, - Computed: false, }, names.AttrValue: schema.StringAttribute{ Optional: true, From 022965fa3f9ba7c6698a351b1979f831d82202b7 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 29 Jul 2024 17:23:43 -0400 Subject: [PATCH 16/36] PR comment changes --- internal/service/datazone/environment_profile.go | 5 ----- internal/service/datazone/environment_profile_test.go | 1 - website/docs/r/datazone_environment_profile.html.markdown | 6 +++--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 7a652d6aefd..4593c505e02 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -80,11 +80,6 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc }, names.AttrID: schema.StringAttribute{ Computed: true, - /* - Validators: []validator.String{ - stringvalidator.RegexMatches(regexache.MustCompile("^[a-zA-Z0-9_-]{1,36}$"), "must match ^[a-zA-Z0-9_-]{1,36}$"), - }, - */ }, names.AttrName: schema.StringAttribute{ Required: true, diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index 38827151468..c4a2bbb759b 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -224,7 +224,6 @@ func testAccAuthorizerEnvProfImportStateIdFunc(resourceName string) resource.Imp return "", fmt.Errorf("Not found: %s", resourceName) } - return strings.Join([]string{rs.Primary.Attributes["domain_identifier"], rs.Primary.ID, rs.Primary.Attributes["environment_blueprint_identifier"], rs.Primary.Attributes["project_identifier"]}, ":"), nil } } diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 72d2b025664..2f004e0b168 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -135,16 +135,16 @@ This resource exports the following attributes in addition to the arguments abov ## Import -In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import DataZone Environment Profile using the `example_id_arg`. For example: +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import DataZone Environment Profile using the `id`. For example: ```terraform import { to = aws_datazone_environment_profile.example - id = "environment_profile-id-12345678" + id = "domain_identifier:environment_profile_id:environment_blueprint_identifier:project_identifier" } ``` -Using `terraform import`, import DataZone Environment Profile using the `example_id_arg`. For example: +Using `terraform import`, import DataZone Environment Profile using the `id`. For example: ```console % terraform import aws_datazone_environment_profile.example environment_profile-id-12345678 From 1637a4bbc6e9327f8fcfcf9f27385ac94bf83bea Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 30 Jul 2024 16:09:22 -0400 Subject: [PATCH 17/36] Pr fixes --- .../service/datazone/environment_profile.go | 106 ++++------ .../datazone/environment_profile_test.go | 187 ++++++++++++------ ...datazone_environment_profile.html.markdown | 6 +- 3 files changed, 168 insertions(+), 131 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 4593c505e02..b0dee87ed10 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -19,7 +19,7 @@ import ( "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/setplanmodifier" + "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" @@ -70,6 +70,9 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc Validators: []validator.String{ stringvalidator.RegexMatches(regexache.MustCompile("^[a-zA-Z0-9_-]{1,36}$"), "must match ^[a-zA-Z0-9_-]{1,36}$"), }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, names.AttrDescription: schema.StringAttribute{ Optional: true, @@ -110,12 +113,8 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc }, }, Blocks: map[string]schema.Block{ - "user_parameters": schema.SetNestedBlock{ - PlanModifiers: []planmodifier.Set{ - setplanmodifier.RequiresReplace(), - setplanmodifier.RequiresReplaceIfConfigured(), - }, - CustomType: fwtypes.NewSetNestedObjectTypeOf[dUserParameters](ctx), + "user_parameters": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[userParametersData](ctx), NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ names.AttrName: schema.StringAttribute{ @@ -123,7 +122,6 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc }, names.AttrValue: schema.StringAttribute{ Optional: true, - Computed: false, }, }, }, @@ -134,20 +132,22 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { conn := r.Meta().DataZoneClient(ctx) - var plan dEnvProfile + var plan envProfileData resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) if resp.Diagnostics.HasError() { return } + option := func(o *flex.AutoFlexOptions) { + o.AddIgnoredField("UserParameters") + } + in := &datazone.CreateEnvironmentProfileInput{} + in.EnvironmentBlueprintIdentifier = plan.EnvironmentBlueprintId.ValueStringPointer() resp.Diagnostics.Append(flex.Expand(ctx, &plan, in)...) if resp.Diagnostics.HasError() { return } - in.Name = plan.Name.ValueStringPointer() - in.EnvironmentBlueprintIdentifier = plan.EnvironmentBlueprintIdentifier.ValueStringPointer() - in.AwsAccountId = plan.AwsAccountId.ValueStringPointer() out, err := conn.CreateEnvironmentProfile(ctx, in) if err != nil { @@ -165,18 +165,7 @@ func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.Cr return } - plan.AwsAccountId = flex.StringToFramework(ctx, out.AwsAccountId) - plan.AwsAccountRegion = flex.StringToFramework(ctx, out.AwsAccountRegion) - plan.CreatedAt = flex.TimeToFramework(ctx, out.CreatedAt) - plan.CreatedBy = flex.StringToFramework(ctx, out.CreatedBy) - plan.Description = flex.StringToFramework(ctx, out.Description) - plan.DomainIdentifier = flex.StringToFramework(ctx, out.DomainId) - plan.EnvironmentBlueprintIdentifier = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) - plan.Id = flex.StringToFramework(ctx, out.Id) - plan.Name = flex.StringToFramework(ctx, out.Name) - plan.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) - plan.UpdatedAt = flex.TimeToFramework(ctx, out.UpdatedAt) - + resp.Diagnostics.Append(flex.Flatten(ctx, out, &plan, option)...) if resp.Diagnostics.HasError() { return } @@ -185,11 +174,8 @@ func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.Cr func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { conn := r.Meta().DataZoneClient(ctx) - o := flex.AutoFlexOptions{} - o.AddIgnoredField("user_parameters") - // TIP: -- 2. Fetch the state - var state dEnvProfile + var state envProfileData resp.Diagnostics.Append(req.State.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return @@ -208,18 +194,12 @@ func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.Read return } - state.AwsAccountId = flex.StringToFramework(ctx, out.AwsAccountId) - state.AwsAccountRegion = flex.StringToFramework(ctx, out.AwsAccountRegion) - state.CreatedAt = flex.TimeToFramework(ctx, out.CreatedAt) - state.CreatedBy = flex.StringToFramework(ctx, out.CreatedBy) - state.Description = flex.StringToFramework(ctx, out.Description) - state.DomainIdentifier = flex.StringToFramework(ctx, out.DomainId) - state.EnvironmentBlueprintIdentifier = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) - state.Id = flex.StringToFramework(ctx, out.Id) - state.Name = flex.StringToFramework(ctx, out.Name) + option := func(o *flex.AutoFlexOptions) { + o.AddIgnoredField("UserParameters") + } + resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, option)...) + state.EnvironmentBlueprintId = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) state.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) - state.UpdatedAt = flex.TimeToFramework(ctx, out.UpdatedAt) - if resp.Diagnostics.HasError() { return } @@ -229,14 +209,13 @@ func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.Read func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { conn := r.Meta().DataZoneClient(ctx) - var plan, state dEnvProfile + var plan, state envProfileData resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) resp.Diagnostics.Append(req.State.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return } - if plan.EnvironmentBlueprintIdentifier.Equal(state.EnvironmentBlueprintIdentifier) && - plan.ProjectIdentifier.Equal(state.ProjectIdentifier) && plan.DomainIdentifier.Equal(state.DomainIdentifier) { + if !plan.Description.Equal(state.Description) || !plan.Name.Equal(state.Name) || !plan.UserParameters.Equal(state.UserParameters) || !plan.AwsAccountId.Equal(state.AwsAccountId) || !plan.AwsAccountRegion.Equal(state.AwsAccountRegion) { in := &datazone.UpdateEnvironmentProfileInput{} resp.Diagnostics.Append(flex.Expand(ctx, plan, in)...) @@ -252,17 +231,10 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up ) return } - state.AwsAccountId = flex.StringToFramework(ctx, out.AwsAccountId) - state.AwsAccountRegion = flex.StringToFramework(ctx, out.AwsAccountRegion) - state.CreatedAt = flex.TimeToFramework(ctx, out.CreatedAt) - state.CreatedBy = flex.StringToFramework(ctx, out.CreatedBy) - state.Description = flex.StringToFramework(ctx, out.Description) - state.DomainIdentifier = flex.StringToFramework(ctx, out.DomainId) - state.EnvironmentBlueprintIdentifier = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) - state.Id = flex.StringToFramework(ctx, out.Id) - state.Name = flex.StringToFramework(ctx, out.Name) - state.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) - state.UpdatedAt = flex.TimeToFramework(ctx, out.UpdatedAt) + option := func(o *flex.AutoFlexOptions) { + o.AddIgnoredField("UserParameters") + } + resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, option)...) if resp.Diagnostics.HasError() { return @@ -273,7 +245,7 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up func (r *resourceEnvironmentProfile) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { conn := r.Meta().DataZoneClient(ctx) - var state dEnvProfile + var state envProfileData resp.Diagnostics.Append(req.State.Get(ctx, &state)...) _, err := conn.DeleteEnvironmentProfile(ctx, &datazone.DeleteEnvironmentProfileInput{ @@ -291,15 +263,13 @@ func (r *resourceEnvironmentProfile) Delete(ctx context.Context, req resource.De } func (r *resourceEnvironmentProfile) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - parts := strings.Split(req.ID, ":") + parts := strings.Split(req.ID, ",") if len(parts) != 4 { - resp.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "DomainIdentifier:Id"`, req.ID)) + resp.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "DomainIdentifier,Id,EnvironmentBlueprint,Id,ProjectIdentifier"`, req.ID)) } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("domain_identifier"), parts[0])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), parts[1])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("environment_blueprint_identifier"), parts[2])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_identifier"), parts[3])...) } func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id string, domain_id string) (*datazone.GetEnvironmentProfileOutput, error) { @@ -316,7 +286,6 @@ func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id s LastRequest: in, } } - return nil, err } @@ -327,27 +296,24 @@ func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id s return out, nil } -type dEnvProfile struct { - // entered and or computed - AwsAccountId types.String `tfsdk:"aws_account_id"` - AwsAccountRegion types.String `tfsdk:"aws_account_region"` - Description types.String `tfsdk:"description"` - Id types.String `tfsdk:"id"` - EnvironmentBlueprintIdentifier types.String `tfsdk:"environment_blueprint_identifier"` - UserParameters fwtypes.SetNestedObjectValueOf[dUserParameters] `tfsdk:"user_parameters"` +type envProfileData struct { + AwsAccountId types.String `tfsdk:"aws_account_id"` + AwsAccountRegion types.String `tfsdk:"aws_account_region"` + Description types.String `tfsdk:"description"` + Id types.String `tfsdk:"id"` + EnvironmentBlueprintId types.String `tfsdk:"environment_blueprint_identifier"` + UserParameters fwtypes.ListNestedObjectValueOf[userParametersData] `tfsdk:"user_parameters"` Name types.String `tfsdk:"name"` ProjectIdentifier types.String `tfsdk:"project_identifier"` - // computed CreatedAt timetypes.RFC3339 `tfsdk:"created_at"` CreatedBy types.String `tfsdk:"created_by"` DomainIdentifier types.String `tfsdk:"domain_identifier"` UpdatedAt timetypes.RFC3339 `tfsdk:"updated_at"` } -type dUserParameters struct { - // entered +type userParametersData struct { Name types.String `tfsdk:"name"` Value types.String `tfsdk:"value"` } diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index c4a2bbb759b..bd74e442b34 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -13,6 +13,8 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/datazone" "github.com/aws/aws-sdk-go-v2/service/datazone/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/datazone/types" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,6 +23,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/errs" tfdatazone "github.com/hashicorp/terraform-provider-aws/internal/service/datazone" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -35,7 +38,61 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { dName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) pName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - envProfName := "aws_datazone_environment_profile.test" + resourceName := "aws_datazone_environment_profile.test" + domainName := "aws_datazone_domain.test" + callName := "data.aws_caller_identity.test" + projectName := "aws_datazone_project.test" + regionName := "data.aws_region.test" + blueName := "data.aws_datazone_environment_blueprint.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.DataZoneEndpointID) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.DataZoneServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckEnvironmentProfileDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccEnvironmentProfileConfig_basic_base(epName, dName, pName), + Check: resource.ComposeTestCheckFunc( + testAccCheckEnvironmentProfileExists(ctx, resourceName, &environmentprofile), + resource.TestCheckResourceAttrPair(resourceName, names.AttrAWSAccountID, callName, names.AttrAccountID), + resource.TestCheckResourceAttrPair(resourceName, "aws_account_region", regionName, names.AttrName), + resource.TestCheckResourceAttrSet(resourceName, names.AttrCreatedAt), + resource.TestCheckResourceAttrSet(resourceName, "created_by"), + resource.TestCheckResourceAttrPair(resourceName, "domain_identifier", domainName, names.AttrID), + resource.TestCheckResourceAttrPair(resourceName, "environment_blueprint_identifier", blueName, names.AttrID), + resource.TestCheckResourceAttrSet(resourceName, names.AttrID), + resource.TestCheckResourceAttr(resourceName, names.AttrName, epName), + resource.TestCheckResourceAttrPair(resourceName, "project_identifier", projectName, names.AttrID), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), + ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user"}, + }, + }, + }) +} + +func TestAccDataZoneEnvironmentProfile_update(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var environmentprofile datazone.GetEnvironmentProfileOutput + epName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + pName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resourceName := "aws_datazone_environment_profile.test" domainName := "aws_datazone_domain.test" callName := "data.aws_caller_identity.test" projectName := "aws_datazone_project.test" @@ -55,53 +112,53 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { { Config: testAccEnvironmentProfileConfig_basic(epName, dName, pName), Check: resource.ComposeTestCheckFunc( - testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), - resource.TestCheckResourceAttrPair(envProfName, names.AttrAWSAccountID, callName, names.AttrAccountID), - resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, names.AttrName), - resource.TestCheckResourceAttrSet(envProfName, names.AttrCreatedAt), - resource.TestCheckResourceAttrSet(envProfName, "created_by"), - resource.TestCheckResourceAttr(envProfName, names.AttrDescription, "desc"), - resource.TestCheckResourceAttr(envProfName, "user_parameters.0.name", "consumerGlueDbName"), - resource.TestCheckResourceAttr(envProfName, "user_parameters.0.value", names.AttrValue), - resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), - resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, names.AttrID), - resource.TestCheckResourceAttrSet(envProfName, names.AttrID), - resource.TestCheckResourceAttr(envProfName, names.AttrName, epName), - resource.TestCheckResourceAttrPair(envProfName, "project_identifier", projectName, names.AttrID), + testAccCheckEnvironmentProfileExists(ctx, resourceName, &environmentprofile), + resource.TestCheckResourceAttrPair(resourceName, names.AttrAWSAccountID, callName, names.AttrAccountID), + resource.TestCheckResourceAttrPair(resourceName, "aws_account_region", regionName, names.AttrName), + resource.TestCheckResourceAttrSet(resourceName, names.AttrCreatedAt), + resource.TestCheckResourceAttrSet(resourceName, "created_by"), + resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "desc"), + resource.TestCheckResourceAttr(resourceName, "user_parameters.0.name", "consumerGlueDbName"), + resource.TestCheckResourceAttr(resourceName, "user_parameters.0.value", names.AttrValue), + resource.TestCheckResourceAttrPair(resourceName, "domain_identifier", domainName, names.AttrID), + resource.TestCheckResourceAttrPair(resourceName, "environment_blueprint_identifier", blueName, names.AttrID), + resource.TestCheckResourceAttrSet(resourceName, names.AttrID), + resource.TestCheckResourceAttr(resourceName, names.AttrName, epName), + resource.TestCheckResourceAttrPair(resourceName, "project_identifier", projectName, names.AttrID), ), }, { - ResourceName: envProfName, + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(envProfName), + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user"}, }, { Config: testAccEnvironmentProfileConfig_update(epName, dName, pName), Check: resource.ComposeTestCheckFunc( - testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), - testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), - resource.TestCheckResourceAttrPair(envProfName, names.AttrAWSAccountID, callName, names.AttrAccountID), - resource.TestCheckResourceAttrPair(envProfName, "aws_account_region", regionName, names.AttrName), - resource.TestCheckResourceAttrSet(envProfName, names.AttrCreatedAt), - resource.TestCheckResourceAttrSet(envProfName, "created_by"), - resource.TestCheckResourceAttr(envProfName, names.AttrDescription, names.AttrDescription), - resource.TestCheckResourceAttr(envProfName, "user_parameters.0.name", "consumerGlueDbName"), - resource.TestCheckResourceAttr(envProfName, "user_parameters.0.value", names.AttrValue), - resource.TestCheckResourceAttrPair(envProfName, "domain_identifier", domainName, names.AttrID), - resource.TestCheckResourceAttrPair(envProfName, "environment_blueprint_identifier", blueName, names.AttrID), - resource.TestCheckResourceAttrSet(envProfName, names.AttrID), - resource.TestCheckResourceAttr(envProfName, names.AttrName, epName), - resource.TestCheckResourceAttrPair(envProfName, "project_identifier", projectName, names.AttrID), - resource.TestCheckResourceAttrSet(envProfName, "updated_at"), + testAccCheckEnvironmentProfileExists(ctx, resourceName, &environmentprofile), + testAccCheckEnvironmentProfileExists(ctx, resourceName, &environmentprofile), + resource.TestCheckResourceAttrPair(resourceName, names.AttrAWSAccountID, callName, names.AttrAccountID), + resource.TestCheckResourceAttrPair(resourceName, "aws_account_region", regionName, names.AttrName), + resource.TestCheckResourceAttrSet(resourceName, names.AttrCreatedAt), + resource.TestCheckResourceAttrSet(resourceName, "created_by"), + resource.TestCheckResourceAttr(resourceName, names.AttrDescription, names.AttrDescription), + resource.TestCheckResourceAttr(resourceName, "user_parameters.0.name", "consumerGlueDbName"), + resource.TestCheckResourceAttr(resourceName, "user_parameters.0.value", names.AttrValue), + resource.TestCheckResourceAttrPair(resourceName, "domain_identifier", domainName, names.AttrID), + resource.TestCheckResourceAttrPair(resourceName, "environment_blueprint_identifier", blueName, names.AttrID), + resource.TestCheckResourceAttrSet(resourceName, names.AttrID), + resource.TestCheckResourceAttr(resourceName, names.AttrName, epName), + resource.TestCheckResourceAttrPair(resourceName, "project_identifier", projectName, names.AttrID), + resource.TestCheckResourceAttrSet(resourceName, "updated_at"), ), }, { - ResourceName: envProfName, + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(envProfName), + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user"}, }, }, @@ -119,7 +176,7 @@ func TestAccDataZoneEnvironmentProfile_disappears(t *testing.T) { dName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) pName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - envProfName := "aws_datazone_environment_profile.test" + resourceName := "aws_datazone_environment_profile.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -134,8 +191,8 @@ func TestAccDataZoneEnvironmentProfile_disappears(t *testing.T) { { Config: testAccEnvironmentProfileConfig_basic(epName, dName, pName), Check: resource.ComposeTestCheckFunc( - testAccCheckEnvironmentProfileExists(ctx, envProfName, &environmentprofile), - acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfdatazone.ResourceEnvironmentProfile, envProfName), + testAccCheckEnvironmentProfileExists(ctx, resourceName, &environmentprofile), + acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfdatazone.ResourceEnvironmentProfile, resourceName), ), ExpectNonEmptyPlan: true, }, @@ -152,12 +209,7 @@ func testAccCheckEnvironmentProfileDestroy(ctx context.Context) resource.TestChe continue } - t := rs.Primary.Attributes["domain_identifier"] - - _, err := conn.GetEnvironmentProfile(ctx, &datazone.GetEnvironmentProfileInput{ - DomainIdentifier: &t, - Identifier: aws.String(rs.Primary.ID), - }) + _, err := findEnvironmentProfileByID(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["domain_identifier"]) if errs.IsA[*types.ResourceNotFoundException](err) || errs.IsA[*types.AccessDeniedException](err) { return nil @@ -184,12 +236,8 @@ func testAccCheckEnvironmentProfileExists(ctx context.Context, name string, envi return create.Error(names.DataZone, create.ErrActionCheckingExistence, tfdatazone.ResNameEnvironmentProfile, name, errors.New("not set")) } - t := rs.Primary.Attributes["domain_identifier"] conn := acctest.Provider.Meta().(*conns.AWSClient).DataZoneClient(ctx) - resp, err := conn.GetEnvironmentProfile(ctx, &datazone.GetEnvironmentProfileInput{ - DomainIdentifier: &t, - Identifier: &rs.Primary.ID, - }) + resp, err := findEnvironmentProfileByID(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["domain_identifier"]) if err != nil { return create.Error(names.DataZone, create.ErrActionCheckingExistence, tfdatazone.ResNameEnvironmentProfile, rs.Primary.ID, err) @@ -201,21 +249,30 @@ func testAccCheckEnvironmentProfileExists(ctx context.Context, name string, envi } } -/* -func envProfTestAccPreCheck(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).DataZoneClient(ctx) +func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id string, domain_id string) (*datazone.GetEnvironmentProfileOutput, error) { + in := &datazone.GetEnvironmentProfileInput{ + Identifier: aws.String(id), + DomainIdentifier: aws.String(domain_id), + } - input := &datazone.ListEnvironmentProfilesInput{} - _, err := conn.ListEnvironmentProfiles(ctx, input) + out, err := conn.GetEnvironmentProfile(ctx, in) + if err != nil { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } - if acctest.PreCheckSkipError(err) { - t.Skipf("skipping acceptance testing: %s", err) + return nil, err } - if err != nil { - t.Fatalf("unexpected PreCheck error: %s", err) + + if out == nil { + return nil, tfresource.NewEmptyResultError(in) } + + return out, nil } -*/ func testAccAuthorizerEnvProfImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { @@ -224,7 +281,7 @@ func testAccAuthorizerEnvProfImportStateIdFunc(resourceName string) resource.Imp return "", fmt.Errorf("Not found: %s", resourceName) } - return strings.Join([]string{rs.Primary.Attributes["domain_identifier"], rs.Primary.ID, rs.Primary.Attributes["environment_blueprint_identifier"], rs.Primary.Attributes["project_identifier"]}, ":"), nil + return strings.Join([]string{rs.Primary.Attributes["domain_identifier"], rs.Primary.ID, rs.Primary.Attributes["environment_blueprint_identifier"], rs.Primary.Attributes["project_identifier"]}, ","), nil } } @@ -284,3 +341,17 @@ resource "aws_datazone_environment_profile" "test" { } `, rName)) } + +func testAccEnvironmentProfileConfig_basic_base(rName, domainName, projectName string) string { + return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` +resource "aws_datazone_environment_profile" "test" { + aws_account_id = data.aws_caller_identity.test.account_id + aws_account_region = data.aws_region.test.name + environment_blueprint_identifier = data.aws_datazone_environment_blueprint.test.id + name = %[1]q + project_identifier = aws_datazone_project.test.id + domain_identifier = aws_datazone_domain.test.id + +} +`, rName)) +} diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 2f004e0b168..12444ee5ed8 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -140,12 +140,12 @@ In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashico ```terraform import { to = aws_datazone_environment_profile.example - id = "domain_identifier:environment_profile_id:environment_blueprint_identifier:project_identifier" + id = "environment-domain-id-12345678,environment_profile-id-12345678" } ``` -Using `terraform import`, import DataZone Environment Profile using the `id`. For example: +Using `terraform import`, import DataZone Environment Profile using a comma-delimited string combining `enviroment-profile-id` and `enviroment-domain-id`. For example: ```console -% terraform import aws_datazone_environment_profile.example environment_profile-id-12345678 +% terraform import aws_datazone_environment_profile.example environment-domain-id-12345678,environment_profile-id-12345678 ``` From 05e8612c1aba61cf38276235377796b1391674d0 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 30 Jul 2024 16:12:39 -0400 Subject: [PATCH 18/36] Ci formatting change --- website/docs/r/datazone_environment_profile.html.markdown | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 12444ee5ed8..6390397637c 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -119,7 +119,6 @@ The following arguments are required: The following arguments are optional: * `description` - (Optional) Description of environment profile. Must be between the length of 0 and 2048. -* `aws_account_Id` - (Optional) - Id of the AWS account being used. Must follow regex of ^\d{12}$ * `user_parameters` - (Optional) - Array of user parameters of the environment profile with the following attributes: * `name` - (Required) - Name of the environment profile parameter. * `value` - (Required) - Value of the environment profile parameter. @@ -140,11 +139,11 @@ In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashico ```terraform import { to = aws_datazone_environment_profile.example - id = "environment-domain-id-12345678,environment_profile-id-12345678" + id = "domain-id-12345678,environment_profile-id-12345678" } ``` -Using `terraform import`, import DataZone Environment Profile using a comma-delimited string combining `enviroment-profile-id` and `enviroment-domain-id`. For example: +Using `terraform import`, import DataZone Environment Profile using a comma-delimited string combining `environment-profile-id` and `domain-id`. For example: ```console % terraform import aws_datazone_environment_profile.example environment-domain-id-12345678,environment_profile-id-12345678 From b932d1a2cca101e4bfe1f67351cc5f9cacd5206d Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 30 Jul 2024 16:53:05 -0400 Subject: [PATCH 19/36] ci changes --- internal/service/datazone/environment_profile_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index bd74e442b34..128d1e00a46 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -12,7 +12,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/datazone" - "github.com/aws/aws-sdk-go-v2/service/datazone/types" awstypes "github.com/aws/aws-sdk-go-v2/service/datazone/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -211,7 +210,7 @@ func testAccCheckEnvironmentProfileDestroy(ctx context.Context) resource.TestChe _, err := findEnvironmentProfileByID(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["domain_identifier"]) - if errs.IsA[*types.ResourceNotFoundException](err) || errs.IsA[*types.AccessDeniedException](err) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) || errs.IsA[*awstypes.AccessDeniedException](err) { return nil } if err != nil { From 24290f69343bd70d828b4effcb24b7401ff909e7 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Thu, 1 Aug 2024 15:52:49 -0400 Subject: [PATCH 20/36] exported finder function --- .../datazone/environment_profile_test.go | 32 ++----------------- internal/service/datazone/exports_test.go | 1 + 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index 128d1e00a46..3153a491a09 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -10,10 +10,8 @@ import ( "strings" "testing" - "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/datazone" awstypes "github.com/aws/aws-sdk-go-v2/service/datazone/types" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +20,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/errs" tfdatazone "github.com/hashicorp/terraform-provider-aws/internal/service/datazone" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -208,7 +205,7 @@ func testAccCheckEnvironmentProfileDestroy(ctx context.Context) resource.TestChe continue } - _, err := findEnvironmentProfileByID(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["domain_identifier"]) + _, err := tfdatazone.FindEnvironmentProfileByID(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["domain_identifier"]) if errs.IsA[*awstypes.ResourceNotFoundException](err) || errs.IsA[*awstypes.AccessDeniedException](err) { return nil @@ -236,7 +233,7 @@ func testAccCheckEnvironmentProfileExists(ctx context.Context, name string, envi } conn := acctest.Provider.Meta().(*conns.AWSClient).DataZoneClient(ctx) - resp, err := findEnvironmentProfileByID(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["domain_identifier"]) + resp, err := tfdatazone.FindEnvironmentProfileByID(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["domain_identifier"]) if err != nil { return create.Error(names.DataZone, create.ErrActionCheckingExistence, tfdatazone.ResNameEnvironmentProfile, rs.Primary.ID, err) @@ -248,31 +245,6 @@ func testAccCheckEnvironmentProfileExists(ctx context.Context, name string, envi } } -func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id string, domain_id string) (*datazone.GetEnvironmentProfileOutput, error) { - in := &datazone.GetEnvironmentProfileInput{ - Identifier: aws.String(id), - DomainIdentifier: aws.String(domain_id), - } - - out, err := conn.GetEnvironmentProfile(ctx, in) - if err != nil { - if errs.IsA[*awstypes.ResourceNotFoundException](err) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: in, - } - } - - return nil, err - } - - if out == nil { - return nil, tfresource.NewEmptyResultError(in) - } - - return out, nil -} - func testAccAuthorizerEnvProfImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] diff --git a/internal/service/datazone/exports_test.go b/internal/service/datazone/exports_test.go index 25bfe480106..11635545e36 100644 --- a/internal/service/datazone/exports_test.go +++ b/internal/service/datazone/exports_test.go @@ -10,4 +10,5 @@ var ( IsResourceMissing = isResourceMissing ResourceProject = newResourceProject ResourceEnvironmentProfile = newResourceEnvironmentProfile + FindEnvironmentProfileByID = findEnvironmentProfileByID ) From ce41328e63a2d18707c6726a695275d881412c4b Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Mon, 5 Aug 2024 13:21:36 -0400 Subject: [PATCH 21/36] Updated autoflex uptions --- internal/service/datazone/environment_profile.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index b0dee87ed10..2c78bb97853 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -138,10 +138,7 @@ func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.Cr return } - option := func(o *flex.AutoFlexOptions) { - o.AddIgnoredField("UserParameters") - } - + option := flex.WithIgnoredFieldNames([]string{"UserParameters"}) in := &datazone.CreateEnvironmentProfileInput{} in.EnvironmentBlueprintIdentifier = plan.EnvironmentBlueprintId.ValueStringPointer() resp.Diagnostics.Append(flex.Expand(ctx, &plan, in)...) @@ -194,9 +191,7 @@ func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.Read return } - option := func(o *flex.AutoFlexOptions) { - o.AddIgnoredField("UserParameters") - } + option := flex.WithIgnoredFieldNames([]string{"UserParameters"}) resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, option)...) state.EnvironmentBlueprintId = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) state.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) @@ -231,11 +226,8 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up ) return } - option := func(o *flex.AutoFlexOptions) { - o.AddIgnoredField("UserParameters") - } + option := flex.WithIgnoredFieldNames([]string{"UserParameters"}) resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, option)...) - if resp.Diagnostics.HasError() { return } From 57e1db12711ca78c72803a1fa78e0417cb2f3e09 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 13:35:58 -0400 Subject: [PATCH 22/36] Update service_package_gen.go --- internal/service/datazone/service_package_gen.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/datazone/service_package_gen.go b/internal/service/datazone/service_package_gen.go index 3c718e83d82..1d291a03f22 100644 --- a/internal/service/datazone/service_package_gen.go +++ b/internal/service/datazone/service_package_gen.go @@ -36,11 +36,11 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic Factory: newResourceEnvironmentBlueprintConfiguration, Name: "Environment Blueprint Configuration", }, - { + { Factory: newResourceEnvironmentProfile, Name: "Environment Profile", }, - { + { Factory: newResourceGlossary, Name: "Glossary", }, From 0117bc245997be1129d3aaed141d2ebb0db34f81 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 13:41:14 -0400 Subject: [PATCH 23/36] Update environment_profile.go --- internal/service/datazone/environment_profile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 2c78bb97853..317d8c7c911 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -226,7 +226,7 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up ) return } - option := flex.WithIgnoredFieldNames([]string{"UserParameters"}) + option := flex.WithIgnoredFieldNames([]string{"UserParameters"}) resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, option)...) if resp.Diagnostics.HasError() { return From 63d7de025646cdbba01adaaa33e69605a60fab8f Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 13:54:40 -0400 Subject: [PATCH 24/36] Update .changelog/35603.txt Co-authored-by: Jared Baker --- .changelog/35603.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/35603.txt b/.changelog/35603.txt index 206475a611a..4f85b5ed660 100644 --- a/.changelog/35603.txt +++ b/.changelog/35603.txt @@ -1,3 +1,3 @@ ```release-note:new-resource -aws_datazone_environment_blueprint +aws_datazone_environment_profile ``` \ No newline at end of file From 32df38252517a0a4947dff80d67ee73eb2733f01 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 13:55:14 -0400 Subject: [PATCH 25/36] Update website/docs/r/datazone_environment_profile.html.markdown Co-authored-by: Jared Baker --- website/docs/r/datazone_environment_profile.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 6390397637c..112c910abd1 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -109,7 +109,7 @@ resource "aws_datazone_environment_profile" "test" { The following arguments are required: -* `aws_account_Id` - (Required) - Id of the AWS account being used. Must follow regex of ^\d{12}$. +* `aws_account_id` - (Required) - Id of the AWS account being used. Must follow regex of ^\d{12}$. * `aws_account_region` - (Required) - Desired region for environment profile. Must follow regex of ^[a-z]{2}-[a-z]{4,10}-\d$. * `domain_identifier` - (Required) - Domain Identifier for environment profile. * `name` - (Required) - Name of the environment profile. Must follow regex of ^[\w -]+$ and have the length between 1 and 64. From 472ce6d9eb51f6e587e21914ac75d6c69428a66c Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 13:55:50 -0400 Subject: [PATCH 26/36] Update website/docs/r/datazone_environment_profile.html.markdown Co-authored-by: Jared Baker --- website/docs/r/datazone_environment_profile.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 112c910abd1..585a3f1fc47 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -143,7 +143,7 @@ import { } ``` -Using `terraform import`, import DataZone Environment Profile using a comma-delimited string combining `environment-profile-id` and `domain-id`. For example: +Using `terraform import`, import DataZone Environment Profile using a comma-delimited string combining `domain_identifier` and `id`. For example: ```console % terraform import aws_datazone_environment_profile.example environment-domain-id-12345678,environment_profile-id-12345678 From 7ee8b137b553f70e4a055cee4082933ab368dd5f Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 13:56:13 -0400 Subject: [PATCH 27/36] Update internal/service/datazone/environment_profile.go Co-authored-by: Jared Baker --- internal/service/datazone/environment_profile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 317d8c7c911..3bc364aa387 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -191,7 +191,7 @@ func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.Read return } - option := flex.WithIgnoredFieldNames([]string{"UserParameters"}) + option := flex.WithIgnoredFieldNamesAppend("UserParameters") resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, option)...) state.EnvironmentBlueprintId = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) state.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) From c202ca3a5d2b0e50b41057876672d1d849c303cc Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 13:56:26 -0400 Subject: [PATCH 28/36] Update website/docs/r/datazone_environment_profile.html.markdown Co-authored-by: Jared Baker --- website/docs/r/datazone_environment_profile.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 585a3f1fc47..ec8e0803bbc 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -146,5 +146,5 @@ import { Using `terraform import`, import DataZone Environment Profile using a comma-delimited string combining `domain_identifier` and `id`. For example: ```console -% terraform import aws_datazone_environment_profile.example environment-domain-id-12345678,environment_profile-id-12345678 +% terraform import aws_datazone_environment_profile.example domain-id-12345678,environment_profile-id-12345678 ``` From 707c94e6a1338973928c6960e62b5ff8206d1f10 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 13:56:37 -0400 Subject: [PATCH 29/36] Update internal/service/datazone/environment_profile_test.go Co-authored-by: Jared Baker --- internal/service/datazone/environment_profile_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index 3153a491a09..7f6b0501f33 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -71,7 +71,6 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), - ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user"}, }, }, }) From cbbe0fc0513a420175d8fb03ed7bd68823e2da91 Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 14:14:38 -0400 Subject: [PATCH 30/36] Formatting + fixing pr issues --- .../service/datazone/environment_profile.go | 6 ++-- .../datazone/environment_profile_test.go | 28 +++++++++---------- .../service/datazone/service_package_gen.go | 4 +-- ...datazone_environment_profile.html.markdown | 12 ++++---- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 3bc364aa387..c704497cfc5 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -138,7 +138,6 @@ func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.Cr return } - option := flex.WithIgnoredFieldNames([]string{"UserParameters"}) in := &datazone.CreateEnvironmentProfileInput{} in.EnvironmentBlueprintIdentifier = plan.EnvironmentBlueprintId.ValueStringPointer() resp.Diagnostics.Append(flex.Expand(ctx, &plan, in)...) @@ -162,6 +161,7 @@ func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.Cr return } + option := flex.WithIgnoredFieldNamesAppend("UserParameters") resp.Diagnostics.Append(flex.Flatten(ctx, out, &plan, option)...) if resp.Diagnostics.HasError() { return @@ -226,7 +226,7 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up ) return } - option := flex.WithIgnoredFieldNames([]string{"UserParameters"}) + option := flex.WithIgnoredFieldNamesAppend("UserParameters") resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, option)...) if resp.Diagnostics.HasError() { return @@ -257,7 +257,7 @@ func (r *resourceEnvironmentProfile) Delete(ctx context.Context, req resource.De func (r *resourceEnvironmentProfile) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { parts := strings.Split(req.ID, ",") - if len(parts) != 4 { + if len(parts) != 2 { resp.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "DomainIdentifier,Id,EnvironmentBlueprint,Id,ProjectIdentifier"`, req.ID)) } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("domain_identifier"), parts[0])...) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index 7f6b0501f33..25cd1adc089 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -67,10 +67,10 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), }, }, }) @@ -123,11 +123,10 @@ func TestAccDataZoneEnvironmentProfile_update(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), - ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), }, { Config: testAccEnvironmentProfileConfig_update(epName, dName, pName), @@ -150,11 +149,10 @@ func TestAccDataZoneEnvironmentProfile_update(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), - ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), }, }, }) @@ -251,7 +249,7 @@ func testAccAuthorizerEnvProfImportStateIdFunc(resourceName string) resource.Imp return "", fmt.Errorf("Not found: %s", resourceName) } - return strings.Join([]string{rs.Primary.Attributes["domain_identifier"], rs.Primary.ID, rs.Primary.Attributes["environment_blueprint_identifier"], rs.Primary.Attributes["project_identifier"]}, ","), nil + return strings.Join([]string{rs.Primary.Attributes["domain_identifier"], rs.Primary.ID}, ","), nil } } diff --git a/internal/service/datazone/service_package_gen.go b/internal/service/datazone/service_package_gen.go index 1d291a03f22..b7f374cebe3 100644 --- a/internal/service/datazone/service_package_gen.go +++ b/internal/service/datazone/service_package_gen.go @@ -36,11 +36,11 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic Factory: newResourceEnvironmentBlueprintConfiguration, Name: "Environment Blueprint Configuration", }, - { + { Factory: newResourceEnvironmentProfile, Name: "Environment Profile", }, - { + { Factory: newResourceGlossary, Name: "Glossary", }, diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index ec8e0803bbc..21beca9e1b2 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -109,16 +109,16 @@ resource "aws_datazone_environment_profile" "test" { The following arguments are required: -* `aws_account_id` - (Required) - Id of the AWS account being used. Must follow regex of ^\d{12}$. -* `aws_account_region` - (Required) - Desired region for environment profile. Must follow regex of ^[a-z]{2}-[a-z]{4,10}-\d$. +* `aws_account_id` - (Required) - Id of the AWS account being used. +* `aws_account_region` - (Required) - Desired region for environment profile. * `domain_identifier` - (Required) - Domain Identifier for environment profile. -* `name` - (Required) - Name of the environment profile. Must follow regex of ^[\w -]+$ and have the length between 1 and 64. -* `environment_blueprint_identifier` - (Required) - ID of the blueprint which the environment will be created with. Must follow regex of ^[a-zA-Z0-9_-]{1,36}$. -* `project_identifier` - (Required) - Project identifier for environment profile. Must follow regex of ^[a-zA-Z0-9_-]{1,36}$. +* `name` - (Required) - Name of the environment profile. +* `environment_blueprint_identifier` - (Required) - ID of the blueprint which the environment will be created with. +* `project_identifier` - (Required) - Project identifier for environment profile. The following arguments are optional: -* `description` - (Optional) Description of environment profile. Must be between the length of 0 and 2048. +* `description` - (Optional) Description of environment profile. * `user_parameters` - (Optional) - Array of user parameters of the environment profile with the following attributes: * `name` - (Required) - Name of the environment profile parameter. * `value` - (Required) - Value of the environment profile parameter. From 65d3de0bcd763179d8005d35f8adf79d8c0f343c Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 14:18:48 -0400 Subject: [PATCH 31/36] Doc changes --- .../r/datazone_environment_profile.html.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 21beca9e1b2..8bd9d5832e0 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -109,16 +109,16 @@ resource "aws_datazone_environment_profile" "test" { The following arguments are required: -* `aws_account_id` - (Required) - Id of the AWS account being used. -* `aws_account_region` - (Required) - Desired region for environment profile. +* `aws_account_id` - (Required) - Id of the AWS account being used. +* `aws_account_region` - (Required) - Desired region for environment profile. * `domain_identifier` - (Required) - Domain Identifier for environment profile. -* `name` - (Required) - Name of the environment profile. -* `environment_blueprint_identifier` - (Required) - ID of the blueprint which the environment will be created with. -* `project_identifier` - (Required) - Project identifier for environment profile. +* `name` - (Required) - Name of the environment profile. +* `environment_blueprint_identifier` - (Required) - ID of the blueprint which the environment will be created with. +* `project_identifier` - (Required) - Project identifier for environment profile. The following arguments are optional: -* `description` - (Optional) Description of environment profile. +* `description` - (Optional) Description of environment profile. * `user_parameters` - (Optional) - Array of user parameters of the environment profile with the following attributes: * `name` - (Required) - Name of the environment profile parameter. * `value` - (Required) - Value of the environment profile parameter. From f2c2fb7c61d3950510eae32645c15e9b1037fe8b Mon Sep 17 00:00:00 2001 From: ThomasZalewski Date: Tue, 6 Aug 2024 14:52:53 -0400 Subject: [PATCH 32/36] Update internal/service/datazone/environment_profile_test.go Co-authored-by: Jared Baker --- internal/service/datazone/environment_profile_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index 25cd1adc089..fa8e71e1e93 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -270,7 +270,7 @@ resource "aws_datazone_environment_blueprint_configuration" "test" { provisioning_role_arn = aws_iam_role.domain_execution_role.arn enabled_regions = [data.aws_region.test.name] } - `)) +`)) } func testAccEnvironmentProfileConfig_basic(rName, domainName, projectName string) string { From 8a726254c92a6813b8aecf5fe252a23f717e303b Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 12 Aug 2024 14:33:09 -0400 Subject: [PATCH 33/36] r/aws_datazone_environment_profile: alphabetize schema, tidy --- .../service/datazone/environment_profile.go | 88 +++++++++++-------- 1 file changed, 51 insertions(+), 37 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index c704497cfc5..5a8f55b84f5 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -65,6 +65,23 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc stringvalidator.RegexMatches(regexache.MustCompile("^[a-z]{2}-[a-z]{4,10}-\\d$"), "must match ^[a-z]{2}-[a-z]{4,10}-\\d$"), }, }, + names.AttrCreatedAt: schema.StringAttribute{ + CustomType: timetypes.RFC3339Type{}, + Computed: true, + }, + "created_by": schema.StringAttribute{ + Computed: true, + }, + names.AttrDescription: schema.StringAttribute{ + Optional: true, + Computed: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(0, 2048), + }, + }, + "domain_identifier": schema.StringAttribute{ + Required: true, + }, "environment_blueprint_identifier": schema.StringAttribute{ Required: true, Validators: []validator.String{ @@ -74,13 +91,6 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc stringplanmodifier.RequiresReplace(), }, }, - names.AttrDescription: schema.StringAttribute{ - Optional: true, - Computed: true, - Validators: []validator.String{ - stringvalidator.LengthBetween(0, 2048), - }, - }, names.AttrID: schema.StringAttribute{ Computed: true, }, @@ -97,16 +107,6 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc stringvalidator.RegexMatches(regexache.MustCompile("^[a-zA-Z0-9_-]{1,36}$"), "must match ^[a-zA-Z0-9_-]{1,36}$"), }, }, - names.AttrCreatedAt: schema.StringAttribute{ - CustomType: timetypes.RFC3339Type{}, - Computed: true, - }, - "created_by": schema.StringAttribute{ - Computed: true, - }, - "domain_identifier": schema.StringAttribute{ - Required: true, - }, "updated_at": schema.StringAttribute{ CustomType: timetypes.RFC3339Type{}, Computed: true, @@ -132,18 +132,19 @@ func (r *resourceEnvironmentProfile) Schema(ctx context.Context, req resource.Sc func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { conn := r.Meta().DataZoneClient(ctx) - var plan envProfileData + + var plan environmentProfileData resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) if resp.Diagnostics.HasError() { return } in := &datazone.CreateEnvironmentProfileInput{} - in.EnvironmentBlueprintIdentifier = plan.EnvironmentBlueprintId.ValueStringPointer() resp.Diagnostics.Append(flex.Expand(ctx, &plan, in)...) if resp.Diagnostics.HasError() { return } + in.EnvironmentBlueprintIdentifier = plan.EnvironmentBlueprintId.ValueStringPointer() out, err := conn.CreateEnvironmentProfile(ctx, in) if err != nil { @@ -166,13 +167,14 @@ func (r *resourceEnvironmentProfile) Create(ctx context.Context, req resource.Cr if resp.Diagnostics.HasError() { return } + resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) } func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { conn := r.Meta().DataZoneClient(ctx) - var state envProfileData + var state environmentProfileData resp.Diagnostics.Append(req.State.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return @@ -193,24 +195,30 @@ func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.Read option := flex.WithIgnoredFieldNamesAppend("UserParameters") resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, option)...) - state.EnvironmentBlueprintId = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) - state.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) if resp.Diagnostics.HasError() { return } + state.EnvironmentBlueprintId = flex.StringToFramework(ctx, out.EnvironmentBlueprintId) + state.ProjectIdentifier = flex.StringToFramework(ctx, out.ProjectId) + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { conn := r.Meta().DataZoneClient(ctx) - var plan, state envProfileData + var plan, state environmentProfileData resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) resp.Diagnostics.Append(req.State.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return } - if !plan.Description.Equal(state.Description) || !plan.Name.Equal(state.Name) || !plan.UserParameters.Equal(state.UserParameters) || !plan.AwsAccountId.Equal(state.AwsAccountId) || !plan.AwsAccountRegion.Equal(state.AwsAccountRegion) { + + if !plan.Description.Equal(state.Description) || + !plan.Name.Equal(state.Name) || + !plan.UserParameters.Equal(state.UserParameters) || + !plan.AwsAccountId.Equal(state.AwsAccountId) || + !plan.AwsAccountRegion.Equal(state.AwsAccountRegion) { in := &datazone.UpdateEnvironmentProfileInput{} resp.Diagnostics.Append(flex.Expand(ctx, plan, in)...) @@ -218,6 +226,7 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up return } in.Identifier = state.Id.ValueStringPointer() + out, err := conn.UpdateEnvironmentProfile(ctx, in) if err != nil { resp.Diagnostics.AddError( @@ -226,19 +235,25 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up ) return } + option := flex.WithIgnoredFieldNamesAppend("UserParameters") resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, option)...) if resp.Diagnostics.HasError() { return } } + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } func (r *resourceEnvironmentProfile) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { conn := r.Meta().DataZoneClient(ctx) - var state envProfileData + + var state environmentProfileData resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } _, err := conn.DeleteEnvironmentProfile(ctx, &datazone.DeleteEnvironmentProfileInput{ DomainIdentifier: state.DomainIdentifier.ValueStringPointer(), @@ -260,14 +275,15 @@ func (r *resourceEnvironmentProfile) ImportState(ctx context.Context, req resour if len(parts) != 2 { resp.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "DomainIdentifier,Id,EnvironmentBlueprint,Id,ProjectIdentifier"`, req.ID)) } + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("domain_identifier"), parts[0])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), parts[1])...) } -func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id string, domain_id string) (*datazone.GetEnvironmentProfileOutput, error) { +func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id string, domainID string) (*datazone.GetEnvironmentProfileOutput, error) { in := &datazone.GetEnvironmentProfileInput{ Identifier: aws.String(id), - DomainIdentifier: aws.String(domain_id), + DomainIdentifier: aws.String(domainID), } out, err := conn.GetEnvironmentProfile(ctx, in) @@ -288,21 +304,19 @@ func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id s return out, nil } -type envProfileData struct { +type environmentProfileData struct { AwsAccountId types.String `tfsdk:"aws_account_id"` AwsAccountRegion types.String `tfsdk:"aws_account_region"` + CreatedAt timetypes.RFC3339 `tfsdk:"created_at"` + CreatedBy types.String `tfsdk:"created_by"` Description types.String `tfsdk:"description"` - Id types.String `tfsdk:"id"` + DomainIdentifier types.String `tfsdk:"domain_identifier"` EnvironmentBlueprintId types.String `tfsdk:"environment_blueprint_identifier"` + Id types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + ProjectIdentifier types.String `tfsdk:"project_identifier"` + UpdatedAt timetypes.RFC3339 `tfsdk:"updated_at"` UserParameters fwtypes.ListNestedObjectValueOf[userParametersData] `tfsdk:"user_parameters"` - - Name types.String `tfsdk:"name"` - ProjectIdentifier types.String `tfsdk:"project_identifier"` - - CreatedAt timetypes.RFC3339 `tfsdk:"created_at"` - CreatedBy types.String `tfsdk:"created_by"` - DomainIdentifier types.String `tfsdk:"domain_identifier"` - UpdatedAt timetypes.RFC3339 `tfsdk:"updated_at"` } type userParametersData struct { From 852adb33c07da8b0b59005b3b2a7e2502a179d4a Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 12 Aug 2024 14:56:43 -0400 Subject: [PATCH 34/36] r/aws_datazone_environment_profile: tidy import func, tests, docs --- .../service/datazone/environment_profile.go | 21 ++++++++++------- .../datazone/environment_profile_test.go | 23 +++++++++++-------- ...datazone_environment_profile.html.markdown | 8 +++---- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index 5a8f55b84f5..d516cc03e71 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -7,7 +7,6 @@ import ( "context" "errors" "fmt" - "strings" "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" @@ -25,6 +24,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/errs" + intflex "github.com/hashicorp/terraform-provider-aws/internal/flex" "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" @@ -39,6 +39,8 @@ func newResourceEnvironmentProfile(_ context.Context) (resource.ResourceWithConf const ( ResNameEnvironmentProfile = "Environment Profile" + + environmentProfileIDParts = 2 ) type resourceEnvironmentProfile struct { @@ -256,8 +258,8 @@ func (r *resourceEnvironmentProfile) Delete(ctx context.Context, req resource.De } _, err := conn.DeleteEnvironmentProfile(ctx, &datazone.DeleteEnvironmentProfileInput{ - DomainIdentifier: state.DomainIdentifier.ValueStringPointer(), Identifier: state.Id.ValueStringPointer(), + DomainIdentifier: state.DomainIdentifier.ValueStringPointer(), }) if err != nil && !errs.IsA[*awstypes.ResourceNotFoundException](err) { @@ -270,14 +272,17 @@ func (r *resourceEnvironmentProfile) Delete(ctx context.Context, req resource.De } func (r *resourceEnvironmentProfile) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - parts := strings.Split(req.ID, ",") - - if len(parts) != 2 { - resp.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "DomainIdentifier,Id,EnvironmentBlueprint,Id,ProjectIdentifier"`, req.ID)) + parts, err := intflex.ExpandResourceId(req.ID, environmentProfileIDParts, false) + if err != nil { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: id,domain_identifier. Got: %q", req.ID), + ) + return } - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("domain_identifier"), parts[0])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), parts[1])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), parts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("domain_identifier"), parts[1])...) } func findEnvironmentProfileByID(ctx context.Context, conn *datazone.Client, id string, domainID string) (*datazone.GetEnvironmentProfileOutput, error) { diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index fa8e71e1e93..5f519246408 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -7,7 +7,6 @@ import ( "context" "errors" "fmt" - "strings" "testing" "github.com/aws/aws-sdk-go-v2/service/datazone" @@ -249,12 +248,14 @@ func testAccAuthorizerEnvProfImportStateIdFunc(resourceName string) resource.Imp return "", fmt.Errorf("Not found: %s", resourceName) } - return strings.Join([]string{rs.Primary.Attributes["domain_identifier"], rs.Primary.ID}, ","), nil + return fmt.Sprintf("%s,%s", rs.Primary.ID, rs.Primary.Attributes["domain_identifier"]), nil } } func testAccEnvironmentProfileConfig_base(domainName, projectName string) string { - return acctest.ConfigCompose(testAccProjectConfig_basic(projectName, domainName), (` + return acctest.ConfigCompose( + testAccProjectConfig_basic(projectName, domainName), + ` data "aws_caller_identity" "test" {} data "aws_region" "test" {} @@ -270,11 +271,13 @@ resource "aws_datazone_environment_blueprint_configuration" "test" { provisioning_role_arn = aws_iam_role.domain_execution_role.arn enabled_regions = [data.aws_region.test.name] } -`)) +`) } func testAccEnvironmentProfileConfig_basic(rName, domainName, projectName string) string { - return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` + return acctest.ConfigCompose( + testAccEnvironmentProfileConfig_base(domainName, projectName), + fmt.Sprintf(` resource "aws_datazone_environment_profile" "test" { aws_account_id = data.aws_caller_identity.test.account_id aws_account_region = data.aws_region.test.name @@ -287,13 +290,14 @@ resource "aws_datazone_environment_profile" "test" { name = "consumerGlueDbName" value = "value" } - } `, rName)) } func testAccEnvironmentProfileConfig_update(rName, domainName, projectName string) string { - return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` + return acctest.ConfigCompose( + testAccEnvironmentProfileConfig_base(domainName, projectName), + fmt.Sprintf(` resource "aws_datazone_environment_profile" "test" { aws_account_id = data.aws_caller_identity.test.account_id aws_account_region = data.aws_region.test.name @@ -311,7 +315,9 @@ resource "aws_datazone_environment_profile" "test" { } func testAccEnvironmentProfileConfig_basic_base(rName, domainName, projectName string) string { - return acctest.ConfigCompose(testAccEnvironmentProfileConfig_base(domainName, projectName), fmt.Sprintf(` + return acctest.ConfigCompose( + testAccEnvironmentProfileConfig_base(domainName, projectName), + fmt.Sprintf(` resource "aws_datazone_environment_profile" "test" { aws_account_id = data.aws_caller_identity.test.account_id aws_account_region = data.aws_region.test.name @@ -319,7 +325,6 @@ resource "aws_datazone_environment_profile" "test" { name = %[1]q project_identifier = aws_datazone_project.test.id domain_identifier = aws_datazone_domain.test.id - } `, rName)) } diff --git a/website/docs/r/datazone_environment_profile.html.markdown b/website/docs/r/datazone_environment_profile.html.markdown index 8bd9d5832e0..e3e77a9a0ab 100644 --- a/website/docs/r/datazone_environment_profile.html.markdown +++ b/website/docs/r/datazone_environment_profile.html.markdown @@ -134,17 +134,17 @@ This resource exports the following attributes in addition to the arguments abov ## Import -In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import DataZone Environment Profile using the `id`. For example: +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import DataZone Environment Profile using a comma-delimited string combining `id` and `domain_identifier`. For example: ```terraform import { to = aws_datazone_environment_profile.example - id = "domain-id-12345678,environment_profile-id-12345678" + id = "environment_profile-id-12345678,domain-id-12345678" } ``` -Using `terraform import`, import DataZone Environment Profile using a comma-delimited string combining `domain_identifier` and `id`. For example: +Using `terraform import`, import DataZone Environment Profile using a comma-delimited string combining `id` and `domain_identifier`. For example: ```console -% terraform import aws_datazone_environment_profile.example domain-id-12345678,environment_profile-id-12345678 +% terraform import aws_datazone_environment_profile.example environment_profile-id-12345678,domain-id-12345678 ``` From c2330190dd7de430dc2e49a29463eec9e3721607 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 12 Aug 2024 15:10:13 -0400 Subject: [PATCH 35/36] r/aws_datazone_environment_profile(test): fix test failures, tidy --- .../datazone/environment_profile_test.go | 118 +++++++----------- 1 file changed, 47 insertions(+), 71 deletions(-) diff --git a/internal/service/datazone/environment_profile_test.go b/internal/service/datazone/environment_profile_test.go index 5f519246408..0a72d752197 100644 --- a/internal/service/datazone/environment_profile_test.go +++ b/internal/service/datazone/environment_profile_test.go @@ -24,9 +24,6 @@ import ( func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { ctx := acctest.Context(t) - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } var environmentprofile datazone.GetEnvironmentProfileOutput epName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -44,14 +41,13 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(ctx, t) acctest.PreCheckPartitionHasService(t, names.DataZoneEndpointID) - testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.DataZoneServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckEnvironmentProfileDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccEnvironmentProfileConfig_basic_base(epName, dName, pName), + Config: testAccEnvironmentProfileConfig_basic(epName, dName, pName), Check: resource.ComposeTestCheckFunc( testAccCheckEnvironmentProfileExists(ctx, resourceName, &environmentprofile), resource.TestCheckResourceAttrPair(resourceName, names.AttrAWSAccountID, callName, names.AttrAccountID), @@ -66,10 +62,42 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"user_parameters"}, + }, + }, + }) +} + +func TestAccDataZoneEnvironmentProfile_disappears(t *testing.T) { + ctx := acctest.Context(t) + + var environmentprofile datazone.GetEnvironmentProfileOutput + epName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + pName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resourceName := "aws_datazone_environment_profile.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.DataZoneEndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.DataZoneServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckEnvironmentProfileDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccEnvironmentProfileConfig_basic(epName, dName, pName), + Check: resource.ComposeTestCheckFunc( + testAccCheckEnvironmentProfileExists(ctx, resourceName, &environmentprofile), + acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfdatazone.ResourceEnvironmentProfile, resourceName), + ), + ExpectNonEmptyPlan: true, }, }, }) @@ -77,9 +105,6 @@ func TestAccDataZoneEnvironmentProfile_basic(t *testing.T) { func TestAccDataZoneEnvironmentProfile_update(t *testing.T) { ctx := acctest.Context(t) - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } var environmentprofile datazone.GetEnvironmentProfileOutput epName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -97,7 +122,6 @@ func TestAccDataZoneEnvironmentProfile_update(t *testing.T) { PreCheck: func() { acctest.PreCheck(ctx, t) acctest.PreCheckPartitionHasService(t, names.DataZoneEndpointID) - testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.DataZoneServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -122,10 +146,11 @@ func TestAccDataZoneEnvironmentProfile_update(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"user_parameters"}, }, { Config: testAccEnvironmentProfileConfig_update(epName, dName, pName), @@ -148,45 +173,11 @@ func TestAccDataZoneEnvironmentProfile_update(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), - }, - }, - }) -} - -func TestAccDataZoneEnvironmentProfile_disappears(t *testing.T) { - ctx := acctest.Context(t) - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } - - var environmentprofile datazone.GetEnvironmentProfileOutput - epName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - dName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - pName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - - resourceName := "aws_datazone_environment_profile.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, names.DataZoneEndpointID) - testAccPreCheck(ctx, t) - }, - ErrorCheck: acctest.ErrorCheck(t, names.DataZoneServiceID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckEnvironmentProfileDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccEnvironmentProfileConfig_basic(epName, dName, pName), - Check: resource.ComposeTestCheckFunc( - testAccCheckEnvironmentProfileExists(ctx, resourceName, &environmentprofile), - acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfdatazone.ResourceEnvironmentProfile, resourceName), - ), - ExpectNonEmptyPlan: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAuthorizerEnvProfImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"user_parameters"}, }, }, }) @@ -313,18 +304,3 @@ resource "aws_datazone_environment_profile" "test" { } `, rName)) } - -func testAccEnvironmentProfileConfig_basic_base(rName, domainName, projectName string) string { - return acctest.ConfigCompose( - testAccEnvironmentProfileConfig_base(domainName, projectName), - fmt.Sprintf(` -resource "aws_datazone_environment_profile" "test" { - aws_account_id = data.aws_caller_identity.test.account_id - aws_account_region = data.aws_region.test.name - environment_blueprint_identifier = data.aws_datazone_environment_blueprint.test.id - name = %[1]q - project_identifier = aws_datazone_project.test.id - domain_identifier = aws_datazone_domain.test.id -} -`, rName)) -} From 6e053e46b4bd9e8d6eb6dba49a1b269480742894 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 12 Aug 2024 15:15:32 -0400 Subject: [PATCH 36/36] r/aws_datazone_environment_profile: fix err message actions --- internal/service/datazone/environment_profile.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/datazone/environment_profile.go b/internal/service/datazone/environment_profile.go index d516cc03e71..d318ea20543 100644 --- a/internal/service/datazone/environment_profile.go +++ b/internal/service/datazone/environment_profile.go @@ -189,7 +189,7 @@ func (r *resourceEnvironmentProfile) Read(ctx context.Context, req resource.Read } if err != nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.DataZone, create.ErrActionSetting, ResNameEnvironmentProfile, state.Id.String(), err), + create.ProblemStandardMessage(names.DataZone, create.ErrActionReading, ResNameEnvironmentProfile, state.Id.String(), err), err.Error(), ) return @@ -232,7 +232,7 @@ func (r *resourceEnvironmentProfile) Update(ctx context.Context, req resource.Up out, err := conn.UpdateEnvironmentProfile(ctx, in) if err != nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.DataZone, create.ErrActionSetting, ResNameEnvironmentProfile, state.Id.ValueString(), err), + create.ProblemStandardMessage(names.DataZone, create.ErrActionUpdating, ResNameEnvironmentProfile, state.Id.ValueString(), err), err.Error(), ) return @@ -264,7 +264,7 @@ func (r *resourceEnvironmentProfile) Delete(ctx context.Context, req resource.De if err != nil && !errs.IsA[*awstypes.ResourceNotFoundException](err) { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.DataZone, create.ErrActionSetting, ResNameEnvironmentProfile, state.Id.ValueString(), err), + create.ProblemStandardMessage(names.DataZone, create.ErrActionDeleting, ResNameEnvironmentProfile, state.Id.ValueString(), err), err.Error(), ) return