github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/tls/provider.go (about) 1 package tls 2 3 import ( 4 "crypto/sha1" 5 "crypto/x509/pkix" 6 "encoding/hex" 7 "strings" 8 9 "github.com/hashicorp/terraform/helper/schema" 10 "github.com/hashicorp/terraform/terraform" 11 ) 12 13 func Provider() terraform.ResourceProvider { 14 return &schema.Provider{ 15 ResourcesMap: map[string]*schema.Resource{ 16 "tls_private_key": resourcePrivateKey(), 17 "tls_locally_signed_cert": resourceLocallySignedCert(), 18 "tls_self_signed_cert": resourceSelfSignedCert(), 19 "tls_cert_request": resourceCertRequest(), 20 }, 21 } 22 } 23 24 func hashForState(value string) string { 25 if value == "" { 26 return "" 27 } 28 hash := sha1.Sum([]byte(strings.TrimSpace(value))) 29 return hex.EncodeToString(hash[:]) 30 } 31 32 func nameFromResourceData(nameMap map[string]interface{}) (*pkix.Name, error) { 33 result := &pkix.Name{} 34 35 if value := nameMap["common_name"]; value != nil { 36 result.CommonName = value.(string) 37 } 38 if value := nameMap["organization"]; value != nil { 39 result.Organization = []string{value.(string)} 40 } 41 if value := nameMap["organizational_unit"]; value != nil { 42 result.OrganizationalUnit = []string{value.(string)} 43 } 44 if value := nameMap["street_address"]; value != nil { 45 valueI := value.([]interface{}) 46 result.StreetAddress = make([]string, len(valueI)) 47 for i, vi := range valueI { 48 result.StreetAddress[i] = vi.(string) 49 } 50 } 51 if value := nameMap["locality"]; value != nil { 52 result.Locality = []string{value.(string)} 53 } 54 if value := nameMap["province"]; value != nil { 55 result.Province = []string{value.(string)} 56 } 57 if value := nameMap["country"]; value != nil { 58 result.Country = []string{value.(string)} 59 } 60 if value := nameMap["postal_code"]; value != nil { 61 result.PostalCode = []string{value.(string)} 62 } 63 if value := nameMap["serial_number"]; value != nil { 64 result.SerialNumber = value.(string) 65 } 66 67 return result, nil 68 } 69 70 var nameSchema *schema.Resource = &schema.Resource{ 71 Schema: map[string]*schema.Schema{ 72 "organization": &schema.Schema{ 73 Type: schema.TypeString, 74 Optional: true, 75 }, 76 "common_name": &schema.Schema{ 77 Type: schema.TypeString, 78 Optional: true, 79 }, 80 "organizational_unit": &schema.Schema{ 81 Type: schema.TypeString, 82 Optional: true, 83 }, 84 "street_address": &schema.Schema{ 85 Type: schema.TypeList, 86 Optional: true, 87 Elem: &schema.Schema{ 88 Type: schema.TypeString, 89 }, 90 }, 91 "locality": &schema.Schema{ 92 Type: schema.TypeString, 93 Optional: true, 94 }, 95 "province": &schema.Schema{ 96 Type: schema.TypeString, 97 Optional: true, 98 }, 99 "country": &schema.Schema{ 100 Type: schema.TypeString, 101 Optional: true, 102 }, 103 "postal_code": &schema.Schema{ 104 Type: schema.TypeString, 105 Optional: true, 106 }, 107 "serial_number": &schema.Schema{ 108 Type: schema.TypeString, 109 Optional: true, 110 }, 111 }, 112 }