Skip to content

Commit

Permalink
Merge pull request #24975 from hashicorp/t-caps2-func-var-const
Browse files Browse the repository at this point in the history
caps2: Fix func,var,const names
  • Loading branch information
YakDriver authored May 24, 2022
2 parents a05752d + 105d09d commit 3c91ed0
Show file tree
Hide file tree
Showing 75 changed files with 681 additions and 376 deletions.
39 changes: 12 additions & 27 deletions .semgrep-service-name0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,10 @@ rules:
message: Use correct caps in func name (i.e., HTTPS or https, not Https) (see list at https://github.com/hashicorp/terraform-provider-aws/tree/main/names/caps.md)
paths:
include:
- internal/service/ec2
- internal/service/timestreamwrite
- internal/service/transfer
- internal/service/waf
- internal/service/wafregional
- internal/service/wafv2
- internal/service/worklink
- internal/service/workspaces
- internal/service/xray
- internal
exclude:
- internal/service/batch
- internal/service/devicefarm
patterns:
- pattern: func $NAME( ... ) { ... }
- metavariable-pattern:
Expand All @@ -175,15 +170,10 @@ rules:
message: Use correct caps in const name (i.e., HTTPS or https, not Https) (see list at https://github.com/hashicorp/terraform-provider-aws/tree/main/names/caps.md)
paths:
include:
- internal/service/ec2
- internal/service/timestreamwrite
- internal/service/transfer
- internal/service/waf
- internal/service/wafregional
- internal/service/wafv2
- internal/service/worklink
- internal/service/workspaces
- internal/service/xray
- internal
exclude:
- internal/service/batch
- internal/service/devicefarm
patterns:
- pattern: const $NAME = ...
- metavariable-pattern:
Expand All @@ -197,15 +187,10 @@ rules:
message: Use correct caps in var name (i.e., HTTPS or https, not Https) (see list at https://github.com/hashicorp/terraform-provider-aws/tree/main/names/caps.md)
paths:
include:
- internal/service/ec2
- internal/service/timestreamwrite
- internal/service/transfer
- internal/service/waf
- internal/service/wafregional
- internal/service/wafv2
- internal/service/worklink
- internal/service/workspaces
- internal/service/xray
- internal
exclude:
- internal/service/batch
- internal/service/devicefarm
patterns:
- pattern: var $NAME = ...
- metavariable-pattern:
Expand Down
43 changes: 43 additions & 0 deletions .semgrep-service-name2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,49 @@ rules:
patterns:
- pattern-regex: "(?i)MQ"
severity: WARNING
- id: msk-in-func-name
languages:
- go
message: Do not use "msk" in func name inside kafka package
paths:
include:
- internal/service/kafka
patterns:
- pattern: func $NAME( ... ) { ... }
- metavariable-pattern:
metavariable: $NAME
patterns:
- pattern-regex: "(?i)msk"
- pattern-not-regex: ^TestAcc.*
severity: WARNING
- id: msk-in-const-name
languages:
- go
message: Do not use "msk" in const name inside kafka package
paths:
include:
- internal/service/kafka
patterns:
- pattern: const $NAME = ...
- metavariable-pattern:
metavariable: $NAME
patterns:
- pattern-regex: "(?i)msk"
severity: WARNING
- id: msk-in-var-name
languages:
- go
message: Do not use "msk" in var name inside kafka package
paths:
include:
- internal/service/kafka
patterns:
- pattern: var $NAME = ...
- metavariable-pattern:
metavariable: $NAME
patterns:
- pattern-regex: "(?i)msk"
severity: WARNING
- id: mwaa-in-func-name
languages:
- go
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing/contribution-checklists.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,11 @@ filters := namevaluesfilters.New(map[string]string{
"internet-gateway-id": d.Get("internet_gateway_id").(string),
})
// Add filters based on keyvalue tags (N.B. Not applicable to all AWS services that support filtering)
filters.Add(namevaluesfilters.Ec2Tags(keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()))
filters.Add(namevaluesfilters.EC2Tags(keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()))
// Add filters based on the custom filtering "filter" attribute.
filters.Add(d.Get("filter").(*schema.Set))
input.Filters = filters.Ec2Filters()
input.Filters = filters.EC2Filters()
```
### Resource Filtering Documentation Implementation
Expand Down
4 changes: 2 additions & 2 deletions internal/acctest/ec2_classic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

const (
// EC2-Classic region testing environment variable name
Ec2ClassicRegionEnvVar = "AWS_EC2_CLASSIC_REGION"
ec2ClassicRegionEnvVar = "AWS_EC2_CLASSIC_REGION"
)

// ProviderEC2Classic is the EC2-Classic provider instance
Expand Down Expand Up @@ -67,7 +67,7 @@ func ConfigEC2ClassicRegionProvider() string {

// EC2ClassicRegion returns the EC2-Classic region for testing
func EC2ClassicRegion() string {
v := os.Getenv(Ec2ClassicRegionEnvVar)
v := os.Getenv(ec2ClassicRegionEnvVar)

if v != "" {
return v
Expand Down
4 changes: 2 additions & 2 deletions internal/generate/namevaluesfilters/ec2_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

// Custom EC2 filter functions.

// Ec2Tags creates NameValuesFilters from a map of keyvalue tags.
func Ec2Tags(tags map[string]string) NameValuesFilters {
// EC2Tags creates NameValuesFilters from a map of keyvalue tags.
func EC2Tags(tags map[string]string) NameValuesFilters {
m := make(map[string]string, len(tags))

for k, v := range tags {
Expand Down
8 changes: 4 additions & 4 deletions internal/generate/namevaluesfilters/ec2_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfilters"
)

func TestNameValuesFiltersEc2Tags(t *testing.T) {
func TestNameValuesFiltersEC2Tags(t *testing.T) {
testCases := []struct {
name string
filters namevaluesfilters.NameValuesFilters
want map[string][]string
}{
{
name: "nil",
filters: namevaluesfilters.Ec2Tags(nil),
filters: namevaluesfilters.EC2Tags(nil),
want: map[string][]string{},
},
{
name: "nil",
filters: namevaluesfilters.Ec2Tags(map[string]string{}),
filters: namevaluesfilters.EC2Tags(map[string]string{}),
want: map[string][]string{},
},
{
name: "tags",
filters: namevaluesfilters.Ec2Tags(map[string]string{
filters: namevaluesfilters.EC2Tags(map[string]string{
"Name": acctest.ResourcePrefix,
"Purpose": "testing",
}),
Expand Down
8 changes: 4 additions & 4 deletions internal/generate/namevaluesfilters/service_filters_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/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ func Provider() *schema.Provider {
"aws_redshift_authentication_profile": redshift.ResourceAuthenticationProfile(),
"aws_redshift_cluster": redshift.ResourceCluster(),
"aws_redshift_event_subscription": redshift.ResourceEventSubscription(),
"aws_redshift_hsm_client_certificate": redshift.ResourceHsmClientCertificate(),
"aws_redshift_hsm_client_certificate": redshift.ResourceHSMClientCertificate(),
"aws_redshift_parameter_group": redshift.ResourceParameterGroup(),
"aws_redshift_scheduled_action": redshift.ResourceScheduledAction(),
"aws_redshift_security_group": redshift.ResourceSecurityGroup(),
Expand Down
4 changes: 2 additions & 2 deletions internal/service/acm/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (

// Maximum amount of time for ACM Certificate asynchronous DNS validation record assignment.
// This timeout is unrelated to any creation or validation of those assigned DNS records.
AcmCertificateDnsValidationAssignmentTimeout = 5 * time.Minute
certificateDNSValidationAssignmentTimeout = 5 * time.Minute

certificateValidationMethodNone = "NONE"
)
Expand Down Expand Up @@ -330,7 +330,7 @@ func resourceCertificateCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId(aws.StringValue(output.CertificateArn))
}

if _, err := waitCertificateDomainValidationsAvailable(conn, d.Id(), AcmCertificateDnsValidationAssignmentTimeout); err != nil {
if _, err := waitCertificateDomainValidationsAvailable(conn, d.Id(), certificateDNSValidationAssignmentTimeout); err != nil {
return fmt.Errorf("waiting for ACM Certificate (%s) to be issued: %w", d.Id(), err)
}

Expand Down
6 changes: 3 additions & 3 deletions internal/service/amp/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ func FindAlertManagerDefinitionByID(ctx context.Context, conn *prometheusservice
return output.AlertManagerDefinition, nil
}

func nameAndWorkspaceIdFromRuleGroupNamespaceArn(arn string) (string, string, error) {
func nameAndWorkspaceIDFromRuleGroupNamespaceARN(arn string) (string, string, error) {
parts := strings.Split(arn, "/")
if len(parts) != 3 {
return "", "", fmt.Errorf("error reading Prometheus Rule Group Namespace expected the arn to be like: arn:PARTITION:aps:REGION:ACCOUNT:rulegroupsnamespace/IDstring/namespace_name but got: %s", arn)
}
return parts[2], parts[1], nil
}

func FindRuleGroupNamespaceByArn(ctx context.Context, conn *prometheusservice.PrometheusService, arn string) (*prometheusservice.RuleGroupsNamespaceDescription, error) {
name, workspaceId, err := nameAndWorkspaceIdFromRuleGroupNamespaceArn(arn)
func FindRuleGroupNamespaceByARN(ctx context.Context, conn *prometheusservice.PrometheusService, arn string) (*prometheusservice.RuleGroupsNamespaceDescription, error) {
name, workspaceId, err := nameAndWorkspaceIDFromRuleGroupNamespaceARN(arn)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/amp/rule_group_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func resourceRuleGroupNamespaceUpdate(ctx context.Context, d *schema.ResourceDat
func resourceRuleGroupNamespaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AMPConn

rgn, err := FindRuleGroupNamespaceByArn(ctx, conn, d.Id())
rgn, err := FindRuleGroupNamespaceByARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Prometheus Rule Group Namespace (%s) not found, removing from state", d.Id())
Expand All @@ -110,7 +110,7 @@ func resourceRuleGroupNamespaceRead(ctx context.Context, d *schema.ResourceData,

d.Set("data", string(rgn.Data))
d.Set("name", rgn.Name)
_, workspaceID, err := nameAndWorkspaceIdFromRuleGroupNamespaceArn(d.Id())
_, workspaceID, err := nameAndWorkspaceIDFromRuleGroupNamespaceARN(d.Id())
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/amp/rule_group_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func testAccCheckRuleGroupNamespaceExists(n string) resource.TestCheckFunc {

conn := acctest.Provider.Meta().(*conns.AWSClient).AMPConn

_, err := tfamp.FindRuleGroupNamespaceByArn(context.TODO(), conn, rs.Primary.ID)
_, err := tfamp.FindRuleGroupNamespaceByARN(context.TODO(), conn, rs.Primary.ID)

if err != nil {
return err
Expand All @@ -104,7 +104,7 @@ func testAccCheckAMPRuleGroupNamespaceDestroy(s *terraform.State) error {
continue
}

_, err := tfamp.FindRuleGroupNamespaceByArn(context.TODO(), conn, rs.Primary.ID)
_, err := tfamp.FindRuleGroupNamespaceByARN(context.TODO(), conn, rs.Primary.ID)

if tfresource.NotFound(err) {
continue
Expand Down
2 changes: 1 addition & 1 deletion internal/service/amp/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func statusAlertManagerDefinition(ctx context.Context, conn *prometheusservice.P

func statusRuleGroupNamespace(ctx context.Context, conn *prometheusservice.PrometheusService, arn string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindRuleGroupNamespaceByArn(ctx, conn, arn)
output, err := FindRuleGroupNamespaceByARN(ctx, conn, arn)

if tfresource.NotFound(err) {
return nil, "", nil
Expand Down
4 changes: 2 additions & 2 deletions internal/service/appflow/connector_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ func resourceConnectorProfileCreate(ctx context.Context, d *schema.ResourceData,
func resourceConnectorProfileRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppFlowConn

connectorProfile, err := FindConnectorProfileByArn(context.Background(), conn, d.Id())
connectorProfile, err := FindConnectorProfileByARN(context.Background(), conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] AppFlow Connector Profile (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -1484,7 +1484,7 @@ func resourceConnectorProfileUpdate(ctx context.Context, d *schema.ResourceData,
func resourceConnectorProfileDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppFlowConn

out, _ := FindConnectorProfileByArn(ctx, conn, d.Id())
out, _ := FindConnectorProfileByARN(ctx, conn, d.Id())

log.Printf("[INFO] Deleting AppFlow Flow %s", d.Id())

Expand Down
2 changes: 1 addition & 1 deletion internal/service/appflow/connector_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func testAccCheckConnectorProfileDestroy(s *terraform.State) error {
continue
}

_, err := tfappflow.FindConnectorProfileByArn(context.Background(), conn, rs.Primary.ID)
_, err := tfappflow.FindConnectorProfileByARN(context.Background(), conn, rs.Primary.ID)

if tfresource.NotFound(err) {
continue
Expand Down
4 changes: 2 additions & 2 deletions internal/service/appflow/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func FindFlowByArn(ctx context.Context, conn *appflow.Appflow, arn string) (*appflow.FlowDefinition, error) {
func FindFlowByARN(ctx context.Context, conn *appflow.Appflow, arn string) (*appflow.FlowDefinition, error) {
in := &appflow.ListFlowsInput{}
var result *appflow.FlowDefinition

Expand Down Expand Up @@ -53,7 +53,7 @@ func FindFlowByArn(ctx context.Context, conn *appflow.Appflow, arn string) (*app
return result, nil
}

func FindConnectorProfileByArn(ctx context.Context, conn *appflow.Appflow, arn string) (*appflow.ConnectorProfile, error) {
func FindConnectorProfileByARN(ctx context.Context, conn *appflow.Appflow, arn string) (*appflow.ConnectorProfile, error) {
params := &appflow.DescribeConnectorProfilesInput{}
var result *appflow.ConnectorProfile

Expand Down
4 changes: 2 additions & 2 deletions internal/service/appflow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ func resourceFlowCreate(ctx context.Context, d *schema.ResourceData, meta interf
func resourceFlowRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppFlowConn

out, err := FindFlowByArn(ctx, conn, d.Id())
out, err := FindFlowByARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] AppFlow Flow (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -1359,7 +1359,7 @@ func resourceFlowUpdate(ctx context.Context, d *schema.ResourceData, meta interf
func resourceFlowDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppFlowConn

out, _ := FindFlowByArn(ctx, conn, d.Id())
out, _ := FindFlowByARN(ctx, conn, d.Id())

log.Printf("[INFO] Deleting AppFlow Flow %s", d.Id())

Expand Down
4 changes: 2 additions & 2 deletions internal/service/appflow/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func testAccCheckFlowExists(resourceName string, flow *appflow.FlowDefinition) r
}

conn := acctest.Provider.Meta().(*conns.AWSClient).AppFlowConn
resp, err := tfappflow.FindFlowByArn(context.Background(), conn, rs.Primary.ID)
resp, err := tfappflow.FindFlowByARN(context.Background(), conn, rs.Primary.ID)

if err != nil {
return err
Expand All @@ -481,7 +481,7 @@ func testAccCheckFlowDestroy(s *terraform.State) error {
continue
}

_, err := tfappflow.FindFlowByArn(context.Background(), conn, rs.Primary.ID)
_, err := tfappflow.FindFlowByARN(context.Background(), conn, rs.Primary.ID)

if tfresource.NotFound(err) {
continue
Expand Down
2 changes: 1 addition & 1 deletion internal/service/appflow/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func FlowStatus(ctx context.Context, conn *appflow.Appflow, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
out, err := FindFlowByArn(ctx, conn, id)
out, err := FindFlowByARN(ctx, conn, id)

if tfresource.NotFound(err) {
return nil, "", nil
Expand Down
Loading

0 comments on commit 3c91ed0

Please sign in to comment.