github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/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_self_signed_cert": resourceSelfSignedCert(),
    18  			"tls_cert_request":     resourceCertRequest(),
    19  		},
    20  	}
    21  }
    22  
    23  func hashForState(value string) string {
    24  	if value == "" {
    25  		return ""
    26  	}
    27  	hash := sha1.Sum([]byte(strings.TrimSpace(value)))
    28  	return hex.EncodeToString(hash[:])
    29  }
    30  
    31  func nameFromResourceData(nameMap map[string]interface{}) (*pkix.Name, error) {
    32  	result := &pkix.Name{}
    33  
    34  	if value := nameMap["common_name"]; value != nil {
    35  		result.CommonName = value.(string)
    36  	}
    37  	if value := nameMap["organization"]; value != nil {
    38  		result.Organization = []string{value.(string)}
    39  	}
    40  	if value := nameMap["organizational_unit"]; value != nil {
    41  		result.OrganizationalUnit = []string{value.(string)}
    42  	}
    43  	if value := nameMap["street_address"]; value != nil {
    44  		valueI := value.([]interface{})
    45  		result.StreetAddress = make([]string, len(valueI))
    46  		for i, vi := range valueI {
    47  			result.StreetAddress[i] = vi.(string)
    48  		}
    49  	}
    50  	if value := nameMap["locality"]; value != nil {
    51  		result.Locality = []string{value.(string)}
    52  	}
    53  	if value := nameMap["province"]; value != nil {
    54  		result.Province = []string{value.(string)}
    55  	}
    56  	if value := nameMap["country"]; value != nil {
    57  		result.Country = []string{value.(string)}
    58  	}
    59  	if value := nameMap["postal_code"]; value != nil {
    60  		result.PostalCode = []string{value.(string)}
    61  	}
    62  	if value := nameMap["serial_number"]; value != nil {
    63  		result.SerialNumber = value.(string)
    64  	}
    65  
    66  	return result, nil
    67  }
    68  
    69  var nameSchema *schema.Resource = &schema.Resource{
    70  	Schema: map[string]*schema.Schema{
    71  		"organization": &schema.Schema{
    72  			Type:     schema.TypeString,
    73  			Optional: true,
    74  		},
    75  		"common_name": &schema.Schema{
    76  			Type:     schema.TypeString,
    77  			Optional: true,
    78  		},
    79  		"organizational_unit": &schema.Schema{
    80  			Type:     schema.TypeString,
    81  			Optional: true,
    82  		},
    83  		"street_address": &schema.Schema{
    84  			Type:     schema.TypeList,
    85  			Optional: true,
    86  			Elem: &schema.Schema{
    87  				Type: schema.TypeString,
    88  			},
    89  		},
    90  		"locality": &schema.Schema{
    91  			Type:     schema.TypeString,
    92  			Optional: true,
    93  		},
    94  		"province": &schema.Schema{
    95  			Type:     schema.TypeString,
    96  			Optional: true,
    97  		},
    98  		"country": &schema.Schema{
    99  			Type:     schema.TypeString,
   100  			Optional: true,
   101  		},
   102  		"postal_code": &schema.Schema{
   103  			Type:     schema.TypeString,
   104  			Optional: true,
   105  		},
   106  		"serial_number": &schema.Schema{
   107  			Type:     schema.TypeString,
   108  			Optional: true,
   109  		},
   110  	},
   111  }