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

Add resource and data for ovh_dbaas_logs #364

Merged
merged 1 commit into from
Feb 22, 2023
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
141 changes: 141 additions & 0 deletions ovh/data_dbaas_logs_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package ovh

import (
"fmt"
"log"
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceDbaasLogsCluster() *schema.Resource {
return &schema.Resource{
Read: func(d *schema.ResourceData, meta interface{}) error {
return dataSourceDbaasLogsClusterRead(d, meta)
},
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Description: "The service name",
Required: true,
},
// Computed
"cluster_type": {
Type: schema.TypeString,
Description: "Cluster type",
Computed: true,
},
"dedicated_input_pem": {
Type: schema.TypeString,
Description: "PEM for dedicated inputs",
Computed: true,
Sensitive: true,
},
"archive_allowed_networks": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Allowed networks for ARCHIVE flow type",
Computed: true,
},
"direct_input_allowed_networks": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Allowed networks for DIRECT_INPUT flow type",
Computed: true,
},
"direct_input_pem": {
Type: schema.TypeString,
Description: "PEM for direct inputs",
Computed: true,
Sensitive: true,
},
"hostname": {
Type: schema.TypeString,
Description: "hostname",
Computed: true,
},
"is_default": {
Type: schema.TypeBool,
Description: "All content generated by given service will be placed on this cluster",
Computed: true,
},
"is_unlocked": {
Type: schema.TypeBool,
Description: "Allow given service to perform advanced operations on cluster",
Computed: true,
},
"query_allowed_networks": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Allowed networks for QUERY flow type",
Computed: true,
},
"region": {
Type: schema.TypeString,
Description: "Data center localization",
Computed: true,
},
},
}
}

func dbaasGetClusterID(config *Config, serviceName string) (string, error) {
res := []string{}

endpoint := fmt.Sprintf(
"/dbaas/logs/%s/cluster",
url.PathEscape(serviceName),
)

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

return res[0], nil
}

func dataSourceDbaasLogsClusterRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

serviceName := d.Get("service_name").(string)

log.Printf("[DEBUG] Will read dbaas logs cluster %s", serviceName)

cluster_id, err := dbaasGetClusterID(config, serviceName)

if err != nil {
return fmt.Errorf("Error fetching info for %s:\n\t %q", serviceName, err)
}

d.SetId(cluster_id)

endpoint := fmt.Sprintf(
"/dbaas/logs/%s/cluster/%s",
url.PathEscape(serviceName),
url.PathEscape(cluster_id),
)

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)
}

d.Set("archive_allowed_networks", res["archiveAllowedNetworks"])
d.Set("cluster_type", res["clusterType"])
d.Set("dedicated_input_pem", res["dedicatedInputPEM"])
d.Set("direct_input_allowed_networks", res["directInputAllowedNetworks"])
d.Set("direct_input_pem", res["directInputPEM"])
d.Set("hostname", res["hostname"])
d.Set("is_default", res["isDefault"])
d.Set("is_unlocked", res["isUnlocked"])
d.Set("query_allowed_networks", res["queryAllowedNetworks"])
d.Set("region", res["region"])

return nil
}
42 changes: 42 additions & 0 deletions ovh/data_dbaas_logs_cluster_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ovh

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

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

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

config := fmt.Sprintf(
testAccDataSourceDbaasLogsCluster,
serviceName,
)

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

Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.ovh_dbaas_logs_cluster.ldp",
"service_name",
serviceName,
),
),
},
},
})
}
2 changes: 2 additions & 0 deletions ovh/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func Provider() *schema.Provider {
"ovh_cloud_project_user_s3_credentials": dataCloudProjectUserS3Credentials(),
"ovh_cloud_project_user_s3_policy": dataCloudProjectUserS3Policy(),
"ovh_cloud_project_users": datasourceCloudProjectUsers(),
"ovh_dbaas_logs_cluster": dataSourceDbaasLogsCluster(),
"ovh_dbaas_logs_input_engine": dataSourceDbaasLogsInputEngine(),
"ovh_dbaas_logs_output_graylog_stream": dataSourceDbaasLogsOutputGraylogStream(),
"ovh_dedicated_ceph": dataSourceDedicatedCeph(),
Expand Down Expand Up @@ -160,6 +161,7 @@ func Provider() *schema.Provider {
"ovh_cloud_project_user_s3_credential": resourceCloudProjectUserS3Credential(),
"ovh_cloud_project_user_s3_policy": resourceCloudProjectUserS3Policy(),
"ovh_cloud_project_workflow_backup": resourceCloudProjectWorkflowBackup(),
"ovh_dbaas_logs_cluster": resourceDbaasLogsCluster(),
"ovh_dbaas_logs_input": resourceDbaasLogsInput(),
"ovh_dbaas_logs_output_graylog_stream": resourceDbaasLogsOutputGraylogStream(),
"ovh_dedicated_ceph_acl": resourceDedicatedCephACL(),
Expand Down
2 changes: 1 addition & 1 deletion ovh/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func testAccPreCheckHostingPrivateDatabaseWhitelist(t *testing.T) {
checkEnvOrSkip(t, "OVH_HOSTING_PRIVATEDATABASE_WHITELIST_SFTP_TEST")
}

// Checks that the environment variables needed for the /cloud acceptance tests
// Checks that the environment variables needed for the /dbaas acceptance tests
// are set.
func testAccPreCheckDbaasLogs(t *testing.T) {
testAccPreCheckCredentials(t)
Expand Down
Loading