-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New data source: Compute SSL certificate
Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
a023def
commit 8cf83e2
Showing
4 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package google | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleComputeSslCertificate() *schema.Resource { | ||
// Generate datasource schema from resource | ||
dsSchema := datasourceSchemaFromResourceSchema(resourceComputeSslCertificate().Schema) | ||
|
||
// Set 'Required' schema elements | ||
addRequiredFieldsToSchema(dsSchema, "name") | ||
|
||
// Set 'Optional' schema elements | ||
addOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceComputeSslCertificateRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceComputeSslCertificateRead(d *schema.ResourceData, meta interface{}) error { | ||
certificateName := d.Get("name").(string) | ||
|
||
d.SetId(certificateName) | ||
|
||
return resourceComputeSslCertificateRead(d, meta) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDataSourceComputeSslCertificate(t *testing.T) { | ||
t.Parallel() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceComputeSslCertificateConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccDataSourceComputeSslCertificateCheck("data.google_compute_ssl_certificate.cert", "google_compute_ssl_certificate.foobar"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceComputeSslCertificateCheck(dataSourceName string, resourceName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
ds, ok := s.RootModule().Resources[dataSourceName] | ||
if !ok { | ||
return fmt.Errorf("root module has no resource called %s", dataSourceName) | ||
} | ||
|
||
rs, ok := s.RootModule().Resources[resourceName] | ||
if !ok { | ||
return fmt.Errorf("can't find %s in state", resourceName) | ||
} | ||
|
||
dsAttr := ds.Primary.Attributes | ||
rsAttr := rs.Primary.Attributes | ||
|
||
certificateAttrToCheck := []string{ | ||
"name", | ||
"project", | ||
"description", | ||
"certificate", | ||
"certificate_id", | ||
"self_link", | ||
"creation_timestamp", | ||
} | ||
|
||
for _, attr := range certificateAttrToCheck { | ||
if dsAttr[attr] != rsAttr[attr] { | ||
return fmt.Errorf( | ||
"%s is %s; want %s", | ||
attr, | ||
dsAttr[attr], | ||
rsAttr[attr], | ||
) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccDataSourceComputeSslCertificateConfig() string { | ||
return fmt.Sprintf(` | ||
resource "google_compute_ssl_certificate" "foobar" { | ||
name = "cert-test-%s" | ||
description = "really descriptive" | ||
private_key = "${file("test-fixtures/ssl_cert/test.key")}" | ||
certificate = "${file("test-fixtures/ssl_cert/test.crt")}" | ||
} | ||
data "google_compute_ssl_certificate" "cert" { | ||
name = "${google_compute_ssl_certificate.foobar.name}" | ||
} | ||
`, acctest.RandString(10)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
website/docs/d/datasource_compute_ssl_certificate.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
layout: "google" | ||
page_title: "Google: google_compute_ssl_certificate" | ||
sidebar_current: "docs-google-datasource-compute-ssl-certificate" | ||
description: |- | ||
Get info about a Google Compute SSL Certificate. | ||
--- | ||
|
||
# google\_compute\_ssl\_certificate | ||
|
||
Get info about a Google Compute SSL Certificate from its name. | ||
|
||
## Example Usage | ||
|
||
```tf | ||
data "google_compute_ssl_certificate" "my_cert" { | ||
name = "my-cert" | ||
location = "us-east1-a" | ||
} | ||
output "certificate" { | ||
value = "${data.google_compute_ssl_certificate.my_cert.certificate}" | ||
} | ||
output "certificate_id" { | ||
value = "${data.google_compute_ssl_certificate.my_cert.certificate_id}" | ||
} | ||
output "self_link" { | ||
value = "${data.google_compute_ssl_certificate.my_cert.self_link}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` (Required) - The name of the certificate. | ||
|
||
- - - | ||
|
||
* `project` - (Optional) The project in which the resource belongs. If it | ||
is not provided, the provider project is used. | ||
|
||
## Attributes Reference | ||
|
||
See [google_compute_ssl_certificate](https://www.terraform.io/docs/providers/google/r/compute_ssl_certificate.html) resource for details of the available attributes. |