From da535a00ca0b6615c892e835ecffea2374fdcec1 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 30 Nov 2023 16:59:27 -0600 Subject: [PATCH 01/12] aws_codeguruprofiler_profiling_group resource --- .../codeguruprofiler/profiling_group.go | 311 ++++++++++++++++++ .../codeguruprofiler/profiling_group_test.go | 209 ++++++++++++ .../codeguruprofiler/service_package_gen.go | 10 +- ...guruprofiler_profiling_group.html.markdown | 63 ++++ 4 files changed, 592 insertions(+), 1 deletion(-) create mode 100644 internal/service/codeguruprofiler/profiling_group.go create mode 100644 internal/service/codeguruprofiler/profiling_group_test.go create mode 100644 website/docs/r/codeguruprofiler_profiling_group.html.markdown diff --git a/internal/service/codeguruprofiler/profiling_group.go b/internal/service/codeguruprofiler/profiling_group.go new file mode 100644 index 000000000000..67c839eb03a7 --- /dev/null +++ b/internal/service/codeguruprofiler/profiling_group.go @@ -0,0 +1,311 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package codeguruprofiler + +import ( + "context" + "errors" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler" + awstypes "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/types" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "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/listplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" + "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" + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// @FrameworkResource(name="Profiling Group") +// @Tags(identifierAttribute="arn") +func newResourceProfilingGroup(_ context.Context) (resource.ResourceWithConfigure, error) { + r := &resourceProfilingGroup{} + + return r, nil +} + +const ( + ResNameProfilingGroup = "Profiling Group" +) + +type resourceProfilingGroup struct { + framework.ResourceWithConfigure +} + +func (r *resourceProfilingGroup) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = "aws_codeguruprofiler_profiling_group" +} + +func (r *resourceProfilingGroup) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + computePlatform := fwtypes.StringEnumType[awstypes.ComputePlatform]() + + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "arn": framework.ARNAttributeComputedOnly(), + "compute_platform": schema.StringAttribute{ + CustomType: computePlatform, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "id": framework.IDAttribute(), + "profiling_group_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "profiling_status": schema.ListAttribute{ + CustomType: fwtypes.NewListNestedObjectTypeOf[profilingStatus](ctx), + Computed: true, + ElementType: fwtypes.NewObjectTypeOf[profilingStatus](ctx), + PlanModifiers: []planmodifier.List{ + listplanmodifier.UseStateForUnknown(), + }, + }, + names.AttrTags: tftags.TagsAttribute(), + names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), + }, + Blocks: map[string]schema.Block{ + "agent_orchestration_config": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[agentOrchestrationConfig](ctx), + Validators: []validator.List{ + listvalidator.SizeAtMost(1), + listvalidator.IsRequired(), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "profiling_enabled": schema.BoolAttribute{ + Required: true, + }, + }, + }, + }, + }, + } +} + +func (r *resourceProfilingGroup) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + conn := r.Meta().CodeGuruProfilerClient(ctx) + + var plan resourceProfilingGroupData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + in := &codeguruprofiler.CreateProfilingGroupInput{} + resp.Diagnostics.Append(flex.Expand(ctx, plan, in)...) + + if resp.Diagnostics.HasError() { + return + } + + in.ClientToken = aws.String(id.UniqueId()) + in.Tags = getTagsIn(ctx) + + out, err := conn.CreateProfilingGroup(ctx, in) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionCreating, ResNameProfilingGroup, plan.ProfilingGroupName.ValueString(), err), + err.Error(), + ) + return + } + if out == nil || out.ProfilingGroup == nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionCreating, ResNameProfilingGroup, plan.ProfilingGroupName.ValueString(), nil), + errors.New("empty output").Error(), + ) + return + } + + state := plan + + resp.Diagnostics.Append(flex.Flatten(ctx, out.ProfilingGroup, &state)...) + + state.ID = flex.StringToFramework(ctx, out.ProfilingGroup.Name) + + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) +} + +func (r *resourceProfilingGroup) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + conn := r.Meta().CodeGuruProfilerClient(ctx) + + var state resourceProfilingGroupData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + out, err := findProfilingGroupByName(ctx, conn, state.ID.ValueString()) + if tfresource.NotFound(err) { + resp.State.RemoveResource(ctx) + return + } + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionSetting, ResNameProfilingGroup, state.ID.String(), err), + err.Error(), + ) + return + } + + resp.Diagnostics.Append(flex.Flatten(ctx, out, &state)...) + + if resp.Diagnostics.HasError() { + return + } + + //state.ProfilingStatus = fwtypes.NewListNestedObjectValueOfPtr(ctx, &profilingStatus{ + // LatestAgentOrchestratedAt: flex.StringValueToFramework(ctx, out.ProfilingStatus.LatestAgentOrchestratedAt.Format(time.RFC3339)), + // LatestAgentProfileReportedAt: flex.StringValueToFramework(ctx, out.ProfilingStatus.LatestAgentProfileReportedAt.Format(time.RFC3339)), + //}) + + setTagsOut(ctx, out.Tags) + + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) +} + +func (r *resourceProfilingGroup) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + conn := r.Meta().CodeGuruProfilerClient(ctx) + + var plan, state resourceProfilingGroupData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + + if resp.Diagnostics.HasError() { + return + } + + if !plan.AgentOrchestrationConfig.Equal(state.AgentOrchestrationConfig) { + in := &codeguruprofiler.UpdateProfilingGroupInput{} + resp.Diagnostics.Append(flex.Expand(ctx, plan, in)...) + + if resp.Diagnostics.HasError() { + return + } + + out, err := conn.UpdateProfilingGroup(ctx, in) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionUpdating, ResNameProfilingGroup, plan.ID.String(), err), + err.Error(), + ) + return + } + + if out == nil || out.ProfilingGroup == nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionUpdating, ResNameProfilingGroup, plan.ID.String(), nil), + errors.New("empty output").Error(), + ) + return + } + } + + resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) +} + +func (r *resourceProfilingGroup) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + conn := r.Meta().CodeGuruProfilerClient(ctx) + + var state resourceProfilingGroupData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + in := &codeguruprofiler.DeleteProfilingGroupInput{ + ProfilingGroupName: aws.String(state.ID.ValueString()), + } + + _, err := conn.DeleteProfilingGroup(ctx, in) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return + } + + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionDeleting, ResNameProfilingGroup, state.ID.String(), err), + err.Error(), + ) + return + } +} + +func (r *resourceProfilingGroup) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +func (r *resourceProfilingGroup) ModifyPlan(ctx context.Context, request resource.ModifyPlanRequest, response *resource.ModifyPlanResponse) { + r.SetTagsAll(ctx, request, response) +} + +func findProfilingGroupByName(ctx context.Context, conn *codeguruprofiler.Client, name string) (*awstypes.ProfilingGroupDescription, error) { + in := &codeguruprofiler.DescribeProfilingGroupInput{ + ProfilingGroupName: aws.String(name), + } + + out, err := conn.DescribeProfilingGroup(ctx, in) + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + if err != nil { + return nil, err + } + + if out == nil || out.ProfilingGroup == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + return out.ProfilingGroup, nil +} + +type resourceProfilingGroupData struct { + ARN types.String `tfsdk:"arn"` + AgentOrchestrationConfig fwtypes.ListNestedObjectValueOf[agentOrchestrationConfig] `tfsdk:"agent_orchestration_config"` + ComputePlatform fwtypes.StringEnum[awstypes.ComputePlatform] `tfsdk:"compute_platform"` + ID types.String `tfsdk:"id"` + ProfilingGroupName types.String `tfsdk:"profiling_group_name"` + ProfilingStatus fwtypes.ListNestedObjectValueOf[profilingStatus] `tfsdk:"profiling_status"` + Tags types.Map `tfsdk:"tags"` + TagsAll types.Map `tfsdk:"tags_all"` +} + +type agentOrchestrationConfig struct { + ProfilingEnabled types.Bool `tfsdk:"profiling_enabled"` +} + +type profilingStatus struct { + LatestAgentOrchestratedAt types.String `tfsdk:"latest_agent_orchestrated_at"` + LatestAgentProfileReportedAt types.String `tfsdk:"latest_agent_profile_reported_at"` + LatestAggregatedProfile fwtypes.ListNestedObjectValueOf[aggregatedProfileTime] `tfsdk:"latest_aggregated_profile"` +} + +type aggregatedProfileTime struct { + Period types.String `tfsdk:"period"` + Start types.String `tfsdk:"start"` +} diff --git a/internal/service/codeguruprofiler/profiling_group_test.go b/internal/service/codeguruprofiler/profiling_group_test.go new file mode 100644 index 000000000000..d3408b3ae482 --- /dev/null +++ b/internal/service/codeguruprofiler/profiling_group_test.go @@ -0,0 +1,209 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package codeguruprofiler_test + +//import ( +// "context" +// "errors" +// "fmt" +// "testing" +// +// "github.com/YakDriver/regexache" +// +// "github.com/aws/aws-sdk-go-v2/aws" +// "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler" +// "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/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" +// "github.com/hashicorp/terraform-provider-aws/names" +// tfcodeguruprofiler "github.com/hashicorp/terraform-provider-aws/internal/service/codeguruprofiler" +//) +// +//func TestAccCodeGuruProfilerProfilingGroup_basic(t *testing.T) { +// ctx := acctest.Context(t) +// if testing.Short() { +// t.Skip("skipping long-running test in short mode") +// } +// +// var profilinggroup codeguruprofiler.DescribeProfilingGroupResponse +// rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) +// resourceName := "aws_codeguruprofiler_profiling_group.test" +// +// resource.ParallelTest(t, resource.TestCase{ +// PreCheck: func() { +// acctest.PreCheck(ctx, t) +// acctest.PreCheckPartitionHasService(t, names.CodeGuruProfilerEndpointID) +// testAccPreCheck(ctx, t) +// }, +// ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), +// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, +// CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), +// Steps: []resource.TestStep{ +// { +// Config: testAccProfilingGroupConfig_basic(rName), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), +// resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "false"), +// resource.TestCheckResourceAttrSet(resourceName, "maintenance_window_start_time.0.day_of_week"), +// resource.TestCheckTypeSetElemNestedAttrs(resourceName, "user.*", map[string]string{ +// "console_access": "false", +// "groups.#": "0", +// "username": "Test", +// "password": "TestTest1234", +// }), +// acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "codeguruprofiler", regexache.MustCompile(`profilinggroup:+.`)), +// ), +// }, +// { +// ResourceName: resourceName, +// ImportState: true, +// ImportStateVerify: true, +// ImportStateVerifyIgnore: []string{"apply_immediately", "user"}, +// }, +// }, +// }) +//} +// +//func TestAccCodeGuruProfilerProfilingGroup_disappears(t *testing.T) { +// ctx := acctest.Context(t) +// if testing.Short() { +// t.Skip("skipping long-running test in short mode") +// } +// +// var profilinggroup codeguruprofiler.DescribeProfilingGroupResponse +// rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) +// resourceName := "aws_codeguruprofiler_profiling_group.test" +// +// resource.ParallelTest(t, resource.TestCase{ +// PreCheck: func() { +// acctest.PreCheck(ctx, t) +// acctest.PreCheckPartitionHasService(t, names.CodeGuruProfilerEndpointID) +// testAccPreCheck(t) +// }, +// ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), +// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, +// CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), +// Steps: []resource.TestStep{ +// { +// Config: testAccProfilingGroupConfig_basic(rName, testAccProfilingGroupVersionNewer), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), +// acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfcodeguruprofiler.ResourceProfilingGroup, resourceName), +// ), +// ExpectNonEmptyPlan: true, +// }, +// }, +// }) +//} +// +//func testAccCheckProfilingGroupDestroy(ctx context.Context) resource.TestCheckFunc { +// return func(s *terraform.State) error { +// conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruProfilerClient(ctx) +// +// for _, rs := range s.RootModule().Resources { +// if rs.Type != "aws_codeguruprofiler_profiling_group" { +// continue +// } +// +// input := &codeguruprofiler.DescribeProfilingGroupInput{ +// ProfilingGroupId: aws.String(rs.Primary.ID), +// } +// _, err := conn.DescribeProfilingGroup(ctx, &codeguruprofiler.DescribeProfilingGroupInput{ +// ProfilingGroupId: aws.String(rs.Primary.ID), +// }) +// if errs.IsA[*types.ResourceNotFoundException](err){ +// return nil +// } +// if err != nil { +// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingDestroyed, tfcodeguruprofiler.ResNameProfilingGroup, rs.Primary.ID, err) +// } +// +// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingDestroyed, tfcodeguruprofiler.ResNameProfilingGroup, rs.Primary.ID, errors.New("not destroyed")) +// } +// +// return nil +// } +//} +// +//func testAccCheckProfilingGroupExists(ctx context.Context, name string, profilinggroup *codeguruprofiler.DescribeProfilingGroupResponse) resource.TestCheckFunc { +// return func(s *terraform.State) error { +// rs, ok := s.RootModule().Resources[name] +// if !ok { +// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingExistence, tfcodeguruprofiler.ResNameProfilingGroup, name, errors.New("not found")) +// } +// +// if rs.Primary.ID == "" { +// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingExistence, tfcodeguruprofiler.ResNameProfilingGroup, name, errors.New("not set")) +// } +// +// conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruProfilerClient(ctx) +// resp, err := conn.DescribeProfilingGroup(ctx, &codeguruprofiler.DescribeProfilingGroupInput{ +// ProfilingGroupId: aws.String(rs.Primary.ID), +// }) +// +// if err != nil { +// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingExistence, tfcodeguruprofiler.ResNameProfilingGroup, rs.Primary.ID, err) +// } +// +// *profilinggroup = *resp +// +// return nil +// } +//} +// +//func testAccPreCheck(ctx context.Context, t *testing.T) { +// conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruProfilerClient(ctx) +// +// input := &codeguruprofiler.ListProfilingGroupsInput{} +// _, err := conn.ListProfilingGroups(ctx, input) +// +// if acctest.PreCheckSkipError(err) { +// t.Skipf("skipping acceptance testing: %s", err) +// } +// if err != nil { +// t.Fatalf("unexpected PreCheck error: %s", err) +// } +//} +// +//func testAccCheckProfilingGroupNotRecreated(before, after *codeguruprofiler.DescribeProfilingGroupResponse) resource.TestCheckFunc { +// return func(s *terraform.State) error { +// if before, after := aws.ToString(before.ProfilingGroupId), aws.ToString(after.ProfilingGroupId); before != after { +// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingNotRecreated, tfcodeguruprofiler.ResNameProfilingGroup, aws.ToString(before.ProfilingGroupId), errors.New("recreated")) +// } +// +// return nil +// } +//} +// +//func testAccProfilingGroupConfig_basic(rName, version string) string { +// return fmt.Sprintf(` +//resource "aws_security_group" "test" { +// name = %[1]q +//} +// +//resource "aws_codeguruprofiler_profiling_group" "test" { +// profiling_group_name = %[1]q +// engine_type = "ActiveCodeGuruProfiler" +// engine_version = %[2]q +// host_instance_type = "codeguruprofiler.t2.micro" +// security_groups = [aws_security_group.test.id] +// authentication_strategy = "simple" +// storage_type = "efs" +// +// logs { +// general = true +// } +// +// user { +// username = "Test" +// password = "TestTest1234" +// } +//} +//`, rName, version) +//} diff --git a/internal/service/codeguruprofiler/service_package_gen.go b/internal/service/codeguruprofiler/service_package_gen.go index 36a71bbefe64..119f9aeacdab 100644 --- a/internal/service/codeguruprofiler/service_package_gen.go +++ b/internal/service/codeguruprofiler/service_package_gen.go @@ -19,7 +19,15 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv } func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { - return []*types.ServicePackageFrameworkResource{} + return []*types.ServicePackageFrameworkResource{ + { + Factory: newResourceProfilingGroup, + Name: "Profiling Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, + }, + } } func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { diff --git a/website/docs/r/codeguruprofiler_profiling_group.html.markdown b/website/docs/r/codeguruprofiler_profiling_group.html.markdown new file mode 100644 index 000000000000..ba0424f8a3ae --- /dev/null +++ b/website/docs/r/codeguruprofiler_profiling_group.html.markdown @@ -0,0 +1,63 @@ +--- +subcategory: "CodeGuru Profiler" +layout: "aws" +page_title: "AWS: aws_codeguruprofiler_profiling_group" +description: |- + Terraform resource for managing an AWS CodeGuru Profiler Profiling Group. +--- +# Resource: aws_codeguruprofiler_profiling_group + +Terraform resource for managing an AWS CodeGuru Profiler Profiling Group. + +## Example Usage + +### Basic Usage + +```terraform +resource "aws_codeguruprofiler_profiling_group" "example" { +} +``` + +## Argument Reference + +The following arguments are required: + +* `example_arg` - (Required) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. + +The following arguments are optional: + +* `optional_arg` - (Optional) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `tags` - (Optional) A map of tags assigned to the WorkSpaces Connection Alias. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. + +## Attribute Reference + +This resource exports the following attributes in addition to the arguments above: + +* `arn` - ARN of the Profiling Group. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `example_attribute` - Concise description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). + +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +* `create` - (Default `60m`) +* `update` - (Default `180m`) +* `delete` - (Default `90m`) + +## Import + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import CodeGuru Profiler Profiling Group using the `example_id_arg`. For example: + +```terraform +import { + to = aws_codeguruprofiler_profiling_group.example + id = "profiling_group-id-12345678" +} +``` + +Using `terraform import`, import CodeGuru Profiler Profiling Group using the `example_id_arg`. For example: + +```console +% terraform import aws_codeguruprofiler_profiling_group.example profiling_group-id-12345678 +``` From c1e6bc37412a0d96f80cbb75b23b616607d86063 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 30 Nov 2023 17:23:43 -0600 Subject: [PATCH 02/12] aws_codeguruprofiler_profiling_group datasource --- .../codeguruprofiler/profiling_group.go | 5 - .../profiling_group_data_source.go | 124 ++++++++++++++++++ .../profiling_group_data_source_test.go | 94 +++++++++++++ .../codeguruprofiler/service_package_gen.go | 7 +- ...guruprofiler_profiling_group.html.markdown | 38 ++++++ 5 files changed, 262 insertions(+), 6 deletions(-) create mode 100644 internal/service/codeguruprofiler/profiling_group_data_source.go create mode 100644 internal/service/codeguruprofiler/profiling_group_data_source_test.go create mode 100644 website/docs/d/codeguruprofiler_profiling_group.html.markdown diff --git a/internal/service/codeguruprofiler/profiling_group.go b/internal/service/codeguruprofiler/profiling_group.go index 67c839eb03a7..c06fbdcab59f 100644 --- a/internal/service/codeguruprofiler/profiling_group.go +++ b/internal/service/codeguruprofiler/profiling_group.go @@ -174,11 +174,6 @@ func (r *resourceProfilingGroup) Read(ctx context.Context, req resource.ReadRequ return } - //state.ProfilingStatus = fwtypes.NewListNestedObjectValueOfPtr(ctx, &profilingStatus{ - // LatestAgentOrchestratedAt: flex.StringValueToFramework(ctx, out.ProfilingStatus.LatestAgentOrchestratedAt.Format(time.RFC3339)), - // LatestAgentProfileReportedAt: flex.StringValueToFramework(ctx, out.ProfilingStatus.LatestAgentProfileReportedAt.Format(time.RFC3339)), - //}) - setTagsOut(ctx, out.Tags) resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) diff --git a/internal/service/codeguruprofiler/profiling_group_data_source.go b/internal/service/codeguruprofiler/profiling_group_data_source.go new file mode 100644 index 000000000000..661aee6afd30 --- /dev/null +++ b/internal/service/codeguruprofiler/profiling_group_data_source.go @@ -0,0 +1,124 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package codeguruprofiler + +import ( + "context" + + awstypes "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/types" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "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" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// @FrameworkDataSource(name="Profiling Group") +func newDataSourceProfilingGroup(context.Context) (datasource.DataSourceWithConfigure, error) { + return &dataSourceProfilingGroup{}, nil +} + +const ( + DSNameProfilingGroup = "Profiling Group Data Source" +) + +type dataSourceProfilingGroup struct { + framework.DataSourceWithConfigure +} + +func (d *dataSourceProfilingGroup) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name + resp.TypeName = "aws_codeguruprofiler_profiling_group" +} + +func (d *dataSourceProfilingGroup) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + computePlatform := fwtypes.StringEnumType[awstypes.ComputePlatform]() + + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "agent_orchestration_config": schema.ListAttribute{ + CustomType: fwtypes.NewListNestedObjectTypeOf[dsAgentOrchestrationConfig](ctx), + Computed: true, + ElementType: fwtypes.NewObjectTypeOf[dsAgentOrchestrationConfig](ctx), + }, + "arn": framework.ARNAttributeComputedOnly(), + "compute_platform": schema.StringAttribute{ + CustomType: computePlatform, + Computed: true, + }, + "id": framework.IDAttribute(), + "name": schema.StringAttribute{ + Required: true, + }, + "profiling_status": schema.ListAttribute{ + CustomType: fwtypes.NewListNestedObjectTypeOf[dsProfilingStatus](ctx), + Computed: true, + ElementType: fwtypes.NewObjectTypeOf[dsProfilingStatus](ctx), + }, + names.AttrTags: tftags.TagsAttributeComputedOnly(), + }, + } +} +func (d *dataSourceProfilingGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + conn := d.Meta().CodeGuruProfilerClient(ctx) + + var data dataSourceProfilingGroupData + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + out, err := findProfilingGroupByName(ctx, conn, data.Name.ValueString()) + if tfresource.NotFound(err) { + resp.State.RemoveResource(ctx) + return + } + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionSetting, DSNameProfilingGroup, data.Name.ValueString(), err), + err.Error(), + ) + return + } + + resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + data.ID = flex.StringToFramework(ctx, out.Name) + data.Tags = flex.FlattenFrameworkStringValueMap(ctx, out.Tags) + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +type dataSourceProfilingGroupData struct { + ARN types.String `tfsdk:"arn"` + AgentOrchestrationConfig fwtypes.ListNestedObjectValueOf[dsAgentOrchestrationConfig] `tfsdk:"agent_orchestration_config"` + ComputePlatform fwtypes.StringEnum[awstypes.ComputePlatform] `tfsdk:"compute_platform"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + ProfilingStatus fwtypes.ListNestedObjectValueOf[dsProfilingStatus] `tfsdk:"profiling_status"` + Tags types.Map `tfsdk:"tags"` +} + +type dsAgentOrchestrationConfig struct { + ProfilingEnabled types.Bool `tfsdk:"profiling_enabled"` +} + +type dsProfilingStatus struct { + LatestAgentOrchestratedAt types.String `tfsdk:"latest_agent_orchestrated_at"` + LatestAgentProfileReportedAt types.String `tfsdk:"latest_agent_profile_reported_at"` + LatestAggregatedProfile fwtypes.ListNestedObjectValueOf[dsAggregatedProfileTime] `tfsdk:"latest_aggregated_profile"` +} + +type dsAggregatedProfileTime struct { + Period types.String `tfsdk:"period"` + Start types.String `tfsdk:"start"` +} diff --git a/internal/service/codeguruprofiler/profiling_group_data_source_test.go b/internal/service/codeguruprofiler/profiling_group_data_source_test.go new file mode 100644 index 000000000000..5ea403636465 --- /dev/null +++ b/internal/service/codeguruprofiler/profiling_group_data_source_test.go @@ -0,0 +1,94 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package codeguruprofiler_test + +//import ( +// "fmt" +// "strings" +// "testing" +// +// "github.com/YakDriver/regexache" +// +// "github.com/aws/aws-sdk-go-v2/aws" +// "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler" +// "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/types" +// "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" +// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +// 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" +// tfcodeguruprofiler "github.com/hashicorp/terraform-provider-aws/internal/service/codeguruprofiler" +// "github.com/hashicorp/terraform-provider-aws/names" +//) +// +// +// +//func TestAccCodeGuruProfilerProfilingGroupDataSource_basic(t *testing.T) { +// ctx := acctest.Context(t) +// if testing.Short() { +// t.Skip("skipping long-running test in short mode") +// } +// +// var profilinggroup codeguruprofiler.DescribeProfilingGroupResponse +// rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) +// dataSourceName := "data.aws_codeguruprofiler_profiling_group.test" +// +// resource.ParallelTest(t, resource.TestCase{ +// PreCheck: func() { +// acctest.PreCheck(ctx, t) +// acctest.PreCheckPartitionHasService(t, codeguruprofiler.EndpointsID) +// testAccPreCheck(ctx, t) +// }, +// ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), +// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, +// CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), +// Steps: []resource.TestStep{ +// { +// Config: testAccProfilingGroupDataSourceConfig_basic(rName), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckProfilingGroupExists(ctx, dataSourceName, &profilinggroup), +// resource.TestCheckResourceAttr(dataSourceName, "auto_minor_version_upgrade", "false"), +// resource.TestCheckResourceAttrSet(dataSourceName, "maintenance_window_start_time.0.day_of_week"), +// resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "user.*", map[string]string{ +// "console_access": "false", +// "groups.#": "0", +// "username": "Test", +// "password": "TestTest1234", +// }), +// acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "codeguruprofiler", regexache.MustCompile(`profilinggroup:+.`)), +// ), +// }, +// }, +// }) +//} +// +//func testAccProfilingGroupDataSourceConfig_basic(rName, version string) string { +// return fmt.Sprintf(` +//data "aws_security_group" "test" { +// name = %[1]q +//} +// +//data "aws_codeguruprofiler_profiling_group" "test" { +// profiling_group_name = %[1]q +// engine_type = "ActiveCodeGuruProfiler" +// engine_version = %[2]q +// host_instance_type = "codeguruprofiler.t2.micro" +// security_groups = [aws_security_group.test.id] +// authentication_strategy = "simple" +// storage_type = "efs" +// +// logs { +// general = true +// } +// +// user { +// username = "Test" +// password = "TestTest1234" +// } +//} +//`, rName, version) +//} diff --git a/internal/service/codeguruprofiler/service_package_gen.go b/internal/service/codeguruprofiler/service_package_gen.go index 119f9aeacdab..7fbe3497966e 100644 --- a/internal/service/codeguruprofiler/service_package_gen.go +++ b/internal/service/codeguruprofiler/service_package_gen.go @@ -15,7 +15,12 @@ import ( type servicePackage struct{} func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { - return []*types.ServicePackageFrameworkDataSource{} + return []*types.ServicePackageFrameworkDataSource{ + { + Factory: newDataSourceProfilingGroup, + Name: "Profiling Group", + }, + } } func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { diff --git a/website/docs/d/codeguruprofiler_profiling_group.html.markdown b/website/docs/d/codeguruprofiler_profiling_group.html.markdown new file mode 100644 index 000000000000..f2314043f4b6 --- /dev/null +++ b/website/docs/d/codeguruprofiler_profiling_group.html.markdown @@ -0,0 +1,38 @@ +--- +subcategory: "CodeGuru Profiler" +layout: "aws" +page_title: "AWS: aws_codeguruprofiler_profiling_group" +description: |- + Terraform data source for managing an AWS CodeGuru Profiler Profiling Group. +--- + +# Data Source: aws_codeguruprofiler_profiling_group + +Terraform data source for managing an AWS CodeGuru Profiler Profiling Group. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_codeguruprofiler_profiling_group" "example" { +} +``` + +## Argument Reference + +The following arguments are required: + +* `example_arg` - (Required) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. + +The following arguments are optional: + +* `optional_arg` - (Optional) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `arn` - ARN of the Profiling Group. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `example_attribute` - Concise description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `tags` - Mapping of Key-Value tags for the resource. \ No newline at end of file From 53de08ddcb6361dea9eee4a2808f3258843efd6e Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 30 Nov 2023 17:38:46 -0600 Subject: [PATCH 03/12] aws_codeguruprofiler_profiling_group: simplify name --- internal/service/codeguruprofiler/profiling_group.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/service/codeguruprofiler/profiling_group.go b/internal/service/codeguruprofiler/profiling_group.go index c06fbdcab59f..0a177caaf32b 100644 --- a/internal/service/codeguruprofiler/profiling_group.go +++ b/internal/service/codeguruprofiler/profiling_group.go @@ -66,7 +66,7 @@ func (r *resourceProfilingGroup) Schema(ctx context.Context, req resource.Schema }, }, "id": framework.IDAttribute(), - "profiling_group_name": schema.StringAttribute{ + "name": schema.StringAttribute{ Required: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), @@ -118,20 +118,21 @@ func (r *resourceProfilingGroup) Create(ctx context.Context, req resource.Create return } + in.ProfilingGroupName = flex.StringFromFramework(ctx, plan.Name) in.ClientToken = aws.String(id.UniqueId()) in.Tags = getTagsIn(ctx) out, err := conn.CreateProfilingGroup(ctx, in) if err != nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionCreating, ResNameProfilingGroup, plan.ProfilingGroupName.ValueString(), err), + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionCreating, ResNameProfilingGroup, plan.Name.ValueString(), err), err.Error(), ) return } if out == nil || out.ProfilingGroup == nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionCreating, ResNameProfilingGroup, plan.ProfilingGroupName.ValueString(), nil), + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionCreating, ResNameProfilingGroup, plan.Name.ValueString(), nil), errors.New("empty output").Error(), ) return @@ -162,7 +163,7 @@ func (r *resourceProfilingGroup) Read(ctx context.Context, req resource.ReadRequ } if err != nil { resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionSetting, ResNameProfilingGroup, state.ID.String(), err), + create.ProblemStandardMessage(names.CodeGuruProfiler, create.ErrActionSetting, ResNameProfilingGroup, state.ID.ValueString(), err), err.Error(), ) return @@ -174,6 +175,7 @@ func (r *resourceProfilingGroup) Read(ctx context.Context, req resource.ReadRequ return } + state.Name = flex.StringToFramework(ctx, out.Name) setTagsOut(ctx, out.Tags) resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) @@ -284,7 +286,7 @@ type resourceProfilingGroupData struct { AgentOrchestrationConfig fwtypes.ListNestedObjectValueOf[agentOrchestrationConfig] `tfsdk:"agent_orchestration_config"` ComputePlatform fwtypes.StringEnum[awstypes.ComputePlatform] `tfsdk:"compute_platform"` ID types.String `tfsdk:"id"` - ProfilingGroupName types.String `tfsdk:"profiling_group_name"` + Name types.String `tfsdk:"name"` ProfilingStatus fwtypes.ListNestedObjectValueOf[profilingStatus] `tfsdk:"profiling_status"` Tags types.Map `tfsdk:"tags"` TagsAll types.Map `tfsdk:"tags_all"` From 023a2606fc9503f139e6e498e75ff3fac584b710 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 30 Nov 2023 17:52:41 -0600 Subject: [PATCH 04/12] aws_codeguruprofiler_profiling_group: add timestamp to datasource --- .../codeguruprofiler/profiling_group.go | 21 ------------------- .../profiling_group_data_source.go | 11 ++++++++++ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/internal/service/codeguruprofiler/profiling_group.go b/internal/service/codeguruprofiler/profiling_group.go index 0a177caaf32b..2c5c56cf0136 100644 --- a/internal/service/codeguruprofiler/profiling_group.go +++ b/internal/service/codeguruprofiler/profiling_group.go @@ -14,7 +14,6 @@ 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/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" @@ -72,14 +71,6 @@ func (r *resourceProfilingGroup) Schema(ctx context.Context, req resource.Schema stringplanmodifier.RequiresReplace(), }, }, - "profiling_status": schema.ListAttribute{ - CustomType: fwtypes.NewListNestedObjectTypeOf[profilingStatus](ctx), - Computed: true, - ElementType: fwtypes.NewObjectTypeOf[profilingStatus](ctx), - PlanModifiers: []planmodifier.List{ - listplanmodifier.UseStateForUnknown(), - }, - }, names.AttrTags: tftags.TagsAttribute(), names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), }, @@ -287,7 +278,6 @@ type resourceProfilingGroupData struct { ComputePlatform fwtypes.StringEnum[awstypes.ComputePlatform] `tfsdk:"compute_platform"` ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` - ProfilingStatus fwtypes.ListNestedObjectValueOf[profilingStatus] `tfsdk:"profiling_status"` Tags types.Map `tfsdk:"tags"` TagsAll types.Map `tfsdk:"tags_all"` } @@ -295,14 +285,3 @@ type resourceProfilingGroupData struct { type agentOrchestrationConfig struct { ProfilingEnabled types.Bool `tfsdk:"profiling_enabled"` } - -type profilingStatus struct { - LatestAgentOrchestratedAt types.String `tfsdk:"latest_agent_orchestrated_at"` - LatestAgentProfileReportedAt types.String `tfsdk:"latest_agent_profile_reported_at"` - LatestAggregatedProfile fwtypes.ListNestedObjectValueOf[aggregatedProfileTime] `tfsdk:"latest_aggregated_profile"` -} - -type aggregatedProfileTime struct { - Period types.String `tfsdk:"period"` - Start types.String `tfsdk:"start"` -} diff --git a/internal/service/codeguruprofiler/profiling_group_data_source.go b/internal/service/codeguruprofiler/profiling_group_data_source.go index 661aee6afd30..fa0693499e21 100644 --- a/internal/service/codeguruprofiler/profiling_group_data_source.go +++ b/internal/service/codeguruprofiler/profiling_group_data_source.go @@ -5,6 +5,7 @@ package codeguruprofiler import ( "context" + "time" awstypes "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/types" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -51,6 +52,9 @@ func (d *dataSourceProfilingGroup) Schema(ctx context.Context, req datasource.Sc CustomType: computePlatform, Computed: true, }, + "created_at": schema.StringAttribute{ + Computed: true, + }, "id": framework.IDAttribute(), "name": schema.StringAttribute{ Required: true, @@ -61,6 +65,9 @@ func (d *dataSourceProfilingGroup) Schema(ctx context.Context, req datasource.Sc ElementType: fwtypes.NewObjectTypeOf[dsProfilingStatus](ctx), }, names.AttrTags: tftags.TagsAttributeComputedOnly(), + "updated_at": schema.StringAttribute{ + Computed: true, + }, }, } } @@ -92,6 +99,8 @@ func (d *dataSourceProfilingGroup) Read(ctx context.Context, req datasource.Read return } + data.CreatedAt = flex.StringValueToFramework(ctx, out.CreatedAt.Format(time.RFC3339)) + data.UpdatedAt = flex.StringValueToFramework(ctx, out.UpdatedAt.Format(time.RFC3339)) data.ID = flex.StringToFramework(ctx, out.Name) data.Tags = flex.FlattenFrameworkStringValueMap(ctx, out.Tags) @@ -102,10 +111,12 @@ type dataSourceProfilingGroupData struct { ARN types.String `tfsdk:"arn"` AgentOrchestrationConfig fwtypes.ListNestedObjectValueOf[dsAgentOrchestrationConfig] `tfsdk:"agent_orchestration_config"` ComputePlatform fwtypes.StringEnum[awstypes.ComputePlatform] `tfsdk:"compute_platform"` + CreatedAt types.String `tfsdk:"created_at"` ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` ProfilingStatus fwtypes.ListNestedObjectValueOf[dsProfilingStatus] `tfsdk:"profiling_status"` Tags types.Map `tfsdk:"tags"` + UpdatedAt types.String `tfsdk:"updated_at"` } type dsAgentOrchestrationConfig struct { From 637d5a8365763ac5e8d87b5b0751520f35d13900 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 30 Nov 2023 19:29:55 -0600 Subject: [PATCH 05/12] aws_codeguruprofiler_profiling_group: set name for update --- internal/service/codeguruprofiler/profiling_group.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/service/codeguruprofiler/profiling_group.go b/internal/service/codeguruprofiler/profiling_group.go index 2c5c56cf0136..130998fa1b29 100644 --- a/internal/service/codeguruprofiler/profiling_group.go +++ b/internal/service/codeguruprofiler/profiling_group.go @@ -61,6 +61,7 @@ func (r *resourceProfilingGroup) Schema(ctx context.Context, req resource.Schema Optional: true, Computed: true, PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), stringplanmodifier.UseStateForUnknown(), }, }, @@ -166,7 +167,6 @@ func (r *resourceProfilingGroup) Read(ctx context.Context, req resource.ReadRequ return } - state.Name = flex.StringToFramework(ctx, out.Name) setTagsOut(ctx, out.Tags) resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) @@ -191,6 +191,7 @@ func (r *resourceProfilingGroup) Update(ctx context.Context, req resource.Update return } + in.ProfilingGroupName = flex.StringFromFramework(ctx, state.ID) out, err := conn.UpdateProfilingGroup(ctx, in) if err != nil { resp.Diagnostics.AddError( From 0f10878c8d453237cce86fb0e309d26b7ce1a088 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 1 Dec 2023 11:48:09 -0600 Subject: [PATCH 06/12] aws_codeguruprofiler_profiling_group: add resource tests --- .../service/codeguruprofiler/exports_test.go | 11 + .../codeguruprofiler/profiling_group_test.go | 507 +++++++++++------- names/names.go | 1 + 3 files changed, 315 insertions(+), 204 deletions(-) create mode 100644 internal/service/codeguruprofiler/exports_test.go diff --git a/internal/service/codeguruprofiler/exports_test.go b/internal/service/codeguruprofiler/exports_test.go new file mode 100644 index 000000000000..2155411f5a03 --- /dev/null +++ b/internal/service/codeguruprofiler/exports_test.go @@ -0,0 +1,11 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package codeguruprofiler + +// Exports for use in tests only. +var ( + ResourceProfilingGroup = newResourceProfilingGroup + + FindProfilingGroupByName = findProfilingGroupByName +) diff --git a/internal/service/codeguruprofiler/profiling_group_test.go b/internal/service/codeguruprofiler/profiling_group_test.go index d3408b3ae482..ec87190281f3 100644 --- a/internal/service/codeguruprofiler/profiling_group_test.go +++ b/internal/service/codeguruprofiler/profiling_group_test.go @@ -3,207 +3,306 @@ package codeguruprofiler_test -//import ( -// "context" -// "errors" -// "fmt" -// "testing" -// -// "github.com/YakDriver/regexache" -// -// "github.com/aws/aws-sdk-go-v2/aws" -// "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler" -// "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/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" -// "github.com/hashicorp/terraform-provider-aws/names" -// tfcodeguruprofiler "github.com/hashicorp/terraform-provider-aws/internal/service/codeguruprofiler" -//) -// -//func TestAccCodeGuruProfilerProfilingGroup_basic(t *testing.T) { -// ctx := acctest.Context(t) -// if testing.Short() { -// t.Skip("skipping long-running test in short mode") -// } -// -// var profilinggroup codeguruprofiler.DescribeProfilingGroupResponse -// rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) -// resourceName := "aws_codeguruprofiler_profiling_group.test" -// -// resource.ParallelTest(t, resource.TestCase{ -// PreCheck: func() { -// acctest.PreCheck(ctx, t) -// acctest.PreCheckPartitionHasService(t, names.CodeGuruProfilerEndpointID) -// testAccPreCheck(ctx, t) -// }, -// ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), -// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, -// CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), -// Steps: []resource.TestStep{ -// { -// Config: testAccProfilingGroupConfig_basic(rName), -// Check: resource.ComposeTestCheckFunc( -// testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), -// resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "false"), -// resource.TestCheckResourceAttrSet(resourceName, "maintenance_window_start_time.0.day_of_week"), -// resource.TestCheckTypeSetElemNestedAttrs(resourceName, "user.*", map[string]string{ -// "console_access": "false", -// "groups.#": "0", -// "username": "Test", -// "password": "TestTest1234", -// }), -// acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "codeguruprofiler", regexache.MustCompile(`profilinggroup:+.`)), -// ), -// }, -// { -// ResourceName: resourceName, -// ImportState: true, -// ImportStateVerify: true, -// ImportStateVerifyIgnore: []string{"apply_immediately", "user"}, -// }, -// }, -// }) -//} -// -//func TestAccCodeGuruProfilerProfilingGroup_disappears(t *testing.T) { -// ctx := acctest.Context(t) -// if testing.Short() { -// t.Skip("skipping long-running test in short mode") -// } -// -// var profilinggroup codeguruprofiler.DescribeProfilingGroupResponse -// rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) -// resourceName := "aws_codeguruprofiler_profiling_group.test" -// -// resource.ParallelTest(t, resource.TestCase{ -// PreCheck: func() { -// acctest.PreCheck(ctx, t) -// acctest.PreCheckPartitionHasService(t, names.CodeGuruProfilerEndpointID) -// testAccPreCheck(t) -// }, -// ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), -// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, -// CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), -// Steps: []resource.TestStep{ -// { -// Config: testAccProfilingGroupConfig_basic(rName, testAccProfilingGroupVersionNewer), -// Check: resource.ComposeTestCheckFunc( -// testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), -// acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfcodeguruprofiler.ResourceProfilingGroup, resourceName), -// ), -// ExpectNonEmptyPlan: true, -// }, -// }, -// }) -//} -// -//func testAccCheckProfilingGroupDestroy(ctx context.Context) resource.TestCheckFunc { -// return func(s *terraform.State) error { -// conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruProfilerClient(ctx) -// -// for _, rs := range s.RootModule().Resources { -// if rs.Type != "aws_codeguruprofiler_profiling_group" { -// continue -// } -// -// input := &codeguruprofiler.DescribeProfilingGroupInput{ -// ProfilingGroupId: aws.String(rs.Primary.ID), -// } -// _, err := conn.DescribeProfilingGroup(ctx, &codeguruprofiler.DescribeProfilingGroupInput{ -// ProfilingGroupId: aws.String(rs.Primary.ID), -// }) -// if errs.IsA[*types.ResourceNotFoundException](err){ -// return nil -// } -// if err != nil { -// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingDestroyed, tfcodeguruprofiler.ResNameProfilingGroup, rs.Primary.ID, err) -// } -// -// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingDestroyed, tfcodeguruprofiler.ResNameProfilingGroup, rs.Primary.ID, errors.New("not destroyed")) -// } -// -// return nil -// } -//} -// -//func testAccCheckProfilingGroupExists(ctx context.Context, name string, profilinggroup *codeguruprofiler.DescribeProfilingGroupResponse) resource.TestCheckFunc { -// return func(s *terraform.State) error { -// rs, ok := s.RootModule().Resources[name] -// if !ok { -// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingExistence, tfcodeguruprofiler.ResNameProfilingGroup, name, errors.New("not found")) -// } -// -// if rs.Primary.ID == "" { -// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingExistence, tfcodeguruprofiler.ResNameProfilingGroup, name, errors.New("not set")) -// } -// -// conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruProfilerClient(ctx) -// resp, err := conn.DescribeProfilingGroup(ctx, &codeguruprofiler.DescribeProfilingGroupInput{ -// ProfilingGroupId: aws.String(rs.Primary.ID), -// }) -// -// if err != nil { -// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingExistence, tfcodeguruprofiler.ResNameProfilingGroup, rs.Primary.ID, err) -// } -// -// *profilinggroup = *resp -// -// return nil -// } -//} -// -//func testAccPreCheck(ctx context.Context, t *testing.T) { -// conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruProfilerClient(ctx) -// -// input := &codeguruprofiler.ListProfilingGroupsInput{} -// _, err := conn.ListProfilingGroups(ctx, input) -// -// if acctest.PreCheckSkipError(err) { -// t.Skipf("skipping acceptance testing: %s", err) -// } -// if err != nil { -// t.Fatalf("unexpected PreCheck error: %s", err) -// } -//} -// -//func testAccCheckProfilingGroupNotRecreated(before, after *codeguruprofiler.DescribeProfilingGroupResponse) resource.TestCheckFunc { -// return func(s *terraform.State) error { -// if before, after := aws.ToString(before.ProfilingGroupId), aws.ToString(after.ProfilingGroupId); before != after { -// return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingNotRecreated, tfcodeguruprofiler.ResNameProfilingGroup, aws.ToString(before.ProfilingGroupId), errors.New("recreated")) -// } -// -// return nil -// } -//} -// -//func testAccProfilingGroupConfig_basic(rName, version string) string { -// return fmt.Sprintf(` -//resource "aws_security_group" "test" { -// name = %[1]q -//} -// -//resource "aws_codeguruprofiler_profiling_group" "test" { -// profiling_group_name = %[1]q -// engine_type = "ActiveCodeGuruProfiler" -// engine_version = %[2]q -// host_instance_type = "codeguruprofiler.t2.micro" -// security_groups = [aws_security_group.test.id] -// authentication_strategy = "simple" -// storage_type = "efs" -// -// logs { -// general = true -// } -// -// user { -// username = "Test" -// password = "TestTest1234" -// } -//} -//`, rName, version) -//} +import ( + "context" + "errors" + "fmt" + "testing" + + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + + "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler" + awstypes "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/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" + tfcodeguruprofiler "github.com/hashicorp/terraform-provider-aws/internal/service/codeguruprofiler" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccCodeGuruProfilerProfilingGroup_basic(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var profilinggroup awstypes.ProfilingGroupDescription + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_codeguruprofiler_profiling_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccProfilingGroupConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrSet(resourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "compute_platform", "Default"), + resource.TestCheckResourceAttr(resourceName, "agent_orchestration_config.0.profiling_enabled", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccCodeGuruProfilerProfilingGroup_disappears(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var profilinggroup awstypes.ProfilingGroupDescription + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_codeguruprofiler_profiling_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccProfilingGroupConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), + acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfcodeguruprofiler.ResourceProfilingGroup, resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccCodeGuruProfilerProfilingGroup_update(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var profilinggroup awstypes.ProfilingGroupDescription + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_codeguruprofiler_profiling_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccProfilingGroupConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrSet(resourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "compute_platform", "Default"), + resource.TestCheckResourceAttr(resourceName, "agent_orchestration_config.0.profiling_enabled", "true"), + ), + }, + { + Config: testAccProfilingGroupConfig_update(rName, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrSet(resourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "compute_platform", "Default"), + resource.TestCheckResourceAttr(resourceName, "agent_orchestration_config.0.profiling_enabled", "false"), + ), + }, + }, + }) +} + +func TestAccCodeGuruProfilerProfilingGroup_tags(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var profilinggroup awstypes.ProfilingGroupDescription + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_codeguruprofiler_profiling_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccProfilingGroupConfig_tags1(rName, "key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + Config: testAccProfilingGroupConfig_tags2(rName, "key1", "value1", "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccProfilingGroupConfig_tags1(rName, "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckProfilingGroupExists(ctx, resourceName, &profilinggroup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + }, + }) +} + +func testAccCheckProfilingGroupDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruProfilerClient(ctx) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_codeguruprofiler_profiling_group" { + continue + } + + _, err := tfcodeguruprofiler.FindProfilingGroupByName(ctx, conn, rs.Primary.ID) + + if tfresource.NotFound(err) { + return nil + } + + if err != nil { + return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingDestroyed, tfcodeguruprofiler.ResNameProfilingGroup, rs.Primary.ID, err) + } + + return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingDestroyed, tfcodeguruprofiler.ResNameProfilingGroup, rs.Primary.ID, errors.New("not destroyed")) + } + + return nil + } +} + +func testAccCheckProfilingGroupExists(ctx context.Context, name string, profilinggroup *awstypes.ProfilingGroupDescription) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingExistence, tfcodeguruprofiler.ResNameProfilingGroup, name, errors.New("not found")) + } + + if rs.Primary.ID == "" { + return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingExistence, tfcodeguruprofiler.ResNameProfilingGroup, name, errors.New("not set")) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruProfilerClient(ctx) + resp, err := tfcodeguruprofiler.FindProfilingGroupByName(ctx, conn, rs.Primary.ID) + + if err != nil { + return create.Error(names.CodeGuruProfiler, create.ErrActionCheckingExistence, tfcodeguruprofiler.ResNameProfilingGroup, rs.Primary.ID, err) + } + + *profilinggroup = *resp + + return nil + } +} + +func testAccPreCheck(ctx context.Context, t *testing.T) { + conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruProfilerClient(ctx) + + input := &codeguruprofiler.ListProfilingGroupsInput{} + _, err := conn.ListProfilingGroups(ctx, input) + + if acctest.PreCheckSkipError(err) { + t.Skipf("skipping acceptance testing: %s", err) + } + if err != nil { + t.Fatalf("unexpected PreCheck error: %s", err) + } +} + +func testAccProfilingGroupConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "aws_codeguruprofiler_profiling_group" "test" { + name = %[1]q + compute_platform = "Default" + + agent_orchestration_config { + profiling_enabled = true + } +} +`, rName) +} + +func testAccProfilingGroupConfig_update(rName string, profilingEnabled bool) string { + return fmt.Sprintf(` +resource "aws_codeguruprofiler_profiling_group" "test" { + name = %[1]q + compute_platform = "Default" + + agent_orchestration_config { + profiling_enabled = %[2]t + } +} +`, rName, profilingEnabled) +} + +func testAccProfilingGroupConfig_tags1(rName, key1, value1 string) string { + return fmt.Sprintf(` +resource "aws_codeguruprofiler_profiling_group" "test" { + name = %[1]q + compute_platform = "Default" + + agent_orchestration_config { + profiling_enabled = true + } + + tags = { + %[2]q = %[3]q + } +} +`, rName, key1, value1) +} +func testAccProfilingGroupConfig_tags2(rName, key1, value1, key2, value2 string) string { + return fmt.Sprintf(` +resource "aws_codeguruprofiler_profiling_group" "test" { + name = %[1]q + compute_platform = "Default" + + agent_orchestration_config { + profiling_enabled = true + } + + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } +} +`, rName, key1, value1, key2, value2) +} diff --git a/names/names.go b/names/names.go index 8b73a9860687..fdfbbb9e8df9 100644 --- a/names/names.go +++ b/names/names.go @@ -40,6 +40,7 @@ const ( CleanRoomsEndpointID = "cleanrooms" CloudWatchLogsEndpointID = "logs" CodeDeployEndpointID = "codedeploy" + CodeGuruProfilerEndpointID = "codeguru-profiler" CodeStarConnectionsEndpointID = "codestar-connections" CodeStarNotificationsEndpointID = "codestar-notifications" ComprehendEndpointID = "comprehend" From a7d6b53b411cd9defbd19c0270a555daec9f8b38 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 1 Dec 2023 11:58:06 -0600 Subject: [PATCH 07/12] aws_codeguruprofiler_profiling_group: add datasource tests --- .../profiling_group_data_source_test.go | 150 +++++++----------- 1 file changed, 61 insertions(+), 89 deletions(-) diff --git a/internal/service/codeguruprofiler/profiling_group_data_source_test.go b/internal/service/codeguruprofiler/profiling_group_data_source_test.go index 5ea403636465..2bf74e54b28b 100644 --- a/internal/service/codeguruprofiler/profiling_group_data_source_test.go +++ b/internal/service/codeguruprofiler/profiling_group_data_source_test.go @@ -3,92 +3,64 @@ package codeguruprofiler_test -//import ( -// "fmt" -// "strings" -// "testing" -// -// "github.com/YakDriver/regexache" -// -// "github.com/aws/aws-sdk-go-v2/aws" -// "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler" -// "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/types" -// "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" -// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -// 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" -// tfcodeguruprofiler "github.com/hashicorp/terraform-provider-aws/internal/service/codeguruprofiler" -// "github.com/hashicorp/terraform-provider-aws/names" -//) -// -// -// -//func TestAccCodeGuruProfilerProfilingGroupDataSource_basic(t *testing.T) { -// ctx := acctest.Context(t) -// if testing.Short() { -// t.Skip("skipping long-running test in short mode") -// } -// -// var profilinggroup codeguruprofiler.DescribeProfilingGroupResponse -// rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) -// dataSourceName := "data.aws_codeguruprofiler_profiling_group.test" -// -// resource.ParallelTest(t, resource.TestCase{ -// PreCheck: func() { -// acctest.PreCheck(ctx, t) -// acctest.PreCheckPartitionHasService(t, codeguruprofiler.EndpointsID) -// testAccPreCheck(ctx, t) -// }, -// ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), -// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, -// CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), -// Steps: []resource.TestStep{ -// { -// Config: testAccProfilingGroupDataSourceConfig_basic(rName), -// Check: resource.ComposeTestCheckFunc( -// testAccCheckProfilingGroupExists(ctx, dataSourceName, &profilinggroup), -// resource.TestCheckResourceAttr(dataSourceName, "auto_minor_version_upgrade", "false"), -// resource.TestCheckResourceAttrSet(dataSourceName, "maintenance_window_start_time.0.day_of_week"), -// resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "user.*", map[string]string{ -// "console_access": "false", -// "groups.#": "0", -// "username": "Test", -// "password": "TestTest1234", -// }), -// acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "codeguruprofiler", regexache.MustCompile(`profilinggroup:+.`)), -// ), -// }, -// }, -// }) -//} -// -//func testAccProfilingGroupDataSourceConfig_basic(rName, version string) string { -// return fmt.Sprintf(` -//data "aws_security_group" "test" { -// name = %[1]q -//} -// -//data "aws_codeguruprofiler_profiling_group" "test" { -// profiling_group_name = %[1]q -// engine_type = "ActiveCodeGuruProfiler" -// engine_version = %[2]q -// host_instance_type = "codeguruprofiler.t2.micro" -// security_groups = [aws_security_group.test.id] -// authentication_strategy = "simple" -// storage_type = "efs" -// -// logs { -// general = true -// } -// -// user { -// username = "Test" -// password = "TestTest1234" -// } -//} -//`, rName, version) -//} +import ( + "fmt" + "testing" + + awstypes "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/types" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccCodeGuruProfilerProfilingGroupDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var profilinggroup awstypes.ProfilingGroupDescription + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dataSourceName := "data.aws_codeguruprofiler_profiling_group.test" + resourceName := "aws_codeguruprofiler_profiling_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CodeGuruProfilerEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckProfilingGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccProfilingGroupDataSourceConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckProfilingGroupExists(ctx, dataSourceName, &profilinggroup), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), + resource.TestCheckResourceAttrPair(dataSourceName, "compute_platform", resourceName, "compute_platform"), + resource.TestCheckResourceAttrPair(dataSourceName, "agent_orchestration_config.0.profiling_enabled", resourceName, "agent_orchestration_config.0.profiling_enabled"), + ), + }, + }, + }) +} + +func testAccProfilingGroupDataSourceConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "aws_codeguruprofiler_profiling_group" "test" { + name = %[1]q + compute_platform = "Default" + + agent_orchestration_config { + profiling_enabled = true + } +} + +data "aws_codeguruprofiler_profiling_group" "test" { + name = aws_codeguruprofiler_profiling_group.test.name +} +`, rName) +} From 87162b33b999261f5cd0c10740cecf02026d84ce Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 1 Dec 2023 12:09:29 -0600 Subject: [PATCH 08/12] aws_codeguruprofiler_profiling_group: add resource documentation --- .../profiling_group_data_source_test.go | 4 +-- .../codeguruprofiler/profiling_group_test.go | 8 +++--- ...guruprofiler_profiling_group.html.markdown | 28 ++++++++++--------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/internal/service/codeguruprofiler/profiling_group_data_source_test.go b/internal/service/codeguruprofiler/profiling_group_data_source_test.go index 2bf74e54b28b..c726630c5e41 100644 --- a/internal/service/codeguruprofiler/profiling_group_data_source_test.go +++ b/internal/service/codeguruprofiler/profiling_group_data_source_test.go @@ -51,7 +51,7 @@ func TestAccCodeGuruProfilerProfilingGroupDataSource_basic(t *testing.T) { func testAccProfilingGroupDataSourceConfig_basic(rName string) string { return fmt.Sprintf(` resource "aws_codeguruprofiler_profiling_group" "test" { - name = %[1]q + name = %[1]q compute_platform = "Default" agent_orchestration_config { @@ -60,7 +60,7 @@ resource "aws_codeguruprofiler_profiling_group" "test" { } data "aws_codeguruprofiler_profiling_group" "test" { - name = aws_codeguruprofiler_profiling_group.test.name + name = aws_codeguruprofiler_profiling_group.test.name } `, rName) } diff --git a/internal/service/codeguruprofiler/profiling_group_test.go b/internal/service/codeguruprofiler/profiling_group_test.go index ec87190281f3..62094562a259 100644 --- a/internal/service/codeguruprofiler/profiling_group_test.go +++ b/internal/service/codeguruprofiler/profiling_group_test.go @@ -250,7 +250,7 @@ func testAccPreCheck(ctx context.Context, t *testing.T) { func testAccProfilingGroupConfig_basic(rName string) string { return fmt.Sprintf(` resource "aws_codeguruprofiler_profiling_group" "test" { - name = %[1]q + name = %[1]q compute_platform = "Default" agent_orchestration_config { @@ -263,7 +263,7 @@ resource "aws_codeguruprofiler_profiling_group" "test" { func testAccProfilingGroupConfig_update(rName string, profilingEnabled bool) string { return fmt.Sprintf(` resource "aws_codeguruprofiler_profiling_group" "test" { - name = %[1]q + name = %[1]q compute_platform = "Default" agent_orchestration_config { @@ -276,7 +276,7 @@ resource "aws_codeguruprofiler_profiling_group" "test" { func testAccProfilingGroupConfig_tags1(rName, key1, value1 string) string { return fmt.Sprintf(` resource "aws_codeguruprofiler_profiling_group" "test" { - name = %[1]q + name = %[1]q compute_platform = "Default" agent_orchestration_config { @@ -292,7 +292,7 @@ resource "aws_codeguruprofiler_profiling_group" "test" { func testAccProfilingGroupConfig_tags2(rName, key1, value1, key2, value2 string) string { return fmt.Sprintf(` resource "aws_codeguruprofiler_profiling_group" "test" { - name = %[1]q + name = %[1]q compute_platform = "Default" agent_orchestration_config { diff --git a/website/docs/r/codeguruprofiler_profiling_group.html.markdown b/website/docs/r/codeguruprofiler_profiling_group.html.markdown index ba0424f8a3ae..b9d226c27188 100644 --- a/website/docs/r/codeguruprofiler_profiling_group.html.markdown +++ b/website/docs/r/codeguruprofiler_profiling_group.html.markdown @@ -15,6 +15,12 @@ Terraform resource for managing an AWS CodeGuru Profiler Profiling Group. ```terraform resource "aws_codeguruprofiler_profiling_group" "example" { + name = "example" + compute_platform = "Default" + + agent_orchestration_config { + profiling_enabled = true + } } ``` @@ -22,28 +28,24 @@ resource "aws_codeguruprofiler_profiling_group" "example" { The following arguments are required: -* `example_arg` - (Required) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `agent_orchestration_config` - (Required) Specifies whether profiling is enabled or disabled for the created profiling. See [Agent Orchestration Config](#agent-orchestration-config) for more details. +* `name` - (Required) The name of the profiling group to create. The following arguments are optional: -* `optional_arg` - (Optional) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `compute_platform` - (Optional) The compute platform of the profiling group. * `tags` - (Optional) A map of tags assigned to the WorkSpaces Connection Alias. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ## Attribute Reference This resource exports the following attributes in addition to the arguments above: -* `arn` - ARN of the Profiling Group. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. -* `example_attribute` - Concise description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `arn` - ARN of the Profiling Group. * `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). -## Timeouts - -[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): +### Agent Orchestration Config -* `create` - (Default `60m`) -* `update` - (Default `180m`) -* `delete` - (Default `90m`) +* `profiling_enabled` - (Required) Boolean that specifies whether the profiling agent collects profiling data or ## Import @@ -52,12 +54,12 @@ In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashico ```terraform import { to = aws_codeguruprofiler_profiling_group.example - id = "profiling_group-id-12345678" + id = "profiling_group-name-12345678" } ``` -Using `terraform import`, import CodeGuru Profiler Profiling Group using the `example_id_arg`. For example: +Using `terraform import`, import CodeGuru Profiler Profiling Group using the `name`. For example: ```console -% terraform import aws_codeguruprofiler_profiling_group.example profiling_group-id-12345678 +% terraform import aws_codeguruprofiler_profiling_group.example profiling_group-name-12345678 ``` From ab26bc5274dbc8ca98fc0e3d33f2924250c6ba74 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 1 Dec 2023 12:16:25 -0600 Subject: [PATCH 09/12] aws_codeguruprofiler_profiling_group: add datasource documentation --- .../d/codeguruprofiler_profiling_group.html.markdown | 12 +++++------- .../r/codeguruprofiler_profiling_group.html.markdown | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/website/docs/d/codeguruprofiler_profiling_group.html.markdown b/website/docs/d/codeguruprofiler_profiling_group.html.markdown index f2314043f4b6..b2d93807aaab 100644 --- a/website/docs/d/codeguruprofiler_profiling_group.html.markdown +++ b/website/docs/d/codeguruprofiler_profiling_group.html.markdown @@ -16,6 +16,7 @@ Terraform data source for managing an AWS CodeGuru Profiler Profiling Group. ```terraform data "aws_codeguruprofiler_profiling_group" "example" { + name = "example" } ``` @@ -23,16 +24,13 @@ data "aws_codeguruprofiler_profiling_group" "example" { The following arguments are required: -* `example_arg` - (Required) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. - -The following arguments are optional: - -* `optional_arg` - (Optional) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `name` - (Required) The name of the profiling group. ## Attribute Reference This data source exports the following attributes in addition to the arguments above: -* `arn` - ARN of the Profiling Group. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. -* `example_attribute` - Concise description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `agent_orchestration_config` - Profiling Group agent orchestration config +* `arn` - ARN of the Profiling Group. +* `compute_platform` - The compute platform of the profiling group. * `tags` - Mapping of Key-Value tags for the resource. \ No newline at end of file diff --git a/website/docs/r/codeguruprofiler_profiling_group.html.markdown b/website/docs/r/codeguruprofiler_profiling_group.html.markdown index b9d226c27188..2939574095a1 100644 --- a/website/docs/r/codeguruprofiler_profiling_group.html.markdown +++ b/website/docs/r/codeguruprofiler_profiling_group.html.markdown @@ -29,7 +29,7 @@ resource "aws_codeguruprofiler_profiling_group" "example" { The following arguments are required: * `agent_orchestration_config` - (Required) Specifies whether profiling is enabled or disabled for the created profiling. See [Agent Orchestration Config](#agent-orchestration-config) for more details. -* `name` - (Required) The name of the profiling group to create. +* `name` - (Required) The name of the profiling group. The following arguments are optional: From d943d4b918140001ac362599ead22989856b3366 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 1 Dec 2023 12:20:03 -0600 Subject: [PATCH 10/12] linter --- website/docs/d/codeguruprofiler_profiling_group.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/codeguruprofiler_profiling_group.html.markdown b/website/docs/d/codeguruprofiler_profiling_group.html.markdown index b2d93807aaab..1cb2e2325a54 100644 --- a/website/docs/d/codeguruprofiler_profiling_group.html.markdown +++ b/website/docs/d/codeguruprofiler_profiling_group.html.markdown @@ -33,4 +33,4 @@ This data source exports the following attributes in addition to the arguments a * `agent_orchestration_config` - Profiling Group agent orchestration config * `arn` - ARN of the Profiling Group. * `compute_platform` - The compute platform of the profiling group. -* `tags` - Mapping of Key-Value tags for the resource. \ No newline at end of file +* `tags` - Mapping of Key-Value tags for the resource. From 8351f23ce1ab5a7cd2b563287bea61105b06d9de Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 1 Dec 2023 12:24:31 -0600 Subject: [PATCH 11/12] fmt imports --- internal/service/codeguruprofiler/profiling_group_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/service/codeguruprofiler/profiling_group_test.go b/internal/service/codeguruprofiler/profiling_group_test.go index 62094562a259..3b34c5623965 100644 --- a/internal/service/codeguruprofiler/profiling_group_test.go +++ b/internal/service/codeguruprofiler/profiling_group_test.go @@ -9,8 +9,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" - "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler" awstypes "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -20,6 +18,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" tfcodeguruprofiler "github.com/hashicorp/terraform-provider-aws/internal/service/codeguruprofiler" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) From 02ca822e6ea868b8bb4284fba59a5ed0ddab9fca Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 1 Dec 2023 12:29:38 -0600 Subject: [PATCH 12/12] add CHANGELOG entry --- .changelog/34672.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/34672.txt diff --git a/.changelog/34672.txt b/.changelog/34672.txt new file mode 100644 index 000000000000..c7bfb292326a --- /dev/null +++ b/.changelog/34672.txt @@ -0,0 +1,7 @@ +```release-note:new-resource +aws_codeguruprofiler_profiling_group +``` + +```release-note:new-data-source +aws_codeguruprofiler_profiling_group +``` \ No newline at end of file