Skip to content

Commit

Permalink
Merge pull request #39057 from hashicorp/td-skaff-names
Browse files Browse the repository at this point in the history
Use ServiceRecord instead of `names` for `skaff`
  • Loading branch information
gdavison authored Aug 29, 2024
2 parents 524df2d + 621023f commit 2309258
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 37 deletions.
9 changes: 9 additions & 0 deletions names/data/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package data

import (
_ "embed"
"fmt"
"log"
"strings"

Expand Down Expand Up @@ -139,6 +140,14 @@ func (sr ServiceRecord) HumanFriendly() string {
return sr[colHumanFriendly]
}

func (sr ServiceRecord) FullHumanFriendly() string {
if sr.Brand() == "" {
return sr.HumanFriendly()
}

return fmt.Sprintf("%s %s", sr.Brand(), sr.HumanFriendly())
}

func (sr ServiceRecord) Brand() string {
return sr[colBrand]
}
Expand Down
24 changes: 7 additions & 17 deletions skaff/datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
"text/template"

"github.com/hashicorp/terraform-provider-aws/names"
"github.com/hashicorp/terraform-provider-aws/names/data"
"github.com/hashicorp/terraform-provider-aws/skaff/convert"
)

Expand Down Expand Up @@ -69,32 +69,22 @@ func Create(dsName, snakeName string, comments, force, v2, pluginFramework, tags

snakeName = convert.ToSnakeCase(dsName, snakeName)

s, err := names.ProviderNameUpper(servicePackage)
service, err := data.LookupService(servicePackage)
if err != nil {
return fmt.Errorf("error getting service connection name: %w", err)
}

sn, err := names.FullHumanFriendly(servicePackage)
if err != nil {
return fmt.Errorf("error getting AWS service name: %w", err)
}

hf, err := names.HumanFriendly(servicePackage)
if err != nil {
return fmt.Errorf("error getting human-friendly name: %w", err)
return fmt.Errorf("error looking up service package data for %q: %w", servicePackage, err)
}

templateData := TemplateData{
DataSource: dsName,
DataSourceLower: strings.ToLower(dsName),
DataSourceSnake: snakeName,
HumanFriendlyService: hf,
HumanFriendlyService: service.HumanFriendly(),
IncludeComments: comments,
IncludeTags: tags,
ServicePackage: servicePackage,
Service: s,
ServiceLower: strings.ToLower(s),
AWSServiceName: sn,
Service: service.ProviderNameUpper(),
ServiceLower: strings.ToLower(service.ProviderNameUpper()),
AWSServiceName: service.FullHumanFriendly(),
AWSGoSDKV2: v2,
PluginFramework: pluginFramework,
HumanDataSourceName: convert.ToHumanResName(dsName),
Expand Down
3 changes: 0 additions & 3 deletions skaff/function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"strings"
"text/template"

"github.com/YakDriver/regexache"
"github.com/hashicorp/terraform-provider-aws/skaff/convert"
)

Expand All @@ -27,8 +26,6 @@ var functionTestTmpl string
//go:embed websitedoc.tmpl
var websiteTmpl string

var snakeCaseRegex = regexache.MustCompile(`[a-z0-9_]*`)

type TemplateData struct {
Function string
FunctionLower string
Expand Down
24 changes: 7 additions & 17 deletions skaff/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
"text/template"

"github.com/hashicorp/terraform-provider-aws/names"
"github.com/hashicorp/terraform-provider-aws/names/data"
"github.com/hashicorp/terraform-provider-aws/skaff/convert"
)

Expand Down Expand Up @@ -69,32 +69,22 @@ func Create(resName, snakeName string, comments, force, v2, pluginFramework, tag

snakeName = convert.ToSnakeCase(resName, snakeName)

s, err := names.ProviderNameUpper(servicePackage)
service, err := data.LookupService(servicePackage)
if err != nil {
return fmt.Errorf("error getting service connection name: %w", err)
}

sn, err := names.FullHumanFriendly(servicePackage)
if err != nil {
return fmt.Errorf("error getting AWS service name: %w", err)
}

hf, err := names.HumanFriendly(servicePackage)
if err != nil {
return fmt.Errorf("error getting human-friendly name: %w", err)
return fmt.Errorf("error looking up service package data for %q: %w", servicePackage, err)
}

templateData := TemplateData{
Resource: resName,
ResourceLower: strings.ToLower(resName),
ResourceSnake: snakeName,
HumanFriendlyService: hf,
HumanFriendlyService: service.HumanFriendly(),
IncludeComments: comments,
IncludeTags: tags,
ServicePackage: servicePackage,
Service: s,
ServiceLower: strings.ToLower(s),
AWSServiceName: sn,
Service: service.ProviderNameUpper(),
ServiceLower: strings.ToLower(service.ProviderNameUpper()),
AWSServiceName: service.FullHumanFriendly(),
AWSGoSDKV2: v2,
PluginFramework: pluginFramework,
HumanResourceName: convert.ToHumanResName(resName),
Expand Down

0 comments on commit 2309258

Please sign in to comment.