github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/cloudflare/validators.go (about) 1 package cloudflare 2 3 import ( 4 "fmt" 5 "net" 6 "strings" 7 ) 8 9 // validateRecordType ensures that the cloudflare record type is valid 10 func validateRecordType(t string, proxied bool) error { 11 switch t { 12 case "A": 13 return nil 14 case "AAAA": 15 return nil 16 case "CNAME": 17 return nil 18 case "TXT": 19 if !proxied { 20 return nil 21 } 22 case "SRV": 23 if !proxied { 24 return nil 25 } 26 case "LOC": 27 if !proxied { 28 return nil 29 } 30 case "MX": 31 if !proxied { 32 return nil 33 } 34 case "NS": 35 if !proxied { 36 return nil 37 } 38 case "SPF": 39 if !proxied { 40 return nil 41 } 42 default: 43 return fmt.Errorf( 44 `Invalid type %q. Valid types are "A", "AAAA", "CNAME", "TXT", "SRV", "LOC", "MX", "NS" or "SPF"`, t) 45 } 46 47 return fmt.Errorf("Type %q cannot be proxied", t) 48 } 49 50 // validateRecordName ensures that based on supplied record type, the name content matches 51 // Currently only validates A and AAAA types 52 func validateRecordName(t string, value string) error { 53 switch t { 54 case "A": 55 // Must be ipv4 addr 56 addr := net.ParseIP(value) 57 if addr == nil || !strings.Contains(value, ".") { 58 return fmt.Errorf("A record must be a valid IPv4 address, got: %q", value) 59 } 60 case "AAAA": 61 // Must be ipv6 addr 62 addr := net.ParseIP(value) 63 if addr == nil || !strings.Contains(value, ":") { 64 return fmt.Errorf("AAAA record must be a valid IPv6 address, got: %q", value) 65 } 66 } 67 68 return nil 69 }