Skip to content

test(lb): fix TestAccScalewayLbCertificate_Basic #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions scaleway/resource_lb_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

func TestAccScalewayLbCertificate_Basic(t *testing.T) {
/**
* Note regarding the usage of xip.io
* See the discussion on https://github.com/terraform-providers/terraform-provider-scaleway/pull/396
* See the discussion on https://github.com/scaleway/terraform-provider-scaleway/pull/396
* Long story short, scaleway API will not permit you to request a certificate in case common name is not pointed
* to the load balancer IP (which is unknown before creating it). In production, this can be overcome by introducing
* an additional step which creates a DNS record and depending on it, but for test purposes, xip.io is an ideal solution.
* an additional step which creates a DNS record and depending on it
* We use a DNS name like: 195-154-70-235.lb.fr-par.scw.cloud
*/
tt := NewTestTools(t)
defer tt.Cleanup()
Expand All @@ -23,17 +23,20 @@ func TestAccScalewayLbCertificate_Basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
resource scaleway_lb_ip ip01 {}
resource scaleway_lb_ip ip01 {
}

resource scaleway_lb lb01 {
ip_id = scaleway_lb_ip.ip01.id
name = "test-lb"
type = "lb-s"
}

resource scaleway_lb_certificate cert01 {
lb_id = scaleway_lb.lb01.id
name = "test-cert"
letsencrypt {
common_name = "${scaleway_lb.lb01.ip_address}.xip.io"
common_name = "${replace(scaleway_lb_ip.ip01.ip_address,".", "-")}.lb.${scaleway_lb.lb01.region}.scw.cloud"
}
}
`,
Expand All @@ -44,18 +47,21 @@ func TestAccScalewayLbCertificate_Basic(t *testing.T) {
},
{
Config: `
resource scaleway_lb_ip ip01 {}
resource scaleway_lb_ip ip01 {
}

resource scaleway_lb lb01 {
ip_id = scaleway_lb_ip.ip01.id
name = "test-lb"
type = "lb-s"
ip_id = scaleway_lb_ip.ip01.id
name = "test-lb"
type = "lb-s"
}

resource scaleway_lb_certificate cert01 {
lb_id = scaleway_lb.lb01.id
name = "test-cert-new"
letsencrypt {
common_name = "${scaleway_lb.lb01.ip_address}.xip.io"
}
letsencrypt {
common_name = "${replace(scaleway_lb.lb01.ip_address, ".", "-")}.lb.${scaleway_lb.lb01.region}.scw.cloud"
}
}
`,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -64,24 +70,27 @@ func TestAccScalewayLbCertificate_Basic(t *testing.T) {
},
{
Config: `
resource scaleway_lb_ip ip01 {}
resource scaleway_lb_ip ip01 {
}

resource scaleway_lb lb01 {
ip_id = scaleway_lb_ip.ip01.id
name = "test-lb"
type = "lb-s"
}

resource scaleway_lb_certificate cert01 {
lb_id = scaleway_lb.lb01.id
name = "test-cert"
letsencrypt {
common_name = "${scaleway_lb.lb01.ip_address}.xip.io"
letsencrypt {
common_name = "${replace(scaleway_lb.lb01.ip_address, ".", "-")}.lb.${scaleway_lb.lb01.region}.scw.cloud"
subject_alternative_name = [
"sub1.${scaleway_lb.lb01.ip_address}.xip.io",
"sub2.${scaleway_lb.lb01.ip_address}.xip.io"
"sub1.${replace(scaleway_lb.lb01.ip_address, ".", "-")}.lb.${scaleway_lb.lb01.region}.scw.cloud",
"sub2.${replace(scaleway_lb.lb01.ip_address, ".", "-")}.lb.${scaleway_lb.lb01.region}.scw.cloud"
]
}
}
}
`,
`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("scaleway_lb_certificate.cert01", "name", "test-cert"),
resource.TestCheckResourceAttr("scaleway_lb_certificate.cert01", "letsencrypt.#", "1"),
Expand All @@ -90,12 +99,15 @@ func TestAccScalewayLbCertificate_Basic(t *testing.T) {
},
{
Config: `
resource scaleway_lb_ip ip01 {}
resource scaleway_lb_ip ip01 {
}

resource scaleway_lb lb01 {
ip_id = scaleway_lb_ip.ip01.id
name = "test-lb"
type = "lb-s"
}

resource scaleway_lb_certificate cert01 {
lb_id = scaleway_lb.lb01.id
name = "test-custom-cert"
Expand Down
Loading