Skip to content

Commit 8b0b594

Browse files
authored
Merge pull request #45319 from hashicorp/skaff-retry
`skaff`: Modernizes resource generation
2 parents 8927020 + f625baa commit 8b0b594

File tree

6 files changed

+478
-1258
lines changed

6 files changed

+478
-1258
lines changed

skaff/cmd/resource.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var resourceCmd = &cobra.Command{
2121
Use: "resource",
2222
Short: "Create scaffolding for a resource",
2323
RunE: func(cmd *cobra.Command, args []string) error {
24-
return resource.Create(name, snakeName, !clearComments, force, !pluginSDKV2, includeTags)
24+
return resource.Create(name, snakeName, !clearComments, force, includeTags)
2525
},
2626
}
2727

@@ -31,6 +31,5 @@ func init() {
3131
resourceCmd.Flags().BoolVarP(&clearComments, "clear-comments", "c", false, "do not include instructional comments in source")
3232
resourceCmd.Flags().StringVarP(&name, "name", "n", "", "name of the entity")
3333
resourceCmd.Flags().BoolVarP(&force, "force", "f", false, "force creation, overwriting existing files")
34-
resourceCmd.Flags().BoolVarP(&pluginSDKV2, "plugin-sdkv2", "p", false, "generate for Terraform Plugin SDK V2")
3534
resourceCmd.Flags().BoolVarP(&includeTags, "include-tags", "t", false, "Indicate that this resource has tags and the code for tagging should be generated")
3635
}

skaff/datasource/datasourcetest.gtpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func TestAcc{{ .Service }}{{ .DataSource }}DataSource_basic(t *testing.T) {
173173
},
174174
ErrorCheck: acctest.ErrorCheck(t, names.{{ .Service }}ServiceID),
175175
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
176-
CheckDestroy: testAccCheck{{ .DataSource }}Destroy(ctx),
176+
CheckDestroy: testAccCheck{{ .DataSource }}Destroy(ctx, t),
177177
Steps: []resource.TestStep{
178178
{
179179
Config: testAcc{{ .DataSource }}DataSourceConfig_basic(rName),

skaff/resource/resource.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ import (
2222
//go:embed resource.gtpl
2323
var resourceTmpl string
2424

25-
//go:embed resourcefw.gtpl
26-
var resourceFrameworkTmpl string
27-
2825
//go:embed resourcetest.gtpl
2926
var resourceTestTmpl string
3027

@@ -33,6 +30,7 @@ var websiteTmpl string
3330

3431
type TemplateData struct {
3532
Resource string
33+
ResourceAWS string
3634
ResourceLower string
3735
ResourceSnake string
3836
HumanFriendlyService string
@@ -43,12 +41,11 @@ type TemplateData struct {
4341
Service string
4442
ServiceLower string
4543
AWSServiceName string
46-
PluginFramework bool
4744
HumanResourceName string
4845
ProviderResourceName string
4946
}
5047

51-
func Create(resName, snakeName string, comments, force, pluginFramework, tags bool) error {
48+
func Create(resName, snakeName string, comments, force, tags bool) error {
5249
wd, err := os.Getwd() // os.Getenv("GOPACKAGE") not available since this is not run with go generate
5350
if err != nil {
5451
return fmt.Errorf("error reading working directory: %s", err)
@@ -79,6 +76,7 @@ func Create(resName, snakeName string, comments, force, pluginFramework, tags bo
7976

8077
templateData := TemplateData{
8178
Resource: resName,
79+
ResourceAWS: capitalizeForAWS(resName),
8280
ResourceLower: strings.ToLower(resName),
8381
ResourceSnake: snakeName,
8482
HumanFriendlyService: service.HumanFriendly(),
@@ -89,17 +87,12 @@ func Create(resName, snakeName string, comments, force, pluginFramework, tags bo
8987
Service: service.ProviderNameUpper(),
9088
ServiceLower: strings.ToLower(service.ProviderNameUpper()),
9189
AWSServiceName: service.FullHumanFriendly(),
92-
PluginFramework: pluginFramework,
9390
HumanResourceName: convert.ToHumanResName(resName),
9491
ProviderResourceName: convert.ToProviderResourceName(servicePackage, snakeName),
9592
}
9693

97-
tmpl := resourceTmpl
98-
if pluginFramework {
99-
tmpl = resourceFrameworkTmpl
100-
}
10194
f := fmt.Sprintf("%s.go", snakeName)
102-
if err = writeTemplate("newres", f, tmpl, force, templateData); err != nil {
95+
if err = writeTemplate("newres", f, resourceTmpl, force, templateData); err != nil {
10396
return fmt.Errorf("writing resource template: %w", err)
10497
}
10598

@@ -155,3 +148,8 @@ func writeTemplate(templateName, filename, tmpl string, force bool, td TemplateD
155148

156149
return nil
157150
}
151+
152+
// AWS API structs use different capitalization than the provider standards
153+
func capitalizeForAWS(s string) string {
154+
return strings.ReplaceAll(s, "VPC", "Vpc")
155+
}

0 commit comments

Comments
 (0)