Skip to content

Commit

Permalink
New data source: Compute SSL certificate (#3683)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and danawillow committed May 23, 2019
1 parent 31b61b7 commit 8566bce
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
29 changes: 29 additions & 0 deletions google/data_source_google_compute_ssl_certificate.go
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)
}
47 changes: 47 additions & 0 deletions google/data_source_google_compute_ssl_certificate_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
47 changes: 47 additions & 0 deletions website/docs/d/datasource_compute_ssl_certificate.html.markdown
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.
3 changes: 3 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<li<%= sidebar_current("docs-google-datasource-compute-regions") %>>
<a href="/docs/providers/google/d/google_compute_regions.html">google_compute_regions</a>
</li>
<li<%= sidebar_current("docs-google-datasource-compute-ssl-certificate") %>>
<a href="/docs/providers/google/d/datasource_compute_ssl_certificate.html">google_compute_ssl_certificate</a>
</li>
<li<%= sidebar_current("docs-google-datasource-compute-ssl-policy") %>>
<a href="/docs/providers/google/d/datasource_compute_ssl_policy.html">google_compute_ssl_policy</a>
</li>
Expand Down

0 comments on commit 8566bce

Please sign in to comment.