Skip to content

Commit f89892c

Browse files
committed
feat: also suggest the managed password solutions available
1 parent e1e55da commit f89892c

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

rules/aws_write_only_attributes.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,40 @@ type AwsWriteOnlyAttributesRule struct {
1818
}
1919

2020
type writeOnlyAttribute struct {
21-
original string
22-
alternative string
21+
original string
22+
writeOnlyAlternative string
23+
otherAlternative string
2324
}
2425

2526
// NewAwsWriteOnlyAttributesRule returns new rule with default attributes
2627
func NewAwsWriteOnlyAttributesRule() *AwsWriteOnlyAttributesRule {
2728
writeOnlyAttributes := map[string]writeOnlyAttribute{
2829
"aws_secretsmanager_secret_version": {
29-
original: "secret_string",
30-
alternative: "secret_string_wo",
30+
original: "secret_string",
31+
writeOnlyAlternative: "secret_string_wo",
3132
},
3233
"aws_rds_cluster": {
33-
original: "master_password",
34-
alternative: "master_password_wo",
34+
original: "master_password",
35+
writeOnlyAlternative: "master_password_wo",
36+
otherAlternative: "manage_master_user_password",
3537
},
3638
"aws_redshift_cluster": {
37-
original: "master_password",
38-
alternative: "master_password_wo",
39+
original: "master_password",
40+
writeOnlyAlternative: "master_password_wo",
41+
otherAlternative: "manage_master_password",
3942
},
4043
"aws_docdb_cluster": {
41-
original: "master_password",
42-
alternative: "master_password_wo",
44+
original: "master_password",
45+
writeOnlyAlternative: "master_password_wo",
4346
},
4447
"aws_redshiftserverless_namespace": {
45-
original: "admin_password",
46-
alternative: "admin_password_wo",
48+
original: "admin_password",
49+
writeOnlyAlternative: "admin_password_wo",
50+
otherAlternative: "manage_admin_password",
4751
},
4852
"aws_ssm_parameter": {
49-
original: "value",
50-
alternative: "value_wo",
53+
original: "value",
54+
writeOnlyAlternative: "value_wo",
5155
},
5256
}
5357
return &AwsWriteOnlyAttributesRule{
@@ -94,13 +98,18 @@ func (r *AwsWriteOnlyAttributesRule) Check(runner tflint.Runner) error {
9498
}
9599

96100
err := runner.EvaluateExpr(attribute.Expr, func(val cty.Value) error {
101+
mitigation := fmt.Sprintf("\"%s\" is a non-ephemeral attribute, which means this secret is stored in state. Please use write-only attribute \"%s\".", attributes.original, attributes.writeOnlyAlternative)
102+
if attributes.otherAlternative != "" {
103+
mitigation += fmt.Sprintf(" Alternatively, you can use \"%s\" to manage the secret in an different way.", attributes.otherAlternative)
104+
}
105+
97106
if !val.IsNull() {
98107
if err := runner.EmitIssueWithFix(
99108
r,
100-
fmt.Sprintf("\"%s\" is a non-ephemeral attribute, which means this secret is stored in state. Please use write-only attribute \"%s\".", attributes.original, attributes.alternative),
109+
mitigation,
101110
attribute.Expr.Range(),
102111
func(f tflint.Fixer) error {
103-
return f.ReplaceText(attribute.NameRange, attributes.alternative)
112+
return f.ReplaceText(attribute.NameRange, attributes.writeOnlyAlternative)
104113
},
105114
); err != nil {
106115
return fmt.Errorf("failed to call EmitIssueWithFix(): %w", err)

rules/aws_write_only_attributes_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ resource "aws_rds_cluster" "test" {
5757
Expected: helper.Issues{
5858
{
5959
Rule: NewAwsWriteOnlyAttributesRule(),
60-
Message: `"master_password" is a non-ephemeral attribute, which means this secret is stored in state. Please use write-only attribute "master_password_wo".`,
60+
Message: `"master_password" is a non-ephemeral attribute, which means this secret is stored in state. Please use write-only attribute "master_password_wo". Alternatively, you can use "manage_master_user_password" to manage the secret in an different way.`,
6161
Range: hcl.Range{
6262
Filename: "resource.tf",
6363
Start: hcl.Pos{Line: 3, Column: 21},
@@ -90,7 +90,7 @@ resource "aws_redshift_cluster" "test" {
9090
Expected: helper.Issues{
9191
{
9292
Rule: NewAwsWriteOnlyAttributesRule(),
93-
Message: `"master_password" is a non-ephemeral attribute, which means this secret is stored in state. Please use write-only attribute "master_password_wo".`,
93+
Message: `"master_password" is a non-ephemeral attribute, which means this secret is stored in state. Please use write-only attribute "master_password_wo". Alternatively, you can use "manage_master_password" to manage the secret in an different way.`,
9494
Range: hcl.Range{
9595
Filename: "resource.tf",
9696
Start: hcl.Pos{Line: 3, Column: 21},
@@ -157,7 +157,7 @@ resource "aws_redshiftserverless_namespace" "test" {
157157
Expected: helper.Issues{
158158
{
159159
Rule: NewAwsWriteOnlyAttributesRule(),
160-
Message: `"admin_password" is a non-ephemeral attribute, which means this secret is stored in state. Please use write-only attribute "admin_password_wo".`,
160+
Message: `"admin_password" is a non-ephemeral attribute, which means this secret is stored in state. Please use write-only attribute "admin_password_wo". Alternatively, you can use "manage_admin_password" to manage the secret in an different way.`,
161161
Range: hcl.Range{
162162
Filename: "resource.tf",
163163
Start: hcl.Pos{Line: 3, Column: 20},

0 commit comments

Comments
 (0)