Skip to content

Commit 7f52256

Browse files
committed
Restore aws_dms_s3_endpoint validation rules with enum transforms
Fixes #989 The `aws_dms_s3_endpoint` mapping was accidentally removed during the Smithy migration in #901. This restores the mapping and adds support for transforming enum values to match Terraform provider expectations. ## Changes ### Mapping restoration - Add `aws_dms_s3_endpoint` mapping to `dms.hcl` - Generate validation rules for 8 attributes (compression_type, encryption_mode, data_format, encoding_type, parquet_version, date_partition_sequence, date_partition_delimiter, canned_acl_for_objects) ### Transform system - Implement HCL function-based transform system in generator - Use `uppercase()` and `replace()` functions directly in mapping expressions - Leverage HCL's `EvalContext` with custom list-transform wrappers ### Enum value corrections - `compression_type`: Smithy "none"/"gzip" → Terraform "NONE"/"GZIP" - `encryption_mode`: Smithy "sse-kms"/"sse-s3" → Terraform "SSE_KMS"/"SSE_S3" - Other enums similarly transformed to uppercase This approach keeps transform logic declarative in the mapping files rather than hardcoded in the generator, making it maintainable and extensible for future cases where Smithy and Terraform enum formats differ.
1 parent 88c5499 commit 7f52256

12 files changed

+978
-1
lines changed

