Skip to content

Commit

Permalink
Add certificate_name to load balancer data source. (#641)
Browse files Browse the repository at this point in the history
* Add certificate_name to load balancer data source.

* Use new SDK resource.TestCheckTypeSetElemNestedAttrs
  • Loading branch information
andrewsomething authored May 28, 2021
1 parent f017e00 commit d1f4688
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions digitalocean/datasource_digitalocean_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func dataSourceDigitalOceanLoadbalancer() *schema.Resource {
Computed: true,
Description: "the id of the tls certificate used for ssl termination if enabled",
},
"certificate_name": {
Type: schema.TypeString,
Computed: true,
Description: "the name of the tls certificate used for ssl termination if enabled",
},
"tls_passthrough": {
Type: schema.TypeBool,
Computed: true,
Expand Down
56 changes: 56 additions & 0 deletions digitalocean/datasource_digitalocean_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/digitalocean/godo"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
Expand Down Expand Up @@ -190,6 +191,61 @@ data "digitalocean_loadbalancer" "foobar" {
})
}

func TestAccDataSourceDigitalOceanLoadBalancer_tlsCert(t *testing.T) {
var loadbalancer godo.LoadBalancer
testName := randomTestName()
rInt := acctest.RandInt()
privateKeyMaterial, leafCertMaterial, certChainMaterial := generateTestCertMaterial(t)
resourceConfig := testAccCheckDigitalOceanLoadbalancerConfig_sslTermination(
testName+"-cert", rInt, privateKeyMaterial, leafCertMaterial, certChainMaterial, "certificate_name",
)
dataSourceConfig := `
data "digitalocean_loadbalancer" "foobar" {
name = digitalocean_loadbalancer.foobar.name
}`

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanLoadbalancerDestroy,
Steps: []resource.TestStep{
{
Config: resourceConfig,
},
{
Config: resourceConfig + dataSourceConfig,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckDigitalOceanLoadbalancerExists("data.digitalocean_loadbalancer.foobar", &loadbalancer),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "name", fmt.Sprintf("loadbalancer-%d", rInt)),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "region", "nyc3"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(
"data.digitalocean_loadbalancer.foobar",
"forwarding_rule.*",
map[string]string{
"entry_port": "443",
"entry_protocol": "https",
"target_port": "80",
"target_protocol": "http",
"certificate_name": testName + "-cert",
"tls_passthrough": "false",
},
),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "size", "lb-small"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "redirect_http_to_https", "true"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "enable_proxy_protocol", "true"),
),
},
},
})
}

func testAccCheckDataSourceDigitalOceanLoadBalancerExists(n string, loadbalancer *godo.LoadBalancer) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down

0 comments on commit d1f4688

Please sign in to comment.