Skip to content

Commit

Permalink
Merge pull request #40628 from hashicorp/td-tfsdk2fw-ids
Browse files Browse the repository at this point in the history
`tfsdk2fw`: Updates `id` handling
  • Loading branch information
gdavison authored Jan 6, 2025
2 parents f68c5aa + b404c09 commit 1139f8a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
16 changes: 8 additions & 8 deletions tools/tfsdk2fw/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.28.7 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.48 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.22 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.44 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.45 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
Expand Down Expand Up @@ -115,9 +115,9 @@ require (
github.com/aws/aws-sdk-go-v2/service/drs v1.30.8 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.38.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ec2 v1.198.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ecr v1.38.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.29.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ecs v1.53.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ecr v1.38.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.29.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ecs v1.53.2 // indirect
github.com/aws/aws-sdk-go-v2/service/efs v1.34.2 // indirect
github.com/aws/aws-sdk-go-v2/service/eks v1.56.0 // indirect
github.com/aws/aws-sdk-go-v2/service/elasticache v1.44.2 // indirect
Expand All @@ -135,7 +135,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/firehose v1.35.3 // indirect
github.com/aws/aws-sdk-go-v2/service/fis v1.31.3 // indirect
github.com/aws/aws-sdk-go-v2/service/fms v1.38.6 // indirect
github.com/aws/aws-sdk-go-v2/service/fsx v1.51.1 // indirect
github.com/aws/aws-sdk-go-v2/service/fsx v1.51.2 // indirect
github.com/aws/aws-sdk-go-v2/service/gamelift v1.38.0 // indirect
github.com/aws/aws-sdk-go-v2/service/glacier v1.26.8 // indirect
github.com/aws/aws-sdk-go-v2/service/globalaccelerator v1.29.8 // indirect
Expand Down Expand Up @@ -227,13 +227,13 @@ require (
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.25.8 // indirect
github.com/aws/aws-sdk-go-v2/service/rolesanywhere v1.16.8 // indirect
github.com/aws/aws-sdk-go-v2/service/route53 v1.46.4 // indirect
github.com/aws/aws-sdk-go-v2/service/route53domains v1.28.1 // indirect
github.com/aws/aws-sdk-go-v2/service/route53domains v1.28.2 // indirect
github.com/aws/aws-sdk-go-v2/service/route53profiles v1.4.8 // indirect
github.com/aws/aws-sdk-go-v2/service/route53recoverycontrolconfig v1.25.8 // indirect
github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness v1.21.8 // indirect
github.com/aws/aws-sdk-go-v2/service/route53resolver v1.34.3 // indirect
github.com/aws/aws-sdk-go-v2/service/rum v1.21.8 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.72.0 // indirect
github.com/aws/aws-sdk-go-v2/service/s3control v1.52.1 // indirect
github.com/aws/aws-sdk-go-v2/service/s3outposts v1.28.8 // indirect
github.com/aws/aws-sdk-go-v2/service/s3tables v1.0.1 // indirect
Expand Down Expand Up @@ -366,7 +366,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/grpc v1.68.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/hashicorp/terraform-provider-aws => ../..
Expand Down
28 changes: 14 additions & 14 deletions tools/tfsdk2fw/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ github.com/aws/aws-sdk-go-v2/credentials v1.17.48 h1:IYdLD1qTJ0zanRavulofmqut4af
github.com/aws/aws-sdk-go-v2/credentials v1.17.48/go.mod h1:tOscxHN3CGmuX9idQ3+qbkzrjVIx32lqDSU1/0d/qXs=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.22 h1:kqOrpojG71DxJm/KDPO+Z/y1phm1JlC8/iT+5XRmAn8=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.22/go.mod h1:NtSFajXVVL8TA2QNngagVZmUtXciyrHOt7xgz4faS/M=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.44 h1:2zxMLXLedpB4K1ilbJFxtMKsVKaexOqDttOhc0QGm3Q=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.44/go.mod h1:VuLHdqwjSvgftNC7yqPWyGVhEwPmJpeRi07gOgOfHF8=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.45 h1:ZxB8WFVYwolhDZxuZXoesHkl+L9cXLWy0K/G0QkNATc=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.45/go.mod h1:1krrbyoFFDqaNldmltPTP+mK3sAXLHPoaFtISOw2Hkk=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 h1:I/5wmGMffY4happ8NOCuIUEWGUvvFp5NSeQcXl9RHcI=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26/go.mod h1:FR8f4turZtNy6baO0KJ5FJUmXH/cSkI9fOngs0yl6mA=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 h1:zXFLuEuMMUOvEARXFUVJdfqZ4bvvSgdGRq/ATcrQxzM=
Expand Down Expand Up @@ -213,12 +213,12 @@ github.com/aws/aws-sdk-go-v2/service/dynamodb v1.38.1 h1:AnSNs7Ogi0LXHPMDBx4RE7i
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.38.1/go.mod h1:J8xqRbx7HIc8ids2P8JbrKx9irONPEYq7Z1FpLDpi3I=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.198.1 h1:YbNopxjd9baM83YEEmkaYHi+NuJt0AszeaSLqo0CVr0=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.198.1/go.mod h1:mwr3iRm8u1+kkEx4ftDM2Q6Yr0XQFBKrP036ng+k5Lk=
github.com/aws/aws-sdk-go-v2/service/ecr v1.38.0 h1:+1IqznlfeMCgFWoWAuwRqykVc6gGoUUQFGXai+77KWs=
github.com/aws/aws-sdk-go-v2/service/ecr v1.38.0/go.mod h1:NqKnlZvLl4Tp2UH/GEc/nhbjmPQhwOXmLp2eldiszLM=
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.29.0 h1:4s8fI+O6gumMp1fU8Lvi0TM9al3eP1JCj6c0o9olqig=
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.29.0/go.mod h1:aHMIyHh+6N2w3CY24J9JoV5ADnGuMZ7dnOJTzO0Txik=
github.com/aws/aws-sdk-go-v2/service/ecs v1.53.1 h1:sAT2jzHkds1cv7VvNpzFfCw2w3zAkh306x3MTLPjuoA=
github.com/aws/aws-sdk-go-v2/service/ecs v1.53.1/go.mod h1:YpTRClSDOPvN2e3kiIrYOx1sI+YKTZVmlMiNO2AwYhE=
github.com/aws/aws-sdk-go-v2/service/ecr v1.38.1 h1:pCI3RIJnZEUs0evNm+pdDzvAp+YwpabUyQTPPvxO8oY=
github.com/aws/aws-sdk-go-v2/service/ecr v1.38.1/go.mod h1:NqKnlZvLl4Tp2UH/GEc/nhbjmPQhwOXmLp2eldiszLM=
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.29.1 h1:pD3CFGTKwsB8TFjTohMWz0Qb1PuYpI78vYU8s5yhLx8=
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.29.1/go.mod h1:aHMIyHh+6N2w3CY24J9JoV5ADnGuMZ7dnOJTzO0Txik=
github.com/aws/aws-sdk-go-v2/service/ecs v1.53.2 h1:o/FdG76sTAoC8h20j6bSBE6MPJYOZhNIh0nJ8Q8druY=
github.com/aws/aws-sdk-go-v2/service/ecs v1.53.2/go.mod h1:YpTRClSDOPvN2e3kiIrYOx1sI+YKTZVmlMiNO2AwYhE=
github.com/aws/aws-sdk-go-v2/service/efs v1.34.2 h1:gV7yKX8euN6W9vXiPutShochfx5ren706E9D0qsoOjo=
github.com/aws/aws-sdk-go-v2/service/efs v1.34.2/go.mod h1:SB5IpCGoPDDTpf7wMLVtq5MRsad+vqIMONmJf/l4nqY=
github.com/aws/aws-sdk-go-v2/service/eks v1.56.0 h1:x31cGGE/t/QkrHVh5m2uWvYwDiaDXpj88nh6OdnI5r0=
Expand Down Expand Up @@ -253,8 +253,8 @@ github.com/aws/aws-sdk-go-v2/service/fis v1.31.3 h1:Pyde+VIhO71j5j+BXiwA2civiljv
github.com/aws/aws-sdk-go-v2/service/fis v1.31.3/go.mod h1:lMzi+Vbnzlq6fPfIvHPWoX2LHKM2S2EOn5z6Vx71nmw=
github.com/aws/aws-sdk-go-v2/service/fms v1.38.6 h1:AC3x00ZKA10zqPJuq6djqZ4SQJOgPSNJWsMYlmoHP4E=
github.com/aws/aws-sdk-go-v2/service/fms v1.38.6/go.mod h1:B3Vak6cFQfuW0ngCa07XogB2G4UNbPsx2RX8i09HYRI=
github.com/aws/aws-sdk-go-v2/service/fsx v1.51.1 h1:+aV/de4zHh5njmTWH9+OtbJ78KHxcdg8YLYjtqQLCaU=
github.com/aws/aws-sdk-go-v2/service/fsx v1.51.1/go.mod h1:cNaIag1SJLzfaYSGY0TY6blDFVpQjRqHfb3NhANZmTo=
github.com/aws/aws-sdk-go-v2/service/fsx v1.51.2 h1:ebMa63iPLHJ0dQgNTu5hJcYtmvr97SgJBMgdJ4Czqzc=
github.com/aws/aws-sdk-go-v2/service/fsx v1.51.2/go.mod h1:cNaIag1SJLzfaYSGY0TY6blDFVpQjRqHfb3NhANZmTo=
github.com/aws/aws-sdk-go-v2/service/gamelift v1.38.0 h1:KNBSQcM3wuDev57F/ORYpX51mOvPjyFu3SSsS2CzHo4=
github.com/aws/aws-sdk-go-v2/service/gamelift v1.38.0/go.mod h1:vrO+dsUPRzqUFiNr5T/9fm2bCZDcQZ8q46anRzviwxk=
github.com/aws/aws-sdk-go-v2/service/glacier v1.26.8 h1:6J1jxl2VB+BNVlI8z/XoJVf5oCjh/Cjz3T6lqU3V8EE=
Expand Down Expand Up @@ -437,8 +437,8 @@ github.com/aws/aws-sdk-go-v2/service/rolesanywhere v1.16.8 h1:UZGvejgPVw0Qhwt3Ku
github.com/aws/aws-sdk-go-v2/service/rolesanywhere v1.16.8/go.mod h1:xgh2UyLblHo40RL4po9e7D1iHfAsA85SxtbfdlDN7pk=
github.com/aws/aws-sdk-go-v2/service/route53 v1.46.4 h1:0jMtawybbfpFEIMy4wvfyW2Z4YLr7mnuzT0fhR67Nrc=
github.com/aws/aws-sdk-go-v2/service/route53 v1.46.4/go.mod h1:xlMODgumb0Pp8bzfpojqelDrf8SL9rb5ovwmwKJl+oU=
github.com/aws/aws-sdk-go-v2/service/route53domains v1.28.1 h1:JQtBxTNftIOozmHvZaD2ZvtS4oJ9zP8W7T/Toy7fDXg=
github.com/aws/aws-sdk-go-v2/service/route53domains v1.28.1/go.mod h1:kbxY8XfDPZYpcBqQtezB8r1DqZWgCydOSmgoKcTjvf4=
github.com/aws/aws-sdk-go-v2/service/route53domains v1.28.2 h1:IH+UWySP8buYbojqBKwOGOZN6zpAc4sd8gTDLEJYl74=
github.com/aws/aws-sdk-go-v2/service/route53domains v1.28.2/go.mod h1:kbxY8XfDPZYpcBqQtezB8r1DqZWgCydOSmgoKcTjvf4=
github.com/aws/aws-sdk-go-v2/service/route53profiles v1.4.8 h1:U1hxHsKRnTh4tI8Ntv0MOsaOH+MdClktUjz0UDcvcPc=
github.com/aws/aws-sdk-go-v2/service/route53profiles v1.4.8/go.mod h1:AitHbOsoMtRWbTE62FvieGF8JMaKcWIMsWV+MgOYn+U=
github.com/aws/aws-sdk-go-v2/service/route53recoverycontrolconfig v1.25.8 h1:gMqOTyw8VBzA6O/4jdZ7VyZd9+U4DtO/YfOayBOpwsw=
Expand All @@ -449,8 +449,8 @@ github.com/aws/aws-sdk-go-v2/service/route53resolver v1.34.3 h1:80FDkostVF+fDsRL
github.com/aws/aws-sdk-go-v2/service/route53resolver v1.34.3/go.mod h1:vYD7xWxRn4FA2LL0zRgiP4GQZPev0VIuKWOYPdU7LEU=
github.com/aws/aws-sdk-go-v2/service/rum v1.21.8 h1:PsjsKI4htYgVNS7SkrvDamC1pudlKdebfKKfT+B+p0k=
github.com/aws/aws-sdk-go-v2/service/rum v1.21.8/go.mod h1:2k7Pf5TV51+bdYg994/m6Pg9pDEU3/75ljg0twzfeqc=
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1 h1:aOVVZJgWbaH+EJYPvEgkNhCEbXXvH7+oML36oaPK3zE=
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1/go.mod h1:r+xl5yzMk9083rMR+sJ5TYj9Tihvf/l1oxzZXDgGj2Q=
github.com/aws/aws-sdk-go-v2/service/s3 v1.72.0 h1:SAfh4pNx5LuTafKKWR02Y+hL3A+3TX8cTKG1OIAJaBk=
github.com/aws/aws-sdk-go-v2/service/s3 v1.72.0/go.mod h1:r+xl5yzMk9083rMR+sJ5TYj9Tihvf/l1oxzZXDgGj2Q=
github.com/aws/aws-sdk-go-v2/service/s3control v1.52.1 h1:xxGbXbGtO/VMz2JqB1UwEDlSchryUss0KmQJSZ0oTUE=
github.com/aws/aws-sdk-go-v2/service/s3control v1.52.1/go.mod h1:6BuUa52of67a+ri/poTH82XiL+rTGQWUPZCmf2cfVHI=
github.com/aws/aws-sdk-go-v2/service/s3outposts v1.28.8 h1:47G52E232ytagHeaPcTIxd8GaVstyT4fKS9CrVRWbXM=
Expand Down
28 changes: 15 additions & 13 deletions tools/tfsdk2fw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,27 @@ func (e *emitter) emitAttributesAndBlocks(path []string, schema map[string]*sche
emittedFieldName = true
}

if name == "id" && isTopLevelAttribute {
fprintf(e.SchemaWriter, `// If the AWS API structs have an "...Id" field, use framework.IDAttribute()`+"\n")
if e.IsDataSource {
fprintf(e.SchemaWriter, `// Otherwise, use framework.IDAttributeDeprecatedNoReplacement()`+"\n")
} else {
fprintf(e.SchemaWriter, `// Otherwise, if the "id" attribute is set to a single attribute of the resource, use framework.IDAttributeDeprecatedWithAlternate()`+"\n")
fprintf(e.SchemaWriter, `// If the "id" attribute is composed from multiple attributes of the resource, use framework.IDAttributeDeprecatedNoReplacement()`+"\n")
}
}
fprintf(e.SchemaWriter, "%q:", name)

if isTopLevelAttribute {
fprintf(e.StructWriter, "%s ", naming.ToCamelCase(name))
}

err := e.emitAttributeProperty(append(path, name), property)

if err != nil {
return err
if name == "id" && isTopLevelAttribute {
fprintf(e.SchemaWriter, "framework.IDAttribute()")
} else {
if err := e.emitAttributeProperty(append(path, name), property); err != nil {
return err
}
}

if isTopLevelAttribute {
Expand Down Expand Up @@ -393,10 +404,6 @@ func (e *emitter) emitAttributeProperty(path []string, property *schema.Schema)
fprintf(e.StructWriter, "fwtypes.ARN")
}
} else {
if isTopLevelAttribute && attributeName == "id" {
fprintf(e.SchemaWriter, "// TODO framework.IDAttribute()\n")
}

fprintf(e.SchemaWriter, "schema.StringAttribute{\n")

if isTopLevelAttribute {
Expand Down Expand Up @@ -552,11 +559,6 @@ func (e *emitter) emitAttributeProperty(path []string, property *schema.Schema)
fprintf(e.SchemaWriter, "},\n")
}

if attributeName == "id" && isTopLevelAttribute && !e.IsDataSource {
planModifiers = append(planModifiers, fmt.Sprintf("%s.UseStateForUnknown()", fwPlanModifierPackage))
e.FrameworkPlanModifierPackages = append(e.FrameworkPlanModifierPackages, fwPlanModifierPackage)
}

if property.ForceNew {
planModifiers = append(planModifiers, fmt.Sprintf("%s.RequiresReplace()", fwPlanModifierPackage))
e.FrameworkPlanModifierPackages = append(e.FrameworkPlanModifierPackages, fwPlanModifierPackage)
Expand Down

0 comments on commit 1139f8a

Please sign in to comment.