Skip to content
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

Support Managed Load Balancer as Resources #122

Merged
merged 11 commits into from
May 24, 2024
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
43 changes: 11 additions & 32 deletions ecl/data_source_ecl_mlb_certificate_v1.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*
Generated by https://github.com/tamac-io/openapi-to-terraform-rb
*/
package ecl

import (
Expand All @@ -14,11 +11,9 @@ import (

func certificateFileSchemaForDataSource() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Type: schema.TypeMap,
Optional: true,
Computed: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": &schema.Schema{
Expand Down Expand Up @@ -86,31 +81,21 @@ func dataSourceMLBCertificateV1Read(d *schema.ResourceData, meta interface{}) er
listOpts.TenantID = v.(string)
}

if v, ok := d.GetOk("ca_cert_status"); ok {
listOpts.CACertStatus = v.(string)
}

if v, ok := d.GetOk("ssl_cert_status"); ok {
listOpts.SSLCertStatus = v.(string)
}

if v, ok := d.GetOk("ssl_key_status"); ok {
listOpts.SSLKeyStatus = v.(string)
}

managedLoadBalancerClient, err := config.managedLoadBalancerV1Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating ECL managed load balancer client: %s", err)
}

log.Printf("[DEBUG] Retrieving ECL managed load balancer certificates with options %+v", listOpts)

pages, err := certificates.List(managedLoadBalancerClient, listOpts).AllPages()
if err != nil {
return err
}

allCertificates, err := certificates.ExtractCertificates(pages)
if err != nil {
return fmt.Errorf("Unable to retrieve certificates: %s", err)
return fmt.Errorf("Unable to retrieve ECL managed load balancer certificates with options %+v: %s", listOpts, err)
}

