From 8566bcee72939a80f5f73a5b5a75b1845f52c9ff Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 23 May 2019 09:57:09 -0700 Subject: [PATCH] New data source: Compute SSL certificate (#3683) Signed-off-by: Modular Magician --- ...a_source_google_compute_ssl_certificate.go | 29 ++++++++++++ ...rce_google_compute_ssl_certificate_test.go | 47 +++++++++++++++++++ google/provider.go | 1 + ...urce_compute_ssl_certificate.html.markdown | 47 +++++++++++++++++++ website/google.erb | 3 ++ 5 files changed, 127 insertions(+) create mode 100644 google/data_source_google_compute_ssl_certificate.go create mode 100644 google/data_source_google_compute_ssl_certificate_test.go create mode 100644 website/docs/d/datasource_compute_ssl_certificate.html.markdown diff --git a/google/data_source_google_compute_ssl_certificate.go b/google/data_source_google_compute_ssl_certificate.go new file mode 100644 index 00000000000..028cfab11c2 --- /dev/null +++ b/google/data_source_google_compute_ssl_certificate.go @@ -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) +} diff --git a/google/data_source_google_compute_ssl_certificate_test.go b/google/data_source_google_compute_ssl_certificate_test.go new file mode 100644 index 00000000000..ba66d07d481 --- /dev/null +++ b/google/data_source_google_compute_ssl_certificate_test.go @@ -0,0 +1,47 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +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( + checkDataSourceStateMatchesResourceStateWithIgnores( + "data.google_compute_ssl_certificate.cert", + "google_compute_ssl_certificate.foobar", + map[string]struct{}{ + "private_key": {}, + }, + ), + ), + }, + }, + }) +} + +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)) +} diff --git a/google/provider.go b/google/provider.go index bd08dd53681..686c785948c 100644 --- a/google/provider.go +++ b/google/provider.go @@ -100,6 +100,7 @@ func Provider() terraform.ResourceProvider { "google_compute_zones": dataSourceGoogleComputeZones(), "google_compute_vpn_gateway": dataSourceGoogleComputeVpnGateway(), "google_compute_ssl_policy": dataSourceGoogleComputeSslPolicy(), + "google_compute_ssl_certificate": dataSourceGoogleComputeSslCertificate(), "google_container_cluster": dataSourceGoogleContainerCluster(), "google_container_engine_versions": dataSourceGoogleContainerEngineVersions(), "google_container_registry_repository": dataSourceGoogleContainerRepo(), diff --git a/website/docs/d/datasource_compute_ssl_certificate.html.markdown b/website/docs/d/datasource_compute_ssl_certificate.html.markdown new file mode 100644 index 00000000000..e7e4efed82a --- /dev/null +++ b/website/docs/d/datasource_compute_ssl_certificate.html.markdown @@ -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. diff --git a/website/google.erb b/website/google.erb index 27c93f352ba..b614b43c7e6 100644 --- a/website/google.erb +++ b/website/google.erb @@ -90,6 +90,9 @@ > google_compute_regions + > + google_compute_ssl_certificate + > google_compute_ssl_policy