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

fix: correctly set cluster_id field in datasource ovh_dbaas_logs_cluster #694

Merged
merged 1 commit into from
Jul 22, 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
6 changes: 4 additions & 2 deletions ovh/data_dbaas_logs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func dataSourceDbaasLogsCluster() *schema.Resource {
"cluster_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
// Computed
"urn": {
Expand Down Expand Up @@ -137,8 +138,9 @@ func dataSourceDbaasLogsClusterRead(d *schema.ResourceData, meta interface{}) er
var err error
clusterId, err = dbaasGetClusterID(config, serviceName)
if err != nil {
return fmt.Errorf("Error retrieving clusterId for %s:\n\t %q", serviceName, err)
return fmt.Errorf("error retrieving cluster_id for %s:\n\t %q", serviceName, err)
}
d.Set("cluster_id", clusterId)
}

log.Printf("[DEBUG] Will read dbaas logs cluster %s/%s", serviceName, clusterId)
Expand All @@ -155,7 +157,7 @@ func dataSourceDbaasLogsClusterRead(d *schema.ResourceData, meta interface{}) er

res := map[string]interface{}{}
if err := config.OVHClient.Get(endpoint, &res); err != nil {
return fmt.Errorf("Error calling GET %s:\n\t %q", endpoint, err)
return fmt.Errorf("error calling GET %s:\n\t %q", endpoint, err)
}

d.Set("archive_allowed_networks", res["archiveAllowedNetworks"])
Expand Down
54 changes: 45 additions & 9 deletions ovh/data_dbaas_logs_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const testAccDataSourceDbaasLogsCluster = `
data "ovh_dbaas_logs_cluster" "ldp" {
service_name = "%s"
cluster_id = "%s"
}
`

func TestAccDataSourceDbaasLogsCluster(t *testing.T) {
serviceName := os.Getenv("OVH_DBAAS_LOGS_SERVICE_TEST")
clusterId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_ID")

config := fmt.Sprintf(
testAccDataSourceDbaasLogsCluster,
config := fmt.Sprintf(`
data "ovh_dbaas_logs_cluster" "ldp" {
service_name = "%s"
cluster_id = "%s"
}`,
serviceName,
clusterId,
)
Expand All @@ -38,6 +34,46 @@ func TestAccDataSourceDbaasLogsCluster(t *testing.T) {
"service_name",
serviceName,
),
resource.TestCheckResourceAttr(
"data.ovh_dbaas_logs_cluster.ldp",
"cluster_id",
clusterId,
),
),
},
},
})
}

func TestAccDataSourceDbaasLogsClusterDefault(t *testing.T) {
serviceName := os.Getenv("OVH_DBAAS_LOGS_SERVICE_TEST")
clusterId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_ID")

config := fmt.Sprintf(`
data "ovh_dbaas_logs_cluster" "ldp" {
service_name = "%s"
}`,
serviceName,
)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckDbaasLogsCluster(t) },

Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.ovh_dbaas_logs_cluster.ldp",
"service_name",
serviceName,
),
resource.TestCheckResourceAttr(
"data.ovh_dbaas_logs_cluster.ldp",
"cluster_id",
clusterId,
),
),
},
},
Expand Down