Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2dcbaf6
internal/seperator: Add id
brittandeyoung Nov 18, 2022
8479da0
lightsail: Amend domain_entry, move to separator.ResourceIdSeparator
brittandeyoung Nov 18, 2022
0fb7162
lightsail: Amend findDomainEntryByIdlightsail: Amend domain_entry, mo…
brittandeyoung Nov 18, 2022
82480ae
budgets: Amend budget, move to separator.ResourceIdSeparator
brittandeyoung Nov 18, 2022
accf7d8
budgets: Amend budget_action, move to separator.ResourceIdSeparator
brittandeyoung Nov 18, 2022
01d5888
flex: Move ExpandResourceId and FlattenResourceId, Add error handling
brittandeyoung Dec 2, 2022
0772df5
flex: golanglint-ci
brittandeyoung Dec 2, 2022
635736f
lightsail: Amend find, golanglint-ci
brittandeyoung Dec 2, 2022
fd6e63b
lightsail: Amend find, update expand resource to use partcount const
brittandeyoung Dec 2, 2022
44f9126
budgets: Amend budget_action, Replace magic number with constant
brittandeyoung Dec 2, 2022
c4d35eb
Merge branch 'main' into td-consistent-id-separator
brittandeyoung Apr 14, 2023
ede4ffa
lightsail: Amend Find, Move to ResourceID common function
brittandeyoung Apr 14, 2023
b32b5f8
lightsail: Amend domain_entry, Move to ResourceID common function
brittandeyoung Apr 14, 2023
4499df1
budget: Amend budget, Move to ResourceID common function
brittandeyoung Apr 14, 2023
0d5e7c0
budget: Amend budget_action, Move to ResourceID common function
brittandeyoung Apr 14, 2023
10ad34e
website: Amend budgets_budget, Move to ResourceID common function
brittandeyoung Apr 14, 2023
2c2278b
website: Amend budgets_budget_action, Move to ResourceID common function
brittandeyoung Apr 14, 2023
87ed5fc
website: Amend lightsail_domain_entry, Move to ResourceID common func…
brittandeyoung Apr 14, 2023
2a3ea18
budgets: Amend sweep, Move to ResourceID common function
brittandeyoung Apr 14, 2023
0410e9c
lightsail: Amend domain_entry, re add resource decorator
brittandeyoung Apr 14, 2023
7395a30
budgets: Amend sweep, Add flex import
brittandeyoung Apr 14, 2023
282e878
ec2: Amend ipam_preview_next_cidr, Move to ResourceID common function
brittandeyoung Apr 14, 2023
9f0f936
ec2: Amend ipam_preview_next_cidr_data_source, Move to ResourceID com…
brittandeyoung Apr 14, 2023
82bff2a
ec2: Amend outposts_local_gateway_route, Move to ResourceID common fu…
brittandeyoung Apr 14, 2023
e72113d
webside: Amend ec2_local_gateway_route, Move to ResourceID common fun…
brittandeyoung Apr 14, 2023
f147637
budgets: Amend budgets and budgets_action, use proper names for error
brittandeyoung Apr 14, 2023
fa17d8a
ec2: Use proper names for errors
brittandeyoung Apr 14, 2023
9ffa2df
website: Amend network_interface_sg_attachment, Move to ResourceID co…
brittandeyoung Apr 14, 2023
c2ac1eb
ec2: Amend vpc_route, Move to ResourceID common function
brittandeyoung Apr 14, 2023
a15f4c3
website: Amend route, Move to ResourceID common function
brittandeyoung Apr 14, 2023
e8a571b
appconfig: Amend configuration_profile, Move to ResourceID common fun…
brittandeyoung Apr 14, 2023
13178b0
website: Amend appconfig_configuration_profile, Move to ResourceID co…
brittandeyoung Apr 14, 2023
bcf133d
appconfig: Amend configuration_profile_data_source, Move to ResourceI…
brittandeyoung Apr 14, 2023
eb22f03
appconfig: Amend environment, Move to ResourceID common function
brittandeyoung Apr 14, 2023
3b686dd
appconfig: Amend environment_data_source, Move to ResourceID common f…
brittandeyoung Apr 14, 2023
a2e03a0
website: Amend appconfig_environment, Move to ResourceID common function
brittandeyoung Apr 14, 2023
3af4d9d
appsync: Amend api_key, Move to ResourceID common function
brittandeyoung Apr 14, 2023
8120ad1
website: appsync_api_key, Move to ResourceID common function
brittandeyoung Apr 14, 2023
5f73721
appsync: Amend type, Move to ResourceID common function
brittandeyoung Apr 14, 2023
1dd212d
website: Amend appsync_type, Move to ResourceID common function
brittandeyoung Apr 14, 2023
a7d2aae
cognitoidp: Amend identity_provider, Move to ResourceID common function
brittandeyoung Apr 14, 2023
1582332
website: Amend cognito_idenity_provider, Move to ResourceID common fu…
brittandeyoung Apr 14, 2023
7f68bab
flex: Amend flex, Add ResourceIdPartCount
brittandeyoung Apr 15, 2023
d810321
cognitoidp: Amend risk_configuration, Move to ResourceID common function
brittandeyoung Apr 15, 2023
7f63f5a
website: Amend cognito_risk_configuration, Move to ResourceID common …
brittandeyoung Apr 15, 2023
18c4931
configservice: Amend aggregate_authorization, Move to ResourceID comm…
brittandeyoung Apr 18, 2023
c4f5057
website: Amend config_aggregate_authorization, Move to ResourceID com…
brittandeyoung Apr 18, 2023
3c84ed8
dataexchange: Amend revision, Move to ResourceID common function
brittandeyoung Apr 18, 2023
42f5a0c
website: Amend dataexchange_revision, Move to ResourceID common function
brittandeyoung Apr 18, 2023
132ce46
deploy: Amend App, Move to ResourceID common function
brittandeyoung Apr 18, 2023
8c61bbe
deploy: Amend deployment_group, Move to ResourceID common function
brittandeyoung Apr 18, 2023
6045e7e
deploy: Amend deployments_group_test, Move to ResourceID common function
brittandeyoung Apr 18, 2023
a4e8d06
website: Amend codedeploy_deployment_group, Move to ResourceID common…
brittandeyoung Apr 18, 2023
548fb14
dynamodb: Amend table_replica, Move to ResourceID common function
brittandeyoung Apr 18, 2023
d49e223
website: Amend dynamodb_table_replica, Move to ResourceID common func…
brittandeyoung Apr 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/flex/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,10 @@ func FlattenResourceId(idParts []string, partCount int) (string, error) {
func StringToBoolValue(v *string) bool {
return aws.StringValue(v) == strconv.FormatBool(true)
}

// Takes a string of resource attributes separated by the ResourceIdSeparator constant
// returns the number of parts
func ResourceIdPartCount(id string) int {
idParts := strings.Split(id, ResourceIdSeparator)
return len(idParts)
}
33 changes: 25 additions & 8 deletions internal/service/appconfig/configuration_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"regexp"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
Expand All @@ -15,12 +14,19 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

const (
ConfigurationProfileIdPartsCount = 2
ResNameConfigurationProfile = "Configuration Profile"
)

// @SDKResource("aws_appconfig_configuration_profile", name="Connection Profile")
// @Tags(identifierAttribute="arn")
func ResourceConfigurationProfile() *schema.Resource {
Expand Down Expand Up @@ -146,7 +152,18 @@ func resourceConfigurationProfileCreate(ctx context.Context, d *schema.ResourceD
return sdkdiag.AppendErrorf(diags, "creating AppConfig Configuration Profile (%s) for Application (%s): empty response", name, appId)
}

d.SetId(fmt.Sprintf("%s:%s", aws.StringValue(profile.Id), aws.StringValue(profile.ApplicationId)))
idParts := []string{
aws.StringValue(profile.Id),
aws.StringValue(profile.ApplicationId),
}

id, err := flex.FlattenResourceId(idParts, ConfigurationProfileIdPartsCount)

if err != nil {
return create.DiagError(names.AppConfig, create.ErrActionFlatteningResourceId, ResNameConfigurationProfile, appId, err)
}

d.SetId(id)

return append(diags, resourceConfigurationProfileRead(ctx, d, meta)...)
}
Expand All @@ -158,7 +175,7 @@ func resourceConfigurationProfileRead(ctx context.Context, d *schema.ResourceDat
confProfID, appID, err := ConfigurationProfileParseID(d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading AppConfig Configuration Profile (%s): %s", d.Id(), err)
return create.DiagError(names.AppConfig, create.ErrActionExpandingResourceId, ResNameConfigurationProfile, d.Id(), err)
}

input := &appconfig.GetConfigurationProfileInput{
Expand Down Expand Up @@ -255,7 +272,7 @@ func resourceConfigurationProfileDelete(ctx context.Context, d *schema.ResourceD
confProfID, appID, err := ConfigurationProfileParseID(d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting AppConfig Configuration Profile (%s): %s", d.Id(), err)
return create.DiagError(names.AppConfig, create.ErrActionExpandingResourceId, ResNameConfigurationProfile, d.Id(), err)
}

input := &appconfig.DeleteConfigurationProfileInput{
Expand All @@ -277,13 +294,13 @@ func resourceConfigurationProfileDelete(ctx context.Context, d *schema.ResourceD
}

func ConfigurationProfileParseID(id string) (string, string, error) {
parts := strings.Split(id, ":")
idParts, err := flex.ExpandResourceId(id, ConfigurationProfileIdPartsCount)

if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return "", "", fmt.Errorf("unexpected format of ID (%q), expected ConfigurationProfileID:ApplicationID", id)
if err != nil {
return "", "", err
}

return parts[0], parts[1], nil
return idParts[0], idParts[1], nil
}

func expandValidator(tfMap map[string]interface{}) *appconfig.Validator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -86,7 +87,17 @@ func dataSourceConfigurationProfileRead(ctx context.Context, d *schema.ResourceD

appId := d.Get("application_id").(string)
profileId := d.Get("configuration_profile_id").(string)
ID := fmt.Sprintf("%s:%s", profileId, appId)

idParts := []string{
appId,
profileId,
}

ID, err := flex.FlattenResourceId(idParts, ConfigurationProfileIdPartsCount)

if err != nil {
return create.DiagError(names.AppConfig, create.ErrActionFlatteningResourceId, ResNameConfigurationProfile, appId, err)
}

out, err := findConfigurationProfileByApplicationAndProfile(ctx, conn, appId, profileId)
if err != nil {
Expand Down
35 changes: 26 additions & 9 deletions internal/service/appconfig/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"regexp"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
Expand All @@ -15,12 +14,19 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

const (
EnvironmentIdPartsCount = 2
ResNameEnvironment = "Environment"
)

// @SDKResource("aws_appconfig_environment", name="Environment")
// @Tags(identifierAttribute="arn")
func ResourceEnvironment() *schema.Resource {
Expand Down Expand Up @@ -120,8 +126,19 @@ func resourceEnvironmentCreate(ctx context.Context, d *schema.ResourceData, meta
return sdkdiag.AppendErrorf(diags, "creating AppConfig Environment for Application (%s): empty response", appId)
}

idParts := []string{
aws.StringValue(environment.Id),
aws.StringValue(environment.ApplicationId),
}

id, err := flex.FlattenResourceId(idParts, EnvironmentIdPartsCount)

if err != nil {
return create.DiagError(names.AppConfig, create.ErrActionFlatteningResourceId, ResNameEnvironment, appId, err)
}

d.SetId(id)
d.Set("environment_id", environment.Id)
d.SetId(fmt.Sprintf("%s:%s", aws.StringValue(environment.Id), aws.StringValue(environment.ApplicationId)))

return append(diags, resourceEnvironmentRead(ctx, d, meta)...)
}
Expand All @@ -133,7 +150,7 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta i
envID, appID, err := EnvironmentParseID(d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading AppConfig Environment (%s): %s", d.Id(), err)
return create.DiagError(names.AppConfig, create.ErrActionExpandingResourceId, ResNameEnvironment, d.Id(), err)
}

input := &appconfig.GetEnvironmentInput{
Expand Down Expand Up @@ -188,7 +205,7 @@ func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, meta
envID, appID, err := EnvironmentParseID(d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating AppConfig Environment (%s): %s", d.Id(), err)
return create.DiagError(names.AppConfig, create.ErrActionExpandingResourceId, ResNameEnvironment, d.Id(), err)
}

updateInput := &appconfig.UpdateEnvironmentInput{
Expand Down Expand Up @@ -225,7 +242,7 @@ func resourceEnvironmentDelete(ctx context.Context, d *schema.ResourceData, meta
envID, appID, err := EnvironmentParseID(d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting AppConfig Environment (%s): %s", d.Id(), err)
return create.DiagError(names.AppConfig, create.ErrActionExpandingResourceId, ResNameEnvironment, d.Id(), err)
}

input := &appconfig.DeleteEnvironmentInput{
Expand All @@ -247,13 +264,13 @@ func resourceEnvironmentDelete(ctx context.Context, d *schema.ResourceData, meta
}

func EnvironmentParseID(id string) (string, string, error) {
parts := strings.Split(id, ":")
idParts, err := flex.ExpandResourceId(id, EnvironmentIdPartsCount)

if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return "", "", fmt.Errorf("unexpected format of ID (%q), expected EnvironmentID:ApplicationID", id)
if err != nil {
return "", "", err
}

return parts[0], parts[1], nil
return idParts[0], idParts[1], nil
}

func expandEnvironmentMonitor(tfMap map[string]interface{}) *appconfig.Monitor {
Expand Down
13 changes: 12 additions & 1 deletion internal/service/appconfig/environment_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -78,7 +79,17 @@ func dataSourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta

appID := d.Get("application_id").(string)
envID := d.Get("environment_id").(string)
ID := fmt.Sprintf("%s:%s", envID, appID)

idParts := []string{
envID,
appID,
}

ID, err := flex.FlattenResourceId(idParts, EnvironmentIdPartsCount)

if err != nil {
return create.DiagError(names.AppConfig, create.ErrActionFlatteningResourceId, ResNameEnvironment, appID, err)
}

out, err := findEnvironmentByApplicationAndEnvironment(ctx, conn, appID, envID)
if err != nil {
Expand Down
40 changes: 30 additions & 10 deletions internal/service/appsync/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package appsync

import (
"context"
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -14,7 +12,15 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
"github.com/hashicorp/terraform-provider-aws/names"
)

const (
APIKeyIdPartsCount = 2
ResNameAPIKey = "APIKey"
)

// @SDKResource("aws_appsync_api_key")
Expand Down Expand Up @@ -78,7 +84,19 @@ func resourceAPIKeyCreate(ctx context.Context, d *schema.ResourceData, meta inte
return sdkdiag.AppendErrorf(diags, "creating Appsync API Key: %s", err)
}

d.SetId(fmt.Sprintf("%s:%s", apiID, aws.StringValue(resp.ApiKey.Id)))
idParts := []string{
apiID,
aws.StringValue(resp.ApiKey.Id),
}

id, err := flex.FlattenResourceId(idParts, APIKeyIdPartsCount)

if err != nil {
return create.DiagError(names.AppSync, create.ErrActionFlatteningResourceId, ResNameAPIKey, apiID, err)
}

d.SetId(id)

return append(diags, resourceAPIKeyRead(ctx, d, meta)...)
}

Expand All @@ -88,7 +106,7 @@ func resourceAPIKeyRead(ctx context.Context, d *schema.ResourceData, meta interf

apiID, keyID, err := DecodeAPIKeyID(d.Id())
if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Appsync API Key (%s): %s", d.Id(), err)
return create.DiagError(names.AppSync, create.ErrActionExpandingResourceId, ResNameAPIKey, d.Id(), err)
}

key, err := GetAPIKey(ctx, apiID, keyID, conn)
Expand All @@ -114,7 +132,7 @@ func resourceAPIKeyUpdate(ctx context.Context, d *schema.ResourceData, meta inte

apiID, keyID, err := DecodeAPIKeyID(d.Id())
if err != nil {
return sdkdiag.AppendErrorf(diags, "updating Appsync API Key (%s): %s", d.Id(), err)
return create.DiagError(names.AppSync, create.ErrActionExpandingResourceId, ResNameAPIKey, d.Id(), err)
}

params := &appsync.UpdateApiKeyInput{
Expand Down Expand Up @@ -143,7 +161,7 @@ func resourceAPIKeyDelete(ctx context.Context, d *schema.ResourceData, meta inte

apiID, keyID, err := DecodeAPIKeyID(d.Id())
if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting Appsync API Key (%s): %s", d.Id(), err)
return create.DiagError(names.AppSync, create.ErrActionExpandingResourceId, ResNameAPIKey, d.Id(), err)
}

input := &appsync.DeleteApiKeyInput{
Expand All @@ -162,11 +180,13 @@ func resourceAPIKeyDelete(ctx context.Context, d *schema.ResourceData, meta inte
}

func DecodeAPIKeyID(id string) (string, string, error) {
parts := strings.Split(id, ":")
if len(parts) != 2 {
return "", "", fmt.Errorf("Unexpected format of ID (%q), expected API-ID:API-KEY-ID", id)
idParts, err := flex.ExpandResourceId(id, APIKeyIdPartsCount)

if err != nil {
return "", "", err
}
return parts[0], parts[1], nil

return idParts[0], idParts[1], nil
}

func GetAPIKey(ctx context.Context, apiID, keyID string, conn *appsync.AppSync) (*appsync.ApiKey, error) {
Expand Down
Loading