docs/rules/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,14 @@ These rules enforce best practices and naming conventions:
517517
|aws_dms_endpoint_invalid_endpoint_type||
518518
|aws_dms_endpoint_invalid_ssl_mode||
519519
|aws_dms_replication_task_invalid_migration_type||
520+
|aws_dms_s3_endpoint_invalid_canned_acl_for_objects||
521+
|aws_dms_s3_endpoint_invalid_compression_type||
522+
|aws_dms_s3_endpoint_invalid_data_format||
523+
|aws_dms_s3_endpoint_invalid_date_partition_delimiter||
524+
|aws_dms_s3_endpoint_invalid_date_partition_sequence||
525+
|aws_dms_s3_endpoint_invalid_encoding_type||
526+
|aws_dms_s3_endpoint_invalid_encryption_mode||
527+
|aws_dms_s3_endpoint_invalid_parquet_version||
520528
|aws_docdb_global_cluster_invalid_global_cluster_identifier||
521529
|aws_dx_bgp_peer_invalid_address_family||
522530
|aws_dx_hosted_private_virtual_interface_invalid_address_family||
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
9+
"github.com/terraform-linters/tflint-plugin-sdk/logger"
10+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
11+
)
12+
13+
// AwsDmsS3EndpointInvalidCannedACLForObjectsRule checks the pattern is valid
14+
type AwsDmsS3EndpointInvalidCannedACLForObjectsRule struct {
15+
tflint.DefaultRule
16+
17+
resourceType string
18+
attributeName string
19+
enum []string
20+
}
21+
22+
// NewAwsDmsS3EndpointInvalidCannedACLForObjectsRule returns new rule with default attributes
23+
func NewAwsDmsS3EndpointInvalidCannedACLForObjectsRule() *AwsDmsS3EndpointInvalidCannedACLForObjectsRule {
24+
return &AwsDmsS3EndpointInvalidCannedACLForObjectsRule{
25+
resourceType: "aws_dms_s3_endpoint",
26+
attributeName: "canned_acl_for_objects",
27+
enum: []string{
28+
"AUTHENTICATED-READ",
29+
"AWS-EXEC-READ",
30+
"BUCKET-OWNER-FULL-CONTROL",
31+
"BUCKET-OWNER-READ",
32+
"NONE",
33+
"PRIVATE",
34+
"PUBLIC-READ",
35+
"PUBLIC-READ-WRITE",
36+
},
37+
}
38+
}
39+
40+
// Name returns the rule name
41+
func (r *AwsDmsS3EndpointInvalidCannedACLForObjectsRule) Name() string {
42+
return "aws_dms_s3_endpoint_invalid_canned_acl_for_objects"
43+
}
44+
45+
// Enabled returns whether the rule is enabled by default
46+
func (r *AwsDmsS3EndpointInvalidCannedACLForObjectsRule) Enabled() bool {
47+
return true
48+
}
49+
50+
// Severity returns the rule severity
51+
func (r *AwsDmsS3EndpointInvalidCannedACLForObjectsRule) Severity() tflint.Severity {
52+
return tflint.ERROR
53+
}
54+
55+
// Link returns the rule reference link
56+
func (r *AwsDmsS3EndpointInvalidCannedACLForObjectsRule) Link() string {
57+
return ""
58+
}
59+
60+
// Check checks the pattern is valid
61+
func (r *AwsDmsS3EndpointInvalidCannedACLForObjectsRule) Check(runner tflint.Runner) error {
62+
logger.Trace("Check `%s` rule", r.Name())
63+
64+
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{
65+
Attributes: []hclext.AttributeSchema{
66+
{Name: r.attributeName},
67+
},
68+
}, nil)
69+
if err != nil {
70+
return err
71+
}
72+
73+
for _, resource := range resources.Blocks {
74+
attribute, exists := resource.Body.Attributes[r.attributeName]
75+
if !exists {
76+
continue
77+
}
78+
79+
err := runner.EvaluateExpr(attribute.Expr, func (val string) error {
80+
found := false
81+
for _, item := range r.enum {
82+
if item == val {
83+
found = true
84+
}
85+
}
86+
if !found {
87+
runner.EmitIssue(
88+
r,
89+
fmt.Sprintf(`"%s" is an invalid value as canned_acl_for_objects`, truncateLongMessage(val)),
90+
attribute.Expr.Range(),
91+
)
92+
}
93+
return nil
94+
}, nil)
95+
if err != nil {
96+
return err
97+
}
98+
}
99+
100+
return nil
101+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
9+
"github.com/terraform-linters/tflint-plugin-sdk/logger"
10+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
11+
)
12+
13+
// AwsDmsS3EndpointInvalidCompressionTypeRule checks the pattern is valid
14+
type AwsDmsS3EndpointInvalidCompressionTypeRule struct {
15+
tflint.DefaultRule
16+
17+
resourceType string
18+
attributeName string
19+
enum []string
20+
}
21+
22+
// NewAwsDmsS3EndpointInvalidCompressionTypeRule returns new rule with default attributes
23+
func NewAwsDmsS3EndpointInvalidCompressionTypeRule() *AwsDmsS3EndpointInvalidCompressionTypeRule {
24+
return &AwsDmsS3EndpointInvalidCompressionTypeRule{
25+
resourceType: "aws_dms_s3_endpoint",
26+
attributeName: "compression_type",
27+
enum: []string{
28+
"GZIP",
29+
"NONE",
30+
},
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsDmsS3EndpointInvalidCompressionTypeRule) Name() string {
36+
return "aws_dms_s3_endpoint_invalid_compression_type"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsDmsS3EndpointInvalidCompressionTypeRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsDmsS3EndpointInvalidCompressionTypeRule) Severity() tflint.Severity {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsDmsS3EndpointInvalidCompressionTypeRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsDmsS3EndpointInvalidCompressionTypeRule) Check(runner tflint.Runner) error {
56+
logger.Trace("Check `%s` rule", r.Name())
57+
58+
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{
59+
Attributes: []hclext.AttributeSchema{
60+
{Name: r.attributeName},
61+
},
62+
}, nil)
63+
if err != nil {
64+
return err
65+
}
66+
67+
for _, resource := range resources.Blocks {
68+
attribute, exists := resource.Body.Attributes[r.attributeName]
69+
if !exists {
70+
continue
71+
}
72+
73+
err := runner.EvaluateExpr(attribute.Expr, func (val string) error {
74+
found := false
75+
for _, item := range r.enum {
76+
if item == val {
77+
found = true
78+
}
79+
}
80+
if !found {
81+
runner.EmitIssue(
82+
r,
83+
fmt.Sprintf(`"%s" is an invalid value as compression_type`, truncateLongMessage(val)),
84+
attribute.Expr.Range(),
85+
)
86+
}
87+
return nil
88+
}, nil)
89+
if err != nil {
90+
return err
91+
}
92+
}
93+
94+
return nil
95+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
9+
"github.com/terraform-linters/tflint-plugin-sdk/logger"
10+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
11+
)
12+
13+
// AwsDmsS3EndpointInvalidDataFormatRule checks the pattern is valid
14+
type AwsDmsS3EndpointInvalidDataFormatRule struct {
15+
tflint.DefaultRule
16+
17+
resourceType string
18+
attributeName string
19+
enum []string
20+
}
21+
22+
// NewAwsDmsS3EndpointInvalidDataFormatRule returns new rule with default attributes
23+
func NewAwsDmsS3EndpointInvalidDataFormatRule() *AwsDmsS3EndpointInvalidDataFormatRule {
24+
return &AwsDmsS3EndpointInvalidDataFormatRule{
25+
resourceType: "aws_dms_s3_endpoint",
26+
attributeName: "data_format",
27+
enum: []string{
28+
"csv",
29+
"parquet",
30+
},
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsDmsS3EndpointInvalidDataFormatRule) Name() string {
36+
return "aws_dms_s3_endpoint_invalid_data_format"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsDmsS3EndpointInvalidDataFormatRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsDmsS3EndpointInvalidDataFormatRule) Severity() tflint.Severity {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsDmsS3EndpointInvalidDataFormatRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsDmsS3EndpointInvalidDataFormatRule) Check(runner tflint.Runner) error {
56+
logger.Trace("Check `%s` rule", r.Name())
57+
58+
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{
59+
Attributes: []hclext.AttributeSchema{
60+
{Name: r.attributeName},
61+
},
62+
}, nil)
63+
if err != nil {
64+
return err
65+
}
66+
67+
for _, resource := range resources.Blocks {
68+
attribute, exists := resource.Body.Attributes[r.attributeName]
69+
if !exists {
70+
continue
71+
}
72+
73+
err := runner.EvaluateExpr(attribute.Expr, func (val string) error {
74+
found := false
75+
for _, item := range r.enum {
76+
if item == val {
77+
found = true
78+
}
79+
}
80+
if !found {
81+
runner.EmitIssue(
82+
r,
83+
fmt.Sprintf(`"%s" is an invalid value as data_format`, truncateLongMessage(val)),
84+
attribute.Expr.Range(),
85+
)
86+
}
87+
return nil
88+
}, nil)
89+
if err != nil {
90+
return err
91+
}
92+
}
93+
94+
return nil
95+
}

0 commit comments

Comments
 (0)