mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #11119 from hashicorp/b-aws-route53-11114
provider/aws: Route53 Record: Add Type validation
This commit is contained in:
commit
b4053dcdc6
@ -47,9 +47,10 @@ func resourceAwsRoute53Record() *schema.Resource {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"type": &schema.Schema{
|
"type": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
|
ValidateFunc: validateRoute53RecordType,
|
||||||
},
|
},
|
||||||
|
|
||||||
"zone_id": &schema.Schema{
|
"zone_id": &schema.Schema{
|
||||||
|
@ -648,3 +648,28 @@ func validateOnceADayWindowFormat(v interface{}, k string) (ws []string, errors
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateRoute53RecordType(v interface{}, k string) (ws []string, errors []error) {
|
||||||
|
// Valid Record types
|
||||||
|
// SOA, A, TXT, NS, CNAME, MX, NAPTR, PTR, SRV, SPF, AAAA
|
||||||
|
validTypes := map[string]struct{}{
|
||||||
|
"SOA": {},
|
||||||
|
"A": {},
|
||||||
|
"TXT": {},
|
||||||
|
"NS": {},
|
||||||
|
"CNAME": {},
|
||||||
|
"MX": {},
|
||||||
|
"NAPTR": {},
|
||||||
|
"PTR": {},
|
||||||
|
"SRV": {},
|
||||||
|
"SPF": {},
|
||||||
|
"AAAA": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
value := v.(string)
|
||||||
|
if _, ok := validTypes[value]; !ok {
|
||||||
|
errors = append(errors, fmt.Errorf(
|
||||||
|
"%q must be one of [SOA, A, TXT, NS, CNAME, MX, NAPTR, PTR, SRV, SPF, AAAA]", k))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -1005,3 +1005,41 @@ func TestValidateOnceADayWindowFormat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateRoute53RecordType(t *testing.T) {
|
||||||
|
validTypes := []string{
|
||||||
|
"AAAA",
|
||||||
|
"SOA",
|
||||||
|
"A",
|
||||||
|
"TXT",
|
||||||
|
"CNAME",
|
||||||
|
"MX",
|
||||||
|
"NAPTR",
|
||||||
|
"PTR",
|
||||||
|
"SPF",
|
||||||
|
"SRV",
|
||||||
|
"NS",
|
||||||
|
}
|
||||||
|
|
||||||
|
invalidTypes := []string{
|
||||||
|
"a",
|
||||||
|
"alias",
|
||||||
|
"SpF",
|
||||||
|
"Txt",
|
||||||
|
"AaAA",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range validTypes {
|
||||||
|
_, errors := validateRoute53RecordType(v, "route53_record")
|
||||||
|
if len(errors) != 0 {
|
||||||
|
t.Fatalf("%q should be a valid Route53 record type: %v", v, errors)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range invalidTypes {
|
||||||
|
_, errors := validateRoute53RecordType(v, "route53_record")
|
||||||
|
if len(errors) == 0 {
|
||||||
|
t.Fatalf("%q should not be a valid Route53 record type", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user