-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for certificate map datasource (#8972) (#6316)
Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Hamza Hassan <[email protected]>
- Loading branch information
1 parent
b58487b
commit dc3a8ec
Showing
5 changed files
with
191 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,3 @@ | ||
```release-note:new-datasource | ||
google_certificate_manager_certificate_map | ||
``` |
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
46 changes: 46 additions & 0 deletions
46
...eta/services/certificatemanager/data_source_google_certificate_manager_certificate_map.go
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,46 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package certificatemanager | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" | ||
) | ||
|
||
func DataSourceGoogleCertificateManagerCertificateMap() *schema.Resource { | ||
|
||
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceCertificateManagerCertificateMap().Schema) | ||
tpgresource.AddRequiredFieldsToSchema(dsSchema, "name") | ||
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceGoogleCertificateManagerCertificateMapRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceGoogleCertificateManagerCertificateMapRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*transport_tpg.Config) | ||
|
||
name := d.Get("name").(string) | ||
|
||
project, err := tpgresource.GetProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id := fmt.Sprintf("projects/%s/locations/global/certificateMaps/%s", project, name) | ||
d.SetId(id) | ||
err = resourceCertificateManagerCertificateMapRead(d, meta) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if d.Id() == "" { | ||
return fmt.Errorf("%s not found", id) | ||
} | ||
return nil | ||
} |
111 changes: 111 additions & 0 deletions
111
...ervices/certificatemanager/data_source_google_certificate_manager_certificate_map_test.go
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,111 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package certificatemanager_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" | ||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" | ||
) | ||
|
||
func TestAccDataSourceGoogleCertificateManagerCertificateMap_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
project := envvar.GetTestProjectFromEnv() | ||
|
||
description := "My acceptance data source test certificate map" | ||
name := fmt.Sprintf("tf-test-certificate-map-%d", acctest.RandInt(t)) | ||
id := fmt.Sprintf("projects/%s/locations/global/certificateMaps/%s", project, name) | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleCertificateManagerCertificateMap_basic(name, description), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_certificate_manager_certificate_map.cert_map_data", "id", id), | ||
resource.TestCheckResourceAttr("data.google_certificate_manager_certificate_map.cert_map_data", "description", description), | ||
resource.TestCheckResourceAttr("data.google_certificate_manager_certificate_map.cert_map_data", "name", name), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceGoogleCertificateManagerCertificateMap_basic(certificateMapName, certificateMapDescription string) string { | ||
return fmt.Sprintf(` | ||
resource "google_certificate_manager_certificate_map" "cert_map" { | ||
name = "%s" | ||
description = "%s" | ||
labels = { | ||
"terraform" : true, | ||
"acc-test" : true, | ||
} | ||
} | ||
data "google_certificate_manager_certificate_map" "cert_map_data" { | ||
name = google_certificate_manager_certificate_map.cert_map.name | ||
} | ||
`, certificateMapName, certificateMapDescription) | ||
} | ||
|
||
func TestAccDataSourceGoogleCertificateManagerCertificateMap_certificateMapEntryUsingMapDatasource(t *testing.T) { | ||
t.Parallel() | ||
|
||
project := envvar.GetTestProjectFromEnv() | ||
|
||
certName := fmt.Sprintf("tf-test-certificate-%d", acctest.RandInt(t)) | ||
mapEntryName := fmt.Sprintf("tf-test-certificate-map-entry-%d", acctest.RandInt(t)) | ||
mapName := fmt.Sprintf("tf-test-certificate-map-%d", acctest.RandInt(t)) | ||
id := fmt.Sprintf("projects/%s/locations/global/certificateMaps/%s", project, mapName) | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleCertificateManagerCertificateMap_certificateMapEntryUsingMapDatasource(mapName, mapEntryName, certName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_certificate_manager_certificate_map.cert_map_data", "id", id), | ||
resource.TestCheckResourceAttr("data.google_certificate_manager_certificate_map.cert_map_data", "name", mapName), | ||
resource.TestCheckResourceAttr("google_certificate_manager_certificate_map_entry.cert_map_entry", "map", mapName), // check that the certificate map entry is referencing the data source | ||
|
||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceGoogleCertificateManagerCertificateMap_certificateMapEntryUsingMapDatasource(certificateMapName, certificateMapEntryName, certificateName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_certificate_manager_certificate_map" "cert_map" { | ||
name = "%s" | ||
description = "certificate map example created for testing data sources in TF" | ||
labels = { | ||
"terraform" : true, | ||
"acc-test" : true, | ||
} | ||
} | ||
data "google_certificate_manager_certificate_map" "cert_map_data" { | ||
name = google_certificate_manager_certificate_map.cert_map.name | ||
} | ||
resource "google_certificate_manager_certificate" "certificate" { | ||
name = "%s" | ||
description = "Global cert" | ||
self_managed { | ||
pem_certificate = file("test-fixtures/cert.pem") | ||
pem_private_key = file("test-fixtures/private-key.pem") | ||
} | ||
} | ||
resource "google_certificate_manager_certificate_map_entry" "cert_map_entry" { | ||
name = "%s" | ||
description = "certificate map entry that reference a data source of certificate map and a self managed certificate" | ||
map = data.google_certificate_manager_certificate_map.cert_map_data.name | ||
certificates = [google_certificate_manager_certificate.certificate.id] | ||
matcher = "PRIMARY" | ||
} | ||
`, certificateMapName, certificateName, certificateMapEntryName) | ||
} |
30 changes: 30 additions & 0 deletions
30
website/docs/d/certificate_manager_certificate_map.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,30 @@ | ||
--- | ||
subcategory: "Certificate manager" | ||
description: |- | ||
Contains the data that describes a Certificate Map | ||
--- | ||
# google_certificate_manager_certificate_map | ||
|
||
Get info about a Google Certificate Manager Certificate Map resource. | ||
|
||
## Example Usage | ||
|
||
```tf | ||
data "google_certificate_manager_certificate_map" "default" { | ||
name = "cert-map" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the certificate map. | ||
|
||
- - - | ||
* `project` - (Optional) The ID of the project in which the resource belongs. If it | ||
is not provided, the provider project is used. | ||
|
||
## Attributes Reference | ||
|
||
See [google_certificate_manager_certificate_map](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/certificate_manager_certificate_map) resource for details of the available attributes. |