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