From 9925c2b2168773c9dad937b1bfbae57f212abee0 Mon Sep 17 00:00:00 2001 From: Cem Mergenci Date: Mon, 29 Jan 2024 16:06:00 +0300 Subject: [PATCH 1/5] Add new service package Support and new resource SupportCase. Signed-off-by: Cem Mergenci --- go.mod | 7 +- go.sum | 14 +- internal/conns/awsclient_gen.go | 5 + internal/provider/service_packages_gen.go | 2 + internal/service/support/generate.go | 4 + .../service/support/service_package_gen.go | 55 ++++ internal/service/support/support_case.go | 261 ++++++++++++++++++ internal/service/support/support_case_test.go | 108 ++++++++ internal/sweep/service_packages_gen_test.go | 2 + names/consts_gen.go | 1 + names/names.go | 1 + names/names_data.csv | 2 +- website/allowed-subcategories.txt | 1 + .../custom-service-endpoints.html.markdown | 1 + 14 files changed, 454 insertions(+), 10 deletions(-) create mode 100644 internal/service/support/generate.go create mode 100644 internal/service/support/service_package_gen.go create mode 100644 internal/service/support/support_case.go create mode 100644 internal/service/support/support_case_test.go diff --git a/go.mod b/go.mod index 553689a5b38..075d8103a96 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c github.com/YakDriver/regexache v0.23.0 github.com/aws/aws-sdk-go v1.49.2 - github.com/aws/aws-sdk-go-v2 v1.24.0 + github.com/aws/aws-sdk-go-v2 v1.24.1 github.com/aws/aws-sdk-go-v2/config v1.26.1 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.15.7 @@ -92,6 +92,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/ssmincidents v1.27.5 github.com/aws/aws-sdk-go-v2/service/ssoadmin v1.23.5 github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 + github.com/aws/aws-sdk-go-v2/service/support v1.19.6 github.com/aws/aws-sdk-go-v2/service/swf v1.20.5 github.com/aws/aws-sdk-go-v2/service/timestreamwrite v1.23.6 github.com/aws/aws-sdk-go-v2/service/transcribe v1.34.5 @@ -148,8 +149,8 @@ require ( github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.16.12 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.9 // indirect github.com/aws/aws-sdk-go-v2/service/dynamodb v1.26.6 // indirect diff --git a/go.sum b/go.sum index 1e073c94d70..007e298bff3 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aws/aws-sdk-go v1.49.2 h1:+4BEcm1nPCoDbVd+gg8cdxpa1qJfrvnddy12vpEVWjw= github.com/aws/aws-sdk-go v1.49.2/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= -github.com/aws/aws-sdk-go-v2 v1.24.0 h1:890+mqQ+hTpNuw0gGP6/4akolQkSToDJgHfQE7AwGuk= -github.com/aws/aws-sdk-go-v2 v1.24.0/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4= +github.com/aws/aws-sdk-go-v2 v1.24.1 h1:xAojnj+ktS95YZlDf0zxWBkbFtymPeDP+rvUQIH3uAU= +github.com/aws/aws-sdk-go-v2 v1.24.1/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 h1:OCs21ST2LrepDfD3lwlQiOqIGp6JiEUqG84GzTDoyJs= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4/go.mod h1:usURWEKSNNAcAZuzRn/9ZYPT8aZQkR7xcCtunK/LkJo= github.com/aws/aws-sdk-go-v2/config v1.26.1 h1:z6DqMxclFGL3Zfo+4Q0rLnAZ6yVkzCRxhRMsiRQnD1o= @@ -36,10 +36,10 @@ github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 h1:w98BT5w+ao1/r5sUuiH6Jk github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10/go.mod h1:K2WGI7vUvkIv1HoNbfBA1bvIZ+9kL3YVmWxeKuLQsiw= github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.15.7 h1:FnLf60PtjXp8ZOzQfhJVsqF0OtYKQZWQfqOLshh8YXg= github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.15.7/go.mod h1:tDVvl8hyU6E9B8TrnNrZQEVkQlB8hjJwcgpPhgtlnNg= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 h1:v+HbZaCGmOwnTTVS86Fleq0vPzOd7tnJGbFhP0stNLs= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9/go.mod h1:Xjqy+Nyj7VDLBtCMkQYOw1QYfAEZCVLrfI0ezve8wd4= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 h1:N94sVhRACtXyVcjXxrwK1SKFIJrA9pOJ5yu2eSHnmls= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9/go.mod h1:hqamLz7g1/4EJP+GH5NBhcUMLjW+gKLQabgyz6/7WAU= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 h1:vF+Zgd9s+H4vOXd5BMaPWykta2a6Ih0AKLq/X6NYKn4= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10/go.mod h1:6BkRjejp/GR4411UGqkX8+wFMbFbqsUIimfK4XjOKR4= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 h1:nYPe006ktcqUji8S2mqXf9c/7NdiKriOwMvWQHgYztw= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10/go.mod h1:6UV4SZkVvmODfXKql4LCbaZUpF7HO2BX38FgBf9ZOLw= github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 h1:GrSw8s0Gs/5zZ0SX+gX4zQjRnRsMJDJ2sLur1gRBhEM= github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY= github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.9 h1:ugD6qzjYtB7zM5PN/ZIeaAIyefPaD82G8+SJopgvUpw= @@ -226,6 +226,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 h1:2k9KmFawS63euAkY4/ixVNsY github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5/go.mod h1:W+nd4wWDVkSUIox9bacmkBP5NMFQeTJ/xqNabpzSR38= github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 h1:5UYvv8JUvllZsRnfrcMQ+hJ9jNICmcgKPAO1CER25Wg= github.com/aws/aws-sdk-go-v2/service/sts v1.26.5/go.mod h1:XX5gh4CB7wAs4KhcF46G6C8a2i7eupU19dcAAE+EydU= +github.com/aws/aws-sdk-go-v2/service/support v1.19.6 h1:ZD8OSo915ouOvw9JIjT0pccHwubdLoHmQYjAXIxFA0I= +github.com/aws/aws-sdk-go-v2/service/support v1.19.6/go.mod h1:Mzty8X8zv84IXyvPJ0nI1gZhurnKgrD46J6MRgJsGGk= github.com/aws/aws-sdk-go-v2/service/swf v1.20.5 h1:9CU3kwRGpUReKubOsmxgG9LfaVpZ1PW/ON+5ZTKu5Gs= github.com/aws/aws-sdk-go-v2/service/swf v1.20.5/go.mod h1:i01QTdCHqrntRqtNeYmxUSDCcmXERzFCePIcHDjASHE= github.com/aws/aws-sdk-go-v2/service/timestreamwrite v1.23.6 h1:+7xZRneTlcraXL4+oN2kUlQX9ULh4aIxmcpUoR/faGA= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 265415a822b..8dfc6fc61c8 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -86,6 +86,7 @@ import ( ssmincidents_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ssmincidents" ssoadmin_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ssoadmin" sts_sdkv2 "github.com/aws/aws-sdk-go-v2/service/sts" + support_sdkv2 "github.com/aws/aws-sdk-go-v2/service/support" swf_sdkv2 "github.com/aws/aws-sdk-go-v2/service/swf" timestreamwrite_sdkv2 "github.com/aws/aws-sdk-go-v2/service/timestreamwrite" transcribe_sdkv2 "github.com/aws/aws-sdk-go-v2/service/transcribe" @@ -1080,6 +1081,10 @@ func (c *AWSClient) StorageGatewayConn(ctx context.Context) *storagegateway_sdkv return errs.Must(conn[*storagegateway_sdkv1.StorageGateway](ctx, c, names.StorageGateway, make(map[string]any))) } +func (c *AWSClient) SupportClient(ctx context.Context) *support_sdkv2.Client { + return errs.Must(client[*support_sdkv2.Client](ctx, c, names.Support, make(map[string]any))) +} + func (c *AWSClient) SyntheticsConn(ctx context.Context) *synthetics_sdkv1.Synthetics { return errs.Must(conn[*synthetics_sdkv1.Synthetics](ctx, c, names.Synthetics, make(map[string]any))) } diff --git a/internal/provider/service_packages_gen.go b/internal/provider/service_packages_gen.go index aae0a465cf6..0d626751b7c 100644 --- a/internal/provider/service_packages_gen.go +++ b/internal/provider/service_packages_gen.go @@ -204,6 +204,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/service/ssoadmin" "github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway" "github.com/hashicorp/terraform-provider-aws/internal/service/sts" + "github.com/hashicorp/terraform-provider-aws/internal/service/support" "github.com/hashicorp/terraform-provider-aws/internal/service/swf" "github.com/hashicorp/terraform-provider-aws/internal/service/synthetics" "github.com/hashicorp/terraform-provider-aws/internal/service/timestreamwrite" @@ -420,6 +421,7 @@ func servicePackages(ctx context.Context) []conns.ServicePackage { ssoadmin.ServicePackage(ctx), storagegateway.ServicePackage(ctx), sts.ServicePackage(ctx), + support.ServicePackage(ctx), swf.ServicePackage(ctx), synthetics.ServicePackage(ctx), timestreamwrite.ServicePackage(ctx), diff --git a/internal/service/support/generate.go b/internal/service/support/generate.go new file mode 100644 index 00000000000..c35010f3a4f --- /dev/null +++ b/internal/service/support/generate.go @@ -0,0 +1,4 @@ +//go:generate go run ../../generate/servicepackage/main.go +// ONLY generate directives and package declaration! Do not add anything else to this file. + +package support diff --git a/internal/service/support/service_package_gen.go b/internal/service/support/service_package_gen.go new file mode 100644 index 00000000000..f8add9b8ad5 --- /dev/null +++ b/internal/service/support/service_package_gen.go @@ -0,0 +1,55 @@ +// Code generated by internal/generate/servicepackages/main.go; DO NOT EDIT. + +package support + +import ( + "context" + + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + support_sdkv2 "github.com/aws/aws-sdk-go-v2/service/support" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/types" + "github.com/hashicorp/terraform-provider-aws/names" +) + +type servicePackage struct{} + +func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { + return []*types.ServicePackageFrameworkDataSource{} +} + +func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { + return []*types.ServicePackageFrameworkResource{ + { + Factory: newResourceSupportCase, + Name: "Support Case", + }, + } +} + +func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { + return []*types.ServicePackageSDKDataSource{} +} + +func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { + return []*types.ServicePackageSDKResource{} +} + +func (p *servicePackage) ServicePackageName() string { + return names.Support +} + +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*support_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) + + return support_sdkv2.NewFromConfig(cfg, func(o *support_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil +} + +func ServicePackage(ctx context.Context) conns.ServicePackage { + return &servicePackage{} +} diff --git a/internal/service/support/support_case.go b/internal/service/support/support_case.go new file mode 100644 index 00000000000..2386442e2fe --- /dev/null +++ b/internal/service/support/support_case.go @@ -0,0 +1,261 @@ +package support + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/support" + awstypes "github.com/aws/aws-sdk-go-v2/service/support/types" + "github.com/aws/aws-sdk-go/aws" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "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/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/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(name="Support Case") +func newResourceSupportCase(_ context.Context) (resource.ResourceWithConfigure, error) { + return &resourceSupportCase{}, nil +} + +const ( + ResourceNameSupportCase = "SupportCase" +) + +type resourceSupportCase struct { + framework.ResourceWithConfigure +} + +func (r *resourceSupportCase) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { + response.TypeName = "aws_support_support_case" +} + +// Schema returns the schema for this resource. +func (r *resourceSupportCase) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { + response.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "case_id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "category_code": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "cc_email_addresses": schema.ListAttribute{ + Optional: true, + ElementType: types.StringType, + Validators: []validator.List{ + listvalidator.SizeAtMost(10), + }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, + }, + "communication_body": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "display_id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "id": framework.IDAttribute(), + "issue_type": schema.StringAttribute{ + Optional: true, + }, + "language": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "service_code": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "severity_code": schema.StringAttribute{ + Required: true, + }, + "subject": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + }, + } +} + +func (r *resourceSupportCase) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + var plan resourceSupportCaseData + response.Diagnostics.Append(request.Plan.Get(ctx, &plan)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().SupportClient(ctx) + + input := support.CreateCaseInput{ + CommunicationBody: flex.StringFromFramework(ctx, plan.CommunicationBody), + Subject: flex.StringFromFramework(ctx, plan.Subject), + CategoryCode: flex.StringFromFramework(ctx, plan.CategoryCode), + CcEmailAddresses: flex.ExpandFrameworkStringValueList(ctx, plan.CCEmailAddresses), + IssueType: flex.StringFromFramework(ctx, plan.IssueType), + Language: flex.StringFromFramework(ctx, plan.Language), + ServiceCode: flex.StringFromFramework(ctx, plan.ServiceCode), + SeverityCode: flex.StringFromFramework(ctx, plan.SeverityCode), + } + output, err := conn.CreateCase(ctx, &input) + if err != nil { + response.Diagnostics.Append(create.DiagErrorFramework(names.Support, create.ErrActionCreating, ResourceNameSupportCase, plan.Subject.String(), err)) + return + } + + // Create API call returns only Case ID. Get other details as well. + caseDetails, err := findSupportCaseByID(ctx, conn, *output.CaseId) + if err != nil { + response.Diagnostics.Append(create.DiagErrorFramework(names.Support, create.ErrActionChecking, ResourceNameSupportCase, plan.Subject.String(), err)) + return + } + + state := plan + state.refreshFromOutput(ctx, caseDetails) + + response.Diagnostics.Append(response.State.Set(ctx, state)...) +} + +func (r *resourceSupportCase) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + var state resourceSupportCaseData + response.Diagnostics.Append(request.State.Get(ctx, &state)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().SupportClient(ctx) + + caseDetails, err := findSupportCaseByID(ctx, conn, state.CaseID.ValueString()) + if tfresource.NotFound(err) { + create.LogNotFoundRemoveState(names.Support, create.ErrActionReading, ResourceNameSupportCase, state.ID.ValueString()) + response.State.RemoveResource(ctx) + return + } + if err != nil { + response.Diagnostics.Append(create.DiagErrorFramework(names.Support, create.ErrActionReading, ResourceNameSupportCase, state.ID.String(), err)) + return + } + + state.refreshFromOutput(ctx, caseDetails) + response.Diagnostics.Append(response.State.Set(ctx, &state)...) +} + +// Update is a no-op, for now. For another no-op update example, see service/auditmanager/organization_admin_account_registration.go +func (r *resourceSupportCase) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { +} + +// Delete is a no-op, because AWS doesn't provide a deletion API. For another no-op update example, see service/auditmanager/organization_admin_account_registration.go +func (r *resourceSupportCase) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { +} + +func (r *resourceSupportCase) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { + // TODO(cem): Discuss whether we should use "case_id" or "id" as resource identifier in Crossplane. + resource.ImportStatePassthroughID(ctx, path.Root("id"), request, response) +} + +func findSupportCaseByID(ctx context.Context, conn *support.Client, caseID string) (*awstypes.CaseDetails, error) { + // See internal/service/opensearchserverless/find.go findLifecyclePolicyByNameAndType() + if caseID == "" { + return nil, &retry.NotFoundError{ + Message: "Cannot find SupportCase with an empty ID.", + } + } + + input := &support.DescribeCasesInput{ + CaseIdList: []string{*aws.String(caseID)}, + } + + output, err := conn.DescribeCases(ctx, input) + + if errs.IsA[*awstypes.CaseIdNotFound](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || output.Cases == nil || len(output.Cases) == 0 { + return nil, tfresource.NewEmptyResultError(input) + } + + if len(output.Cases) > 1 { + return nil, tfresource.NewTooManyResultsError(len(output.Cases), input) + } + + return &output.Cases[0], nil +} + +type resourceSupportCaseData struct { + CaseID types.String `tfsdk:"case_id"` + CategoryCode types.String `tfsdk:"category_code"` + CCEmailAddresses types.List `tfsdk:"cc_email_addresses"` + CommunicationBody types.String `tfsdk:"communication_body"` + DisplayID types.String `tfsdk:"display_id"` + ID types.String `tfsdk:"id"` + IssueType types.String `tfsdk:"issue_type"` + Language types.String `tfsdk:"language"` + ServiceCode types.String `tfsdk:"service_code"` + SeverityCode types.String `tfsdk:"severity_code"` + Subject types.String `tfsdk:"subject"` +} + +func (rd *resourceSupportCaseData) refreshFromOutput(ctx context.Context, out *awstypes.CaseDetails) { + if out == nil { + return + } + + rd.CaseID = flex.StringToFramework(ctx, out.CaseId) + rd.ID = rd.CaseID + + rd.CategoryCode = flex.StringToFramework(ctx, out.CategoryCode) + rd.CCEmailAddresses = flex.FlattenFrameworkStringValueList(ctx, out.CcEmailAddresses) + rd.DisplayID = flex.StringToFramework(ctx, out.DisplayId) + rd.Language = flex.StringToFramework(ctx, out.Language) + rd.ServiceCode = flex.StringToFramework(ctx, out.ServiceCode) + rd.SeverityCode = flex.StringToFramework(ctx, out.SeverityCode) + rd.Subject = flex.StringToFramework(ctx, out.Subject) +} diff --git a/internal/service/support/support_case_test.go b/internal/service/support/support_case_test.go new file mode 100644 index 00000000000..3b1a9914a02 --- /dev/null +++ b/internal/service/support/support_case_test.go @@ -0,0 +1,108 @@ +package support_test + +import ( + "context" + "errors" + "testing" + + "github.com/aws/aws-sdk-go-v2/service/support" + "github.com/aws/aws-sdk-go/aws/endpoints" + "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" + tfsupport "github.com/hashicorp/terraform-provider-aws/internal/service/support" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func init() { + acctest.RegisterServiceErrorCheckFunc(names.SupportEndpointID, testAccErrorCheckSkip) +} + +func testAccErrorCheckSkip(t *testing.T) resource.ErrorCheckFunc { + return acctest.ErrorCheckSkipMessagesContaining(t, + "To be determined...", + ) +} + +func TestAccSupportCase_serial(t *testing.T) { + testCases := map[string]func(t *testing.T){ + "basic": testAccSupportCase_basic, + // "disappears": testAccAccountRegistration_disappears, + // "kms key": testAccAccountRegistration_optionalKMSKey, + } + + acctest.RunSerialTests1Level(t, testCases, 0) +} + +func testAccSupportCase_basic(t *testing.T) { + ctx := acctest.Context(t) + resourceName := "aws_support_support_case.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckRegion(t, endpoints.UsEast1RegionID, endpoints.UsWest2RegionID, endpoints.EuWest1RegionID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.SupportEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + // CheckDestroy: testAccCheckAccountRegistrationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccConfigSupportCase_basic(), + Check: resource.ComposeTestCheckFunc( + testAccCheckSupportCaseIsActive(ctx, resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +// testAccCheckAccountRegisterationIsActive verifies AuditManager is active in the current account/region combination +func testAccCheckSupportCaseIsActive(ctx context.Context, name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameSupportCase, name, errors.New("not found")) + } + + if rs.Primary.ID == "" { + return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameSupportCase, name, errors.New("not set")) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).SupportClient(ctx) + out, err := conn.DescribeCases(ctx, &support.DescribeCasesInput{ + CaseIdList: []string{rs.Primary.ID}, + }) + if err != nil { + return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameSupportCase, rs.Primary.ID, err) + } + + // TODO(cem): Consider performing extra checks here, like resource ID, or whatever checks there could be. + if out == nil || len(out.Cases) != 1 { + return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameSupportCase, rs.Primary.ID, errors.New("support case not active")) + } + + return nil + } +} + +func testAccConfigSupportCase_basic() string { + return ` +resource "aws_support_support_case" "test" { + subject = "TEST CASE-Please ignore" + communication_body = "This support case is created for AWS SDK development purposes." + issue_type = "technical" + language = "en" + service_code = "support-api" + category_code = "other" + severity_code = "low" +} +` +} diff --git a/internal/sweep/service_packages_gen_test.go b/internal/sweep/service_packages_gen_test.go index ee5ac8ad441..a2c76ca2ef1 100644 --- a/internal/sweep/service_packages_gen_test.go +++ b/internal/sweep/service_packages_gen_test.go @@ -204,6 +204,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/service/ssoadmin" "github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway" "github.com/hashicorp/terraform-provider-aws/internal/service/sts" + "github.com/hashicorp/terraform-provider-aws/internal/service/support" "github.com/hashicorp/terraform-provider-aws/internal/service/swf" "github.com/hashicorp/terraform-provider-aws/internal/service/synthetics" "github.com/hashicorp/terraform-provider-aws/internal/service/timestreamwrite" @@ -420,6 +421,7 @@ func servicePackages(ctx context.Context) []conns.ServicePackage { ssoadmin.ServicePackage(ctx), storagegateway.ServicePackage(ctx), sts.ServicePackage(ctx), + support.ServicePackage(ctx), swf.ServicePackage(ctx), synthetics.ServicePackage(ctx), timestreamwrite.ServicePackage(ctx), diff --git a/names/consts_gen.go b/names/consts_gen.go index 1a227be34cd..1ec3ae51728 100644 --- a/names/consts_gen.go +++ b/names/consts_gen.go @@ -204,6 +204,7 @@ const ( Signer = "signer" SimpleDB = "simpledb" StorageGateway = "storagegateway" + Support = "support" Synthetics = "synthetics" TimestreamWrite = "timestreamwrite" Transcribe = "transcribe" diff --git a/names/names.go b/names/names.go index 30dd6320c9d..31991ef5a2a 100644 --- a/names/names.go +++ b/names/names.go @@ -89,6 +89,7 @@ const ( SSMIncidentsEndpointID = "ssm-incidents" SSOAdminEndpointID = "sso" STSEndpointID = "sts" + SupportEndpointID = "support" SWFEndpointID = "swf" TimestreamWriteEndpointID = "ingest.timestream" TranscribeEndpointID = "transcribe" diff --git a/names/names_data.csv b/names/names_data.csv index 1db2a8f79ec..a321fe1f370 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -347,7 +347,7 @@ sso-oidc,ssooidc,ssooidc,ssooidc,,ssooidc,,,SSOOIDC,SSOOIDC,,1,,,aws_ssooidc_,,s storagegateway,storagegateway,storagegateway,storagegateway,,storagegateway,,,StorageGateway,StorageGateway,,1,,,aws_storagegateway_,,storagegateway_,Storage Gateway,AWS,,,,,,, sts,sts,sts,sts,,sts,,,STS,STS,x,1,2,aws_caller_identity,aws_sts_,,caller_identity,STS (Security Token),AWS,,,,,AWS_STS_ENDPOINT,TF_AWS_STS_ENDPOINT, ,,,,,,,,,,,,,,,,,Sumerian,Amazon,x,,,,,,No SDK support -support,support,support,support,,support,,,Support,Support,,1,,,aws_support_,,support_,Support,AWS,,x,,,,, +support,support,support,support,,support,,,Support,Support,,,2,,aws_support_,,support_,Support,AWS,,,,,,, swf,swf,swf,swf,,swf,,,SWF,SWF,,,2,,aws_swf_,,swf_,SWF (Simple Workflow),Amazon,,,,,,, ,,,,,,,,,,,,,,,,,Tag Editor,AWS,x,,,,,,Part of Resource Groups Tagging textract,textract,textract,textract,,textract,,,Textract,Textract,,1,,,aws_textract_,,textract_,Textract,Amazon,,x,,,,, diff --git a/website/allowed-subcategories.txt b/website/allowed-subcategories.txt index 76ecec7af1f..3f0f151cb51 100644 --- a/website/allowed-subcategories.txt +++ b/website/allowed-subcategories.txt @@ -203,6 +203,7 @@ Service Quotas Shield Signer Storage Gateway +Support Timestream Write Transcribe Transfer Family diff --git a/website/docs/guides/custom-service-endpoints.html.markdown b/website/docs/guides/custom-service-endpoints.html.markdown index 936bc3b264b..bcc36ec1a65 100644 --- a/website/docs/guides/custom-service-endpoints.html.markdown +++ b/website/docs/guides/custom-service-endpoints.html.markdown @@ -271,6 +271,7 @@ provider "aws" {
  • ssoadmin
  • storagegateway
  • sts
  • +
  • support
  • swf
  • synthetics
  • timestreamwrite
  • From 216c5c820a117905ce6ccae0ff5e36a24a2d156c Mon Sep 17 00:00:00 2001 From: Cem Mergenci Date: Wed, 31 Jan 2024 17:28:15 +0300 Subject: [PATCH 2/5] Remove documented-but-not-enforced size limit. AWS Support SDK documentation states that ten CC email addresses are allowed, but eleven email addresses are accepted in practice. https://docs.aws.amazon.com/awssupport/latest/APIReference/API_CreateCase.html Signed-off-by: Cem Mergenci --- internal/service/support/support_case.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/internal/service/support/support_case.go b/internal/service/support/support_case.go index 2386442e2fe..03cb2d3a890 100644 --- a/internal/service/support/support_case.go +++ b/internal/service/support/support_case.go @@ -6,7 +6,6 @@ import ( "github.com/aws/aws-sdk-go-v2/service/support" awstypes "github.com/aws/aws-sdk-go-v2/service/support/types" "github.com/aws/aws-sdk-go/aws" - "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -64,9 +63,6 @@ func (r *resourceSupportCase) Schema(ctx context.Context, request resource.Schem "cc_email_addresses": schema.ListAttribute{ Optional: true, ElementType: types.StringType, - Validators: []validator.List{ - listvalidator.SizeAtMost(10), - }, PlanModifiers: []planmodifier.List{ listplanmodifier.RequiresReplace(), }, From 73e2699794755d06e0871c238c7c9b4c54f06084 Mon Sep 17 00:00:00 2001 From: Cem Mergenci Date: Wed, 31 Jan 2024 17:38:49 +0300 Subject: [PATCH 3/5] Make code idiomatic and remove development comments. Signed-off-by: Cem Mergenci --- internal/service/support/support_case.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/service/support/support_case.go b/internal/service/support/support_case.go index 03cb2d3a890..449b99b673e 100644 --- a/internal/service/support/support_case.go +++ b/internal/service/support/support_case.go @@ -16,6 +16,7 @@ import ( "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" @@ -37,7 +38,7 @@ type resourceSupportCase struct { framework.ResourceWithConfigure } -func (r *resourceSupportCase) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { +func (r *resourceSupportCase) Metadata(_ context.Context, _ resource.MetadataRequest, response *resource.MetadataResponse) { response.TypeName = "aws_support_support_case" } @@ -176,24 +177,22 @@ func (r *resourceSupportCase) Read(ctx context.Context, request resource.ReadReq response.Diagnostics.Append(response.State.Set(ctx, &state)...) } -// Update is a no-op, for now. For another no-op update example, see service/auditmanager/organization_admin_account_registration.go -func (r *resourceSupportCase) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { +// Update is a no-op. +func (r *resourceSupportCase) Update(_ context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { } -// Delete is a no-op, because AWS doesn't provide a deletion API. For another no-op update example, see service/auditmanager/organization_admin_account_registration.go -func (r *resourceSupportCase) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { +// Delete is a no-op, because AWS doesn't provide a deletion API. +func (r *resourceSupportCase) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { } func (r *resourceSupportCase) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { - // TODO(cem): Discuss whether we should use "case_id" or "id" as resource identifier in Crossplane. resource.ImportStatePassthroughID(ctx, path.Root("id"), request, response) } func findSupportCaseByID(ctx context.Context, conn *support.Client, caseID string) (*awstypes.CaseDetails, error) { - // See internal/service/opensearchserverless/find.go findLifecyclePolicyByNameAndType() if caseID == "" { return nil, &retry.NotFoundError{ - Message: "Cannot find SupportCase with an empty ID.", + Message: "cannot find SupportCase with an empty ID.", } } @@ -214,7 +213,7 @@ func findSupportCaseByID(ctx context.Context, conn *support.Client, caseID strin return nil, err } - if output == nil || output.Cases == nil || len(output.Cases) == 0 { + if output == nil || len(output.Cases) == 0 { return nil, tfresource.NewEmptyResultError(input) } From 7aa25b4f9175f1f673e2311d5602f3bc9802673c Mon Sep 17 00:00:00 2001 From: Cem Mergenci Date: Wed, 31 Jan 2024 21:25:30 +0300 Subject: [PATCH 4/5] Rename SupportCase to Case and add license headers. According to resource naming rules in Contributor Guide, "Case" is a better name than "SuportCase". https://hashicorp.github.io/terraform-provider-aws/naming/#rule_2 Signed-off-by: Cem Mergenci --- .../support/{support_case.go => case.go} | 53 ++++++++++--------- .../{support_case_test.go => case_test.go} | 30 +++++------ internal/service/support/generate.go | 3 ++ .../service/support/service_package_gen.go | 4 +- 4 files changed, 48 insertions(+), 42 deletions(-) rename internal/service/support/{support_case.go => case.go} (77%) rename internal/service/support/{support_case_test.go => case_test.go} (72%) diff --git a/internal/service/support/support_case.go b/internal/service/support/case.go similarity index 77% rename from internal/service/support/support_case.go rename to internal/service/support/case.go index 449b99b673e..ae3e928b6fb 100644 --- a/internal/service/support/support_case.go +++ b/internal/service/support/case.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package support import ( @@ -25,25 +28,25 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// @FrameworkResource(name="Support Case") -func newResourceSupportCase(_ context.Context) (resource.ResourceWithConfigure, error) { - return &resourceSupportCase{}, nil +// @FrameworkResource(name="Case") +func newResourceCase(_ context.Context) (resource.ResourceWithConfigure, error) { + return &resourceCase{}, nil } const ( - ResourceNameSupportCase = "SupportCase" + ResourceNameCase = "Case" ) -type resourceSupportCase struct { +type resourceCase struct { framework.ResourceWithConfigure } -func (r *resourceSupportCase) Metadata(_ context.Context, _ resource.MetadataRequest, response *resource.MetadataResponse) { - response.TypeName = "aws_support_support_case" +func (r *resourceCase) Metadata(_ context.Context, _ resource.MetadataRequest, response *resource.MetadataResponse) { + response.TypeName = "aws_support_case" } // Schema returns the schema for this resource. -func (r *resourceSupportCase) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { +func (r *resourceCase) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "case_id": schema.StringAttribute{ @@ -115,8 +118,8 @@ func (r *resourceSupportCase) Schema(ctx context.Context, request resource.Schem } } -func (r *resourceSupportCase) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { - var plan resourceSupportCaseData +func (r *resourceCase) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + var plan resourceCaseData response.Diagnostics.Append(request.Plan.Get(ctx, &plan)...) if response.Diagnostics.HasError() { return @@ -136,14 +139,14 @@ func (r *resourceSupportCase) Create(ctx context.Context, request resource.Creat } output, err := conn.CreateCase(ctx, &input) if err != nil { - response.Diagnostics.Append(create.DiagErrorFramework(names.Support, create.ErrActionCreating, ResourceNameSupportCase, plan.Subject.String(), err)) + response.Diagnostics.Append(create.DiagErrorFramework(names.Support, create.ErrActionCreating, ResourceNameCase, plan.Subject.String(), err)) return } // Create API call returns only Case ID. Get other details as well. - caseDetails, err := findSupportCaseByID(ctx, conn, *output.CaseId) + caseDetails, err := findCaseByID(ctx, conn, *output.CaseId) if err != nil { - response.Diagnostics.Append(create.DiagErrorFramework(names.Support, create.ErrActionChecking, ResourceNameSupportCase, plan.Subject.String(), err)) + response.Diagnostics.Append(create.DiagErrorFramework(names.Support, create.ErrActionChecking, ResourceNameCase, plan.Subject.String(), err)) return } @@ -153,8 +156,8 @@ func (r *resourceSupportCase) Create(ctx context.Context, request resource.Creat response.Diagnostics.Append(response.State.Set(ctx, state)...) } -func (r *resourceSupportCase) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { - var state resourceSupportCaseData +func (r *resourceCase) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + var state resourceCaseData response.Diagnostics.Append(request.State.Get(ctx, &state)...) if response.Diagnostics.HasError() { return @@ -162,14 +165,14 @@ func (r *resourceSupportCase) Read(ctx context.Context, request resource.ReadReq conn := r.Meta().SupportClient(ctx) - caseDetails, err := findSupportCaseByID(ctx, conn, state.CaseID.ValueString()) + caseDetails, err := findCaseByID(ctx, conn, state.ID.ValueString()) if tfresource.NotFound(err) { - create.LogNotFoundRemoveState(names.Support, create.ErrActionReading, ResourceNameSupportCase, state.ID.ValueString()) + create.LogNotFoundRemoveState(names.Support, create.ErrActionReading, ResourceNameCase, state.ID.ValueString()) response.State.RemoveResource(ctx) return } if err != nil { - response.Diagnostics.Append(create.DiagErrorFramework(names.Support, create.ErrActionReading, ResourceNameSupportCase, state.ID.String(), err)) + response.Diagnostics.Append(create.DiagErrorFramework(names.Support, create.ErrActionReading, ResourceNameCase, state.ID.String(), err)) return } @@ -178,21 +181,21 @@ func (r *resourceSupportCase) Read(ctx context.Context, request resource.ReadReq } // Update is a no-op. -func (r *resourceSupportCase) Update(_ context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { +func (r *resourceCase) Update(_ context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { } // Delete is a no-op, because AWS doesn't provide a deletion API. -func (r *resourceSupportCase) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { +func (r *resourceCase) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { } -func (r *resourceSupportCase) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { +func (r *resourceCase) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { resource.ImportStatePassthroughID(ctx, path.Root("id"), request, response) } -func findSupportCaseByID(ctx context.Context, conn *support.Client, caseID string) (*awstypes.CaseDetails, error) { +func findCaseByID(ctx context.Context, conn *support.Client, caseID string) (*awstypes.CaseDetails, error) { if caseID == "" { return nil, &retry.NotFoundError{ - Message: "cannot find SupportCase with an empty ID.", + Message: "cannot find Case with an empty ID.", } } @@ -224,7 +227,7 @@ func findSupportCaseByID(ctx context.Context, conn *support.Client, caseID strin return &output.Cases[0], nil } -type resourceSupportCaseData struct { +type resourceCaseData struct { CaseID types.String `tfsdk:"case_id"` CategoryCode types.String `tfsdk:"category_code"` CCEmailAddresses types.List `tfsdk:"cc_email_addresses"` @@ -238,7 +241,7 @@ type resourceSupportCaseData struct { Subject types.String `tfsdk:"subject"` } -func (rd *resourceSupportCaseData) refreshFromOutput(ctx context.Context, out *awstypes.CaseDetails) { +func (rd *resourceCaseData) refreshFromOutput(ctx context.Context, out *awstypes.CaseDetails) { if out == nil { return } diff --git a/internal/service/support/support_case_test.go b/internal/service/support/case_test.go similarity index 72% rename from internal/service/support/support_case_test.go rename to internal/service/support/case_test.go index 3b1a9914a02..461546d0888 100644 --- a/internal/service/support/support_case_test.go +++ b/internal/service/support/case_test.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go/aws/endpoints" "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" @@ -26,9 +27,9 @@ func testAccErrorCheckSkip(t *testing.T) resource.ErrorCheckFunc { ) } -func TestAccSupportCase_serial(t *testing.T) { +func TestAccCase_serial(t *testing.T) { testCases := map[string]func(t *testing.T){ - "basic": testAccSupportCase_basic, + "basic": testAccCase_basic, // "disappears": testAccAccountRegistration_disappears, // "kms key": testAccAccountRegistration_optionalKMSKey, } @@ -36,9 +37,9 @@ func TestAccSupportCase_serial(t *testing.T) { acctest.RunSerialTests1Level(t, testCases, 0) } -func testAccSupportCase_basic(t *testing.T) { +func testAccCase_basic(t *testing.T) { ctx := acctest.Context(t) - resourceName := "aws_support_support_case.test" + resourceName := "aws_support_case.test" resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -50,9 +51,9 @@ func testAccSupportCase_basic(t *testing.T) { // CheckDestroy: testAccCheckAccountRegistrationDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccConfigSupportCase_basic(), + Config: testAccConfigCase_basic(), Check: resource.ComposeTestCheckFunc( - testAccCheckSupportCaseIsActive(ctx, resourceName), + testAccCheckCaseIsActive(ctx, resourceName), ), }, { @@ -64,16 +65,16 @@ func testAccSupportCase_basic(t *testing.T) { }) } -// testAccCheckAccountRegisterationIsActive verifies AuditManager is active in the current account/region combination -func testAccCheckSupportCaseIsActive(ctx context.Context, name string) resource.TestCheckFunc { +// testAccCheckCaseIsActive verifies Case is active in the current account/region combination +func testAccCheckCaseIsActive(ctx context.Context, name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { - return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameSupportCase, name, errors.New("not found")) + return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameCase, name, errors.New("not found")) } if rs.Primary.ID == "" { - return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameSupportCase, name, errors.New("not set")) + return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameCase, name, errors.New("not set")) } conn := acctest.Provider.Meta().(*conns.AWSClient).SupportClient(ctx) @@ -81,21 +82,20 @@ func testAccCheckSupportCaseIsActive(ctx context.Context, name string) resource. CaseIdList: []string{rs.Primary.ID}, }) if err != nil { - return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameSupportCase, rs.Primary.ID, err) + return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameCase, rs.Primary.ID, err) } - // TODO(cem): Consider performing extra checks here, like resource ID, or whatever checks there could be. if out == nil || len(out.Cases) != 1 { - return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameSupportCase, rs.Primary.ID, errors.New("support case not active")) + return create.Error(names.Support, create.ErrActionCheckingExistence, tfsupport.ResourceNameCase, rs.Primary.ID, errors.New("support case not active")) } return nil } } -func testAccConfigSupportCase_basic() string { +func testAccConfigCase_basic() string { return ` -resource "aws_support_support_case" "test" { +resource "aws_support_case" "test" { subject = "TEST CASE-Please ignore" communication_body = "This support case is created for AWS SDK development purposes." issue_type = "technical" diff --git a/internal/service/support/generate.go b/internal/service/support/generate.go index c35010f3a4f..928ffb559f8 100644 --- a/internal/service/support/generate.go +++ b/internal/service/support/generate.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/support/service_package_gen.go b/internal/service/support/service_package_gen.go index f8add9b8ad5..4dfff84209e 100644 --- a/internal/service/support/service_package_gen.go +++ b/internal/service/support/service_package_gen.go @@ -21,8 +21,8 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { return []*types.ServicePackageFrameworkResource{ { - Factory: newResourceSupportCase, - Name: "Support Case", + Factory: newResourceCase, + Name: "Case", }, } } From 8f37918284b9fff3a15299a9832e7c114345e8dd Mon Sep 17 00:00:00 2001 From: Cem Mergenci Date: Wed, 31 Jan 2024 21:28:00 +0300 Subject: [PATCH 5/5] Add license header. Signed-off-by: Cem Mergenci --- xpprovider/xpprovider.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xpprovider/xpprovider.go b/xpprovider/xpprovider.go index b4a29760bfc..5bdf19df8dd 100644 --- a/xpprovider/xpprovider.go +++ b/xpprovider/xpprovider.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + // Package xpprovider exports needed internal types and functions used by Crossplane for instantiating, interacting and // configuring the underlying Terraform AWS providers. package xpprovider