Skip to content

M3DB user and Namespace + Database + capabilities data #313

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
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/ovh/go-ovh v1.1.0
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
github.com/ybriffa/rfc3339 v0.0.0-20220203155318-1789e3fd6e70
golang.org/x/tools v0.0.0-20201118030313-598b068a9102 // indirect
gopkg.in/ini.v1 v1.57.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
github.com/ybriffa/rfc3339 v0.0.0-20220203155318-1789e3fd6e70 h1:eLNDtF6iVvMgWzQsxJrX+BQhuFgBZ9yeUWfVK0veHcs=
github.com/ybriffa/rfc3339 v0.0.0-20220203155318-1789e3fd6e70/go.mod h1:zm6iUC+TqI9sIhE8TLV2vAbi/cUzFYvBPZqfDVl6u7k=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
10 changes: 10 additions & 0 deletions ovh/data_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
Description: "The node flavor used for this cluster",
Computed: true,
},
"kafka_rest_api": {
Type: schema.TypeBool,
Description: "Defines whether the REST API is enabled on a Kafka cluster",
Computed: true,
},
"maintenance_time": {
Type: schema.TypeString,
Description: "Time on which maintenances can start every day",
Expand Down Expand Up @@ -132,6 +137,11 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
},
},
},
"opensearch_acls_enabled": {
Type: schema.TypeBool,
Description: "Defines whether the ACLs are enabled on an Opensearch cluster",
Computed: true,
},
"plan": {
Type: schema.TypeString,
Description: "Plan of the cluster",
Expand Down
156 changes: 156 additions & 0 deletions ovh/data_cloud_project_database_capabilities.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package ovh

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

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

func dataSourceCloudProjectDatabaseCapabilities() *schema.Resource {
return &schema.Resource{
Read: dataSourceCloudProjectDatabaseCapabilitiesRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil),
},

// Computed
"engines": {
Type: schema.TypeSet,
Description: "Database engines available",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default_version": {
Type: schema.TypeString,
Description: "Default version used for the engine",
Computed: true,
},
"description": {
Type: schema.TypeString,
Description: "Description of the engine",
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "Engine name",
Computed: true,
},
"ssl_modes": {
Type: schema.TypeSet,
Description: "SSL modes for this engine",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"versions": {
Type: schema.TypeSet,
Description: "Versions available for this engine",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"flavors": {
Type: schema.TypeSet,
Description: "Flavors available",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"core": {
Type: schema.TypeInt,
Description: "Flavor core number",
Computed: true,
},
"memory": {
Type: schema.TypeInt,
Description: "Flavor ram size in GB",
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "Name of the flavor",
Computed: true,
},
"storage": {
Type: schema.TypeInt,
Description: "Flavor disk size in GB",
Computed: true,
},
},
},
},
"options": {
Type: schema.TypeSet,
Description: "Options available",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "Name of the option",
Computed: true,
},
"type": {
Type: schema.TypeString,
Description: "Type of the option",
Computed: true,
},
},
},
},
"plans": {
Type: schema.TypeSet,
Description: "Plans available",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"backup_retention": {
Type: schema.TypeString,
Description: "Automatic backup retention duration",
Computed: true,
},
"description": {
Type: schema.TypeString,
Description: "Description of the plan",
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "Name of the plan",
Computed: true,
},
},
},
},
},
}
}

func dataSourceCloudProjectDatabaseCapabilitiesRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)

capabilitiesEndpoint := fmt.Sprintf("/cloud/project/%s/database/capabilities",
url.PathEscape(serviceName),
)
capabilitiesRes := &CloudProjectDatabaseCapabilitiesResponse{}

log.Printf("[DEBUG] Will read capabilities from project %s", serviceName)
if err := config.OVHClient.Get(capabilitiesEndpoint, capabilitiesRes); err != nil {
return helpers.CheckDeleted(d, err, capabilitiesEndpoint)
}

d.SetId(serviceName)
for k, v := range capabilitiesRes.ToMap() {
d.Set(k, v)
}

log.Printf("[DEBUG] Read capabilities %+v", capabilitiesRes)
return nil
}
108 changes: 108 additions & 0 deletions ovh/data_cloud_project_database_capabilities_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package ovh

import (
"fmt"
"os"
"testing"

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

const testAccCloudProjectDatabaseCapabilitiesDatasourceConfig_Basic = `
data "ovh_cloud_project_database_capabilities" "capabilities" {
service_name = "%s"
}
`

func TestAccCloudProjectDatabaseCapabilitiesDataSource_basic(t *testing.T) {
serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST")

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCloud(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"engines.#",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"engines.0.default_version",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"engines.0.description",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"engines.0.name",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"engines.0.ssl_modes.#",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"engines.0.versions.#",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"flavors.#",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"flavors.0.core",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"flavors.0.memory",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"flavors.0.name",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"flavors.0.storage",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"options.#",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"options.0.name",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"options.0.type",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"plans.#",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"plans.0.backup_retention",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"plans.0.description",
),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database_capabilities.capabilities",
"plans.0.name",
),
),
},
},
})
}
Loading