AWSAT004

package
v0.0.0-...-803190b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2022 License: MPL-2.0 Imports: 6 Imported by: 0

README

AWSAT004

The AWSAT004 analyzer reports TestCheckResourceAttr() calls with hardcoded TypeSet state hashes. Hardcoded state hashes are an unreliable way to specifically address state values since hashes may change over time, be inconsistent across partitions, and can be inadvertently changed by modifying configurations.

Flagged Code

func TestAccELBV2LoadBalancer_basic(t *testing.T) {
  ...
	resource.ParallelTest(t, resource.TestCase{
    ...
		Steps: []resource.TestStep{
			{
				Config: testELBV2LoadBalancerConfig_basic,
				Check: resource.ComposeTestCheckFunc(
          ...
					resource.TestCheckResourceAttr(resourceName, "listener.206423021.instance_port", "8000"),
					resource.TestCheckResourceAttr(resourceName, "listener.206423021.instance_protocol", "http"),
					resource.TestCheckResourceAttr(resourceName, "listener.206423021.lb_port", "80"),
					resource.TestCheckResourceAttr(resourceName, "listener.206423021.lb_protocol", "http"),
          ...
				),
			},
      ...
		},
	})
}

Passing Code

The flagged code above can be replaced with the following passing code:

func TestAccELBV2LoadBalancer_basic(t *testing.T) {
  ...
    resource.ParallelTest(t, resource.TestCase{
    ...
        Steps: []resource.TestStep{
            {
                Config: testAccELBV2LoadBalancerConfig_basic,
                Check: resource.ComposeTestCheckFunc(
                ...
                    resource.TestCheckTypeSetElemNestedAttrs(resourceName, "listener.*", map[string]string{
                        "instance_port":     "8000",
                        "instance_protocol": "http",
                        "lb_port":           "80",
                        "lb_protocol":       "http",
                ),
                ...
            },
        ...
        },
    })
}

Ignoring Reports

Singular reports can be ignored by adding the a //lintignore:AWSAT004 Go code comment at the end of the offending line or on the line immediately proceding, e.g.

resource.TestCheckResourceAttr(resourceName, "listener.206423021.instance_port", "8000"), //lintignore:AWSAT004

Documentation

Overview

Package AWSAT004 defines an Analyzer that checks for TestCheckResourceAttr() calls with hardcoded TypeSet state hashes

Index

Constants

View Source
const Doc = `` /* 388-byte string literal not displayed */

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: analyzerName,
	Doc:  Doc,
	Requires: []*analysis.Analyzer{
		commentignore.Analyzer,
		testcheckresourceattrcallexpr.Analyzer,
	},
	Run: run,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL