Skip to content

Commit

Permalink
Merge pull request #40919 from hashicorp/td-fw-resource-annotation-re…
Browse files Browse the repository at this point in the history
…quire-name

Tech debt: Require `name=` value for `@EphemeralResource` and `@FrameworkResource` annotations
  • Loading branch information
ewbankkit authored Jan 14, 2025
2 parents f3a5a72 + 6f51657 commit e57d523
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 10 deletions.
8 changes: 8 additions & 0 deletions internal/generate/servicepackage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
} else {
v.ephemeralResources = append(v.ephemeralResources, d)
}

if d.Name == "" {
v.g.Errorf("%s missing name: %s.%s", annotationName, v.packageName, v.functionName)
}
case "FrameworkDataSource":
if slices.ContainsFunc(v.frameworkDataSources, func(d ResourceDatum) bool { return d.FactoryName == v.functionName }) {
v.errs = append(v.errs, fmt.Errorf("duplicate Framework Data Source: %s", fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
Expand All @@ -261,6 +265,10 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
} else {
v.frameworkResources = append(v.frameworkResources, d)
}

if d.Name == "" {
v.g.Errorf("%s missing name: %s.%s", annotationName, v.packageName, v.functionName)
}
case "SDKDataSource":
if len(args.Positional) == 0 {
v.errs = append(v.errs, fmt.Errorf("no type name: %s", fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
Expand Down
2 changes: 1 addition & 1 deletion internal/service/apigateway/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource("aws_api_gateway_account")
// @FrameworkResource("aws_api_gateway_account", name="Account")
func newResourceAccount(context.Context) (resource.ResourceWithConfigure, error) {
r := &resourceAccount{}

Expand Down
1 change: 1 addition & 0 deletions internal/service/apigateway/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/auditmanager/account_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource
// @FrameworkResource("aws_auditmanager_account_registration", name="Account Registration")
func newResourceAccountRegistration(_ context.Context) (resource.ResourceWithConfigure, error) {
return &resourceAccountRegistration{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/auditmanager/assessment_delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource
// @FrameworkResource("aws_auditmanager_assessment_delegation", name="Assessment Delegation")
func newResourceAssessmentDelegation(_ context.Context) (resource.ResourceWithConfigure, error) {
return &resourceAssessmentDelegation{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/auditmanager/assessment_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

const reportCompletionTimeout = 5 * time.Minute

// @FrameworkResource
// @FrameworkResource("aws_auditmanager_assessment_report", name="Assessment Report")
func newResourceAssessmentReport(_ context.Context) (resource.ResourceWithConfigure, error) {
return &resourceAssessmentReport{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/auditmanager/framework_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource
// @FrameworkResource("aws_auditmanager_framework_share", name="Framework Share")
func newResourceFrameworkShare(_ context.Context) (resource.ResourceWithConfigure, error) {
return &resourceFrameworkShare{}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource
// @FrameworkResource("aws_auditmanager_organization_admin_account_registration", name="Organization Admin Account Registration")
func newResourceOrganizationAdminAccountRegistration(_ context.Context) (resource.ResourceWithConfigure, error) {
return &resourceOrganizationAdminAccountRegistration{}, nil
}
Expand Down
5 changes: 5 additions & 0 deletions internal/service/auditmanager/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/elasticache/reserved_cache_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource("aws_elasticache_reserved_cache_node")
// @FrameworkResource("aws_elasticache_reserved_cache_node", name="Reserved Cache Node")
// @Tags(identifierAttribute="arn")
// @Testing(tagsTests=false)
func newResourceReservedCacheNode(context.Context) (resource.ResourceWithConfigure, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/service/elasticache/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/medialive/multiplex_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource("aws_medialive_multiplex_program")
// @FrameworkResource("aws_medialive_multiplex_program", name="Multiplex Program")
func newResourceMultiplexProgram(_ context.Context) (resource.ResourceWithConfigure, error) {
return &multiplexProgram{}, nil
}
Expand Down
1 change: 1 addition & 0 deletions internal/service/medialive/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/rds/export_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource("aws_rds_export_task")
// @FrameworkResource("aws_rds_export_task", name="Export Task")
func newResourceExportTask(_ context.Context) (resource.ResourceWithConfigure, error) {
r := &resourceExportTask{}
r.SetDefaultCreateTimeout(60 * time.Minute)
Expand Down
1 change: 1 addition & 0 deletions internal/service/rds/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/simpledb/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource
// @FrameworkResource("aws_simpledb_domain", name="Domain")
func newDomainResource(context.Context) (resource.ResourceWithConfigure, error) {
r := &domainResource{}

Expand Down
1 change: 1 addition & 0 deletions internal/service/simpledb/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e57d523

Please sign in to comment.