diff --git a/builtin/providers/tls/resource_cert_request.go b/builtin/providers/tls/data_source_cert_request.go similarity index 86% rename from builtin/providers/tls/resource_cert_request.go rename to builtin/providers/tls/data_source_cert_request.go index 267f0db39..19bcd3129 100644 --- a/builtin/providers/tls/resource_cert_request.go +++ b/builtin/providers/tls/data_source_cert_request.go @@ -12,11 +12,9 @@ import ( const pemCertReqType = "CERTIFICATE REQUEST" -func resourceCertRequest() *schema.Resource { +func dataSourceCertRequest() *schema.Resource { return &schema.Resource{ - Create: CreateCertRequest, - Delete: DeleteCertRequest, - Read: ReadCertRequest, + Read: ReadCertRequest, Schema: map[string]*schema.Schema{ @@ -24,7 +22,6 @@ func resourceCertRequest() *schema.Resource { Type: schema.TypeList, Optional: true, Description: "List of DNS names to use as subjects of the certificate", - ForceNew: true, Elem: &schema.Schema{ Type: schema.TypeString, }, @@ -34,7 +31,6 @@ func resourceCertRequest() *schema.Resource { Type: schema.TypeList, Optional: true, Description: "List of IP addresses to use as subjects of the certificate", - ForceNew: true, Elem: &schema.Schema{ Type: schema.TypeString, }, @@ -44,14 +40,12 @@ func resourceCertRequest() *schema.Resource { Type: schema.TypeString, Required: true, Description: "Name of the algorithm to use to generate the certificate's private key", - ForceNew: true, }, "private_key_pem": &schema.Schema{ Type: schema.TypeString, Required: true, Description: "PEM-encoded private key that the certificate will belong to", - ForceNew: true, StateFunc: func(v interface{}) string { return hashForState(v.(string)) }, @@ -61,7 +55,6 @@ func resourceCertRequest() *schema.Resource { Type: schema.TypeList, Required: true, Elem: nameSchema, - ForceNew: true, }, "cert_request_pem": &schema.Schema{ @@ -72,7 +65,7 @@ func resourceCertRequest() *schema.Resource { } } -func CreateCertRequest(d *schema.ResourceData, meta interface{}) error { +func ReadCertRequest(d *schema.ResourceData, meta interface{}) error { key, err := parsePrivateKey(d, "private_key_pem", "key_algorithm") if err != nil { return err @@ -116,12 +109,3 @@ func CreateCertRequest(d *schema.ResourceData, meta interface{}) error { return nil } - -func DeleteCertRequest(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} - -func ReadCertRequest(d *schema.ResourceData, meta interface{}) error { - return nil -} diff --git a/builtin/providers/tls/resource_cert_request_test.go b/builtin/providers/tls/data_source_cert_request_test.go similarity index 96% rename from builtin/providers/tls/resource_cert_request_test.go rename to builtin/providers/tls/data_source_cert_request_test.go index c31b8d6a1..16cd29264 100644 --- a/builtin/providers/tls/resource_cert_request_test.go +++ b/builtin/providers/tls/data_source_cert_request_test.go @@ -12,12 +12,12 @@ import ( ) func TestCertRequest(t *testing.T) { - r.Test(t, r.TestCase{ + r.UnitTest(t, r.TestCase{ Providers: testProviders, Steps: []r.TestStep{ r.TestStep{ Config: fmt.Sprintf(` - resource "tls_cert_request" "test" { + data "tls_cert_request" "test" { subject { common_name = "example.com" organization = "Example, Inc" @@ -46,7 +46,7 @@ func TestCertRequest(t *testing.T) { EOT } output "key_pem" { - value = "${tls_cert_request.test.cert_request_pem}" + value = "${data.tls_cert_request.test.cert_request_pem}" } `, testPrivateKey), Check: func(s *terraform.State) error { diff --git a/builtin/providers/tls/provider.go b/builtin/providers/tls/provider.go index e6c1d6198..6f3363a95 100644 --- a/builtin/providers/tls/provider.go +++ b/builtin/providers/tls/provider.go @@ -12,11 +12,18 @@ import ( func Provider() terraform.ResourceProvider { return &schema.Provider{ + DataSourcesMap: map[string]*schema.Resource{ + "tls_cert_request": dataSourceCertRequest(), + }, ResourcesMap: map[string]*schema.Resource{ "tls_private_key": resourcePrivateKey(), "tls_locally_signed_cert": resourceLocallySignedCert(), "tls_self_signed_cert": resourceSelfSignedCert(), - "tls_cert_request": resourceCertRequest(), + + "tls_cert_request": schema.DataSourceResourceShim( + "tls_cert_request", + dataSourceCertRequest(), + ), }, } } diff --git a/website/source/docs/providers/tls/r/cert_request.html.md b/website/source/docs/providers/tls/d/cert_request.html.md similarity index 92% rename from website/source/docs/providers/tls/r/cert_request.html.md rename to website/source/docs/providers/tls/d/cert_request.html.md index aeb7e1180..8891171e0 100644 --- a/website/source/docs/providers/tls/r/cert_request.html.md +++ b/website/source/docs/providers/tls/d/cert_request.html.md @@ -13,13 +13,11 @@ typical format used to request a certificate from a certificate authority. This resource is intended to be used in conjunction with a Terraform provider for a particular certificate authority in order to provision a new certificate. -This is a *logical resource*, so it contributes only to the current Terraform -state and does not create any external managed resources. ## Example Usage ``` -resource "tls_cert_request" "example" { +data "tls_cert_request" "example" { key_algorithm = "ECDSA" private_key_pem = "${file(\"private_key.pem\")}" diff --git a/website/source/layouts/tls.erb b/website/source/layouts/tls.erb index 363a5a306..b47c089b7 100644 --- a/website/source/layouts/tls.erb +++ b/website/source/layouts/tls.erb @@ -10,6 +10,15 @@ TLS Provider + > + Data Sources + + + > Resources