if len(allCertificates) < 1 {
Expand All @@ -125,24 +110,18 @@ func dataSourceMLBCertificateV1Read(d *schema.ResourceData, meta interface{}) er

certificate := allCertificates[0]

log.Printf("[DEBUG] Retrieved certificate %s: %+v", d.Id(), certificate)
log.Printf("[DEBUG] Retrieved ECL managed load balancer certificate: %+v", certificate)

d.SetId(certificate.ID)

sslKey := make([]interface{}, 1)
sslKeyResult := make(map[string]interface{})
sslKeyResult["status"] = certificate.SSLKey.Status
sslKey[0] = sslKeyResult
sslKey := make(map[string]interface{})
sslKey["status"] = certificate.SSLKey.Status

sslCert := make([]interface{}, 1)
sslCertResult := make(map[string]interface{})
sslCertResult["status"] = certificate.SSLCert.Status
sslCert[0] = sslCertResult
sslCert := make(map[string]interface{})
sslCert["status"] = certificate.SSLCert.Status

caCert := make([]interface{}, 1)
caCertResult := make(map[string]interface{})
caCertResult["status"] = certificate.CACert.Status
caCert[0] = caCertResult
caCert := make(map[string]interface{})
caCert["status"] = certificate.CACert.Status

d.Set("name", certificate.Name)
d.Set("description", certificate.Description)
Expand Down
117 changes: 110 additions & 7 deletions ecl/data_source_ecl_mlb_certificate_v1_mock_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*
Generated by https://github.com/tamac-io/openapi-to-terraform-rb
*/
package ecl

import (
Expand All @@ -20,6 +17,8 @@ func TestMockedAccMLBV1CertificateDataSource(t *testing.T) {

mc.Register(t, "keystone", "/v3/auth/tokens", postKeystone)
mc.Register(t, "certificates", "/v1.0/certificates", testMockMLBV1CertificatesListNameQuery)
mc.Register(t, "certificates", "/v1.0/certificates", testMockMLBV1CertificatesListDescriptionQuery)
mc.Register(t, "certificates", "/v1.0/certificates", testMockMLBV1CertificatesListTenantIDQuery)

mc.StartServer(t)

Expand All @@ -30,14 +29,40 @@ func TestMockedAccMLBV1CertificateDataSource(t *testing.T) {
{
Config: testAccMLBV1CertificateDataSourceQueryName,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ecl_mlb_certificate_v1.certificate_1", "id"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "id", "497f6eca-6276-4993-bfeb-53cbbbba6f08"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "name", "certificate"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "description", "description"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "tags.key", "value"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "tenant_id", "34f5c98ef430457ba81292637d0c6fd0"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ca_cert.0.status", "NOT_UPLOADED"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ssl_cert.0.status", "NOT_UPLOADED"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ssl_key.0.status", "NOT_UPLOADED"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ca_cert.status", "NOT_UPLOADED"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ssl_cert.status", "NOT_UPLOADED"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ssl_key.status", "NOT_UPLOADED"),
),
},
{
Config: testAccMLBV1CertificateDataSourceQueryDescription,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "id", "497f6eca-6276-4993-bfeb-53cbbbba6f08"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "name", "certificate"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "description", "description"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "tags.key", "value"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "tenant_id", "34f5c98ef430457ba81292637d0c6fd0"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ca_cert.status", "NOT_UPLOADED"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ssl_cert.status", "NOT_UPLOADED"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ssl_key.status", "NOT_UPLOADED"),
),
},
{
Config: testAccMLBV1CertificateDataSourceQueryTenantID,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "id", "497f6eca-6276-4993-bfeb-53cbbbba6f08"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "name", "certificate"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "description", "description"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "tags.key", "value"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "tenant_id", "34f5c98ef430457ba81292637d0c6fd0"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ca_cert.status", "NOT_UPLOADED"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ssl_cert.status", "NOT_UPLOADED"),
resource.TestCheckResourceAttr("data.ecl_mlb_certificate_v1.certificate_1", "ssl_key.status", "NOT_UPLOADED"),
),
},
},
Expand Down Expand Up @@ -82,3 +107,81 @@ response:
]
}
`)

var testAccMLBV1CertificateDataSourceQueryDescription = fmt.Sprintf(`
data "ecl_mlb_certificate_v1" "certificate_1" {
description = "description"
}
`)

var testMockMLBV1CertificatesListDescriptionQuery = fmt.Sprintf(`
request:
method: GET
query:
description:
- description
response:
code: 200
body: >
{
"certificates": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "certificate",
"description": "description",
"tags": {
"key": "value"
},
"tenant_id": "34f5c98ef430457ba81292637d0c6fd0",
"ca_cert": {
"status": "NOT_UPLOADED"
},
"ssl_cert": {
"status": "NOT_UPLOADED"
},
"ssl_key": {
"status": "NOT_UPLOADED"
}
}
]
}
`)

var testAccMLBV1CertificateDataSourceQueryTenantID = fmt.Sprintf(`
data "ecl_mlb_certificate_v1" "certificate_1" {
tenant_id = "34f5c98ef430457ba81292637d0c6fd0"
}
`)

var testMockMLBV1CertificatesListTenantIDQuery = fmt.Sprintf(`
request:
method: GET
query:
tenant_id:
- 34f5c98ef430457ba81292637d0c6fd0
response:
code: 200
body: >
{
"certificates": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "certificate",
"description": "description",
"tags": {
"key": "value"
},
"tenant_id": "34f5c98ef430457ba81292637d0c6fd0",
"ca_cert": {
"status": "NOT_UPLOADED"
},
"ssl_cert": {
"status": "NOT_UPLOADED"
},
"ssl_key": {
"status": "NOT_UPLOADED"
}
}
]
}
`)
9 changes: 4 additions & 5 deletions ecl/data_source_ecl_mlb_health_monitor_v1.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*
Generated by https://github.com/tamac-io/openapi-to-terraform-rb
*/
package ecl

import (
Expand Down Expand Up @@ -159,14 +156,16 @@ func dataSourceMLBHealthMonitorV1Read(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error creating ECL managed load balancer client: %s", err)
}

log.Printf("[DEBUG] Retrieving ECL managed load balancer health monitors with options %+v", listOpts)

pages, err := health_monitors.List(managedLoadBalancerClient, listOpts).AllPages()
if err != nil {
return err
}

allHealthMonitors, err := health_monitors.ExtractHealthMonitors(pages)
if err != nil {
return fmt.Errorf("Unable to retrieve health monitors: %s", err)
return fmt.Errorf("Unable to retrieve ECL managed load balancer health monitors with options %+v: %s", listOpts, err)
}

if len(allHealthMonitors) < 1 {
Expand All @@ -181,7 +180,7 @@ func dataSourceMLBHealthMonitorV1Read(d *schema.ResourceData, meta interface{})

healthMonitor := allHealthMonitors[0]

log.Printf("[DEBUG] Retrieved health monitor %s: %+v", d.Id(), healthMonitor)
log.Printf("[DEBUG] Retrieved ECL managed load balancer health monitor: %+v", healthMonitor)

d.SetId(healthMonitor.ID)

Expand Down
Loading
Loading