Skip to content

Commit e1a1561

Browse files
authored
Merge pull request #313 from lpatte/PUD-1399-1400_m3db-lifecycle_PUD-1651/90-database
M3DB user and Namespace + Database + capabilities data
2 parents 7480742 + 9210645 commit e1a1561

File tree

53 files changed

+3495
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3495
-41
lines changed

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/mitchellh/go-homedir v1.1.0
99
github.com/ovh/go-ovh v1.1.0
1010
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
11+
github.com/ybriffa/rfc3339 v0.0.0-20220203155318-1789e3fd6e70
1112
golang.org/x/tools v0.0.0-20201118030313-598b068a9102 // indirect
1213
gopkg.in/ini.v1 v1.57.0
1314
)

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+
310310
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
311311
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
312312
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
313+
github.com/ybriffa/rfc3339 v0.0.0-20220203155318-1789e3fd6e70 h1:eLNDtF6iVvMgWzQsxJrX+BQhuFgBZ9yeUWfVK0veHcs=
314+
github.com/ybriffa/rfc3339 v0.0.0-20220203155318-1789e3fd6e70/go.mod h1:zm6iUC+TqI9sIhE8TLV2vAbi/cUzFYvBPZqfDVl6u7k=
313315
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
314316
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
315317
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

Diff for: ovh/data_cloud_project_database.go

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
9898
Description: "The node flavor used for this cluster",
9999
Computed: true,
100100
},
101+
"kafka_rest_api": {
102+
Type: schema.TypeBool,
103+
Description: "Defines whether the REST API is enabled on a Kafka cluster",
104+
Computed: true,
105+
},
101106
"maintenance_time": {
102107
Type: schema.TypeString,
103108
Description: "Time on which maintenances can start every day",
@@ -132,6 +137,11 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
132137
},
133138
},
134139
},
140+
"opensearch_acls_enabled": {
141+
Type: schema.TypeBool,
142+
Description: "Defines whether the ACLs are enabled on an Opensearch cluster",
143+
Computed: true,
144+
},
135145
"plan": {
136146
Type: schema.TypeString,
137147
Description: "Plan of the cluster",

Diff for: ovh/data_cloud_project_database_capabilities.go

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package ovh
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net/url"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
10+
)
11+
12+
func dataSourceCloudProjectDatabaseCapabilities() *schema.Resource {
13+
return &schema.Resource{
14+
Read: dataSourceCloudProjectDatabaseCapabilitiesRead,
15+
Schema: map[string]*schema.Schema{
16+
"service_name": {
17+
Type: schema.TypeString,
18+
Required: true,
19+
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil),
20+
},
21+
22+
// Computed
23+
"engines": {
24+
Type: schema.TypeSet,
25+
Description: "Database engines available",
26+
Computed: true,
27+
Elem: &schema.Resource{
28+
Schema: map[string]*schema.Schema{
29+
"default_version": {
30+
Type: schema.TypeString,
31+
Description: "Default version used for the engine",
32+
Computed: true,
33+
},
34+
"description": {
35+
Type: schema.TypeString,
36+
Description: "Description of the engine",
37+
Computed: true,
38+
},
39+
"name": {
40+
Type: schema.TypeString,
41+
Description: "Engine name",
42+
Computed: true,
43+
},
44+
"ssl_modes": {
45+
Type: schema.TypeSet,
46+
Description: "SSL modes for this engine",
47+
Computed: true,
48+
Elem: &schema.Schema{Type: schema.TypeString},
49+
},
50+
"versions": {
51+
Type: schema.TypeSet,
52+
Description: "Versions available for this engine",
53+
Computed: true,
54+
Elem: &schema.Schema{Type: schema.TypeString},
55+
},
56+
},
57+
},
58+
},
59+
"flavors": {
60+
Type: schema.TypeSet,
61+
Description: "Flavors available",
62+
Computed: true,
63+
Elem: &schema.Resource{
64+
Schema: map[string]*schema.Schema{
65+
"core": {
66+
Type: schema.TypeInt,
67+
Description: "Flavor core number",
68+
Computed: true,
69+
},
70+
"memory": {
71+
Type: schema.TypeInt,
72+
Description: "Flavor ram size in GB",
73+
Computed: true,
74+
},
75+
"name": {
76+
Type: schema.TypeString,
77+
Description: "Name of the flavor",
78+
Computed: true,
79+
},
80+
"storage": {
81+
Type: schema.TypeInt,
82+
Description: "Flavor disk size in GB",
83+
Computed: true,
84+
},
85+
},
86+
},
87+
},
88+
"options": {
89+
Type: schema.TypeSet,
90+
Description: "Options available",
91+
Computed: true,
92+
Elem: &schema.Resource{
93+
Schema: map[string]*schema.Schema{
94+
"name": {
95+
Type: schema.TypeString,
96+
Description: "Name of the option",
97+
Computed: true,
98+
},
99+
"type": {
100+
Type: schema.TypeString,
101+
Description: "Type of the option",
102+
Computed: true,
103+
},
104+
},
105+
},
106+
},
107+
"plans": {
108+
Type: schema.TypeSet,
109+
Description: "Plans available",
110+
Computed: true,
111+
Elem: &schema.Resource{
112+
Schema: map[string]*schema.Schema{
113+
"backup_retention": {
114+
Type: schema.TypeString,
115+
Description: "Automatic backup retention duration",
116+
Computed: true,
117+
},
118+
"description": {
119+
Type: schema.TypeString,
120+
Description: "Description of the plan",
121+
Computed: true,
122+
},
123+
"name": {
124+
Type: schema.TypeString,
125+
Description: "Name of the plan",
126+
Computed: true,
127+
},
128+
},
129+
},
130+
},
131+
},
132+
}
133+
}
134+
135+
func dataSourceCloudProjectDatabaseCapabilitiesRead(d *schema.ResourceData, meta interface{}) error {
136+
config := meta.(*Config)
137+
serviceName := d.Get("service_name").(string)
138+
139+
capabilitiesEndpoint := fmt.Sprintf("/cloud/project/%s/database/capabilities",
140+
url.PathEscape(serviceName),
141+
)
142+
capabilitiesRes := &CloudProjectDatabaseCapabilitiesResponse{}
143+
144+
log.Printf("[DEBUG] Will read capabilities from project %s", serviceName)
145+
if err := config.OVHClient.Get(capabilitiesEndpoint, capabilitiesRes); err != nil {
146+
return helpers.CheckDeleted(d, err, capabilitiesEndpoint)
147+
}
148+
149+
d.SetId(serviceName)
150+
for k, v := range capabilitiesRes.ToMap() {
151+
d.Set(k, v)
152+
}
153+
154+
log.Printf("[DEBUG] Read capabilities %+v", capabilitiesRes)
155+
return nil
156+
}

Diff for: ovh/data_cloud_project_database_capabilities_test.go

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package ovh
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
)
10+
11+
const testAccCloudProjectDatabaseCapabilitiesDatasourceConfig_Basic = `
12+
data "ovh_cloud_project_database_capabilities" "capabilities" {
13+
service_name = "%s"
14+
}
15+
`
16+
17+
func TestAccCloudProjectDatabaseCapabilitiesDataSource_basic(t *testing.T) {
18+
serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST")
19+
20+
config := fmt.Sprintf(
21+
testAccCloudProjectDatabaseCapabilitiesDatasourceConfig_Basic,
22+
serviceName,
23+
)
24+
25+
resource.Test(t, resource.TestCase{
26+
PreCheck: func() { testAccPreCheckCloud(t) },
27+
Providers: testAccProviders,
28+
Steps: []resource.TestStep{
29+
{
30+
Config: config,
31+
Check: resource.ComposeTestCheckFunc(
32+
resource.TestCheckResourceAttrSet(
33+
"data.ovh_cloud_project_database_capabilities.capabilities",
34+
"engines.#",
35+
),
36+
resource.TestCheckResourceAttrSet(
37+
"data.ovh_cloud_project_database_capabilities.capabilities",
38+
"engines.0.default_version",
39+
),
40+
resource.TestCheckResourceAttrSet(
41+
"data.ovh_cloud_project_database_capabilities.capabilities",
42+
"engines.0.description",
43+
),
44+
resource.TestCheckResourceAttrSet(
45+
"data.ovh_cloud_project_database_capabilities.capabilities",
46+
"engines.0.name",
47+
),
48+
resource.TestCheckResourceAttrSet(
49+
"data.ovh_cloud_project_database_capabilities.capabilities",
50+
"engines.0.ssl_modes.#",
51+
),
52+
resource.TestCheckResourceAttrSet(
53+
"data.ovh_cloud_project_database_capabilities.capabilities",
54+
"engines.0.versions.#",
55+
),
56+
resource.TestCheckResourceAttrSet(
57+
"data.ovh_cloud_project_database_capabilities.capabilities",
58+
"flavors.#",
59+
),
60+
resource.TestCheckResourceAttrSet(
61+
"data.ovh_cloud_project_database_capabilities.capabilities",
62+
"flavors.0.core",
63+
),
64+
resource.TestCheckResourceAttrSet(
65+
"data.ovh_cloud_project_database_capabilities.capabilities",
66+
"flavors.0.memory",
67+
),
68+
resource.TestCheckResourceAttrSet(
69+
"data.ovh_cloud_project_database_capabilities.capabilities",
70+
"flavors.0.name",
71+
),
72+
resource.TestCheckResourceAttrSet(
73+
"data.ovh_cloud_project_database_capabilities.capabilities",
74+
"flavors.0.storage",
75+
),
76+
resource.TestCheckResourceAttrSet(
77+
"data.ovh_cloud_project_database_capabilities.capabilities",
78+
"options.#",
79+
),
80+
resource.TestCheckResourceAttrSet(
81+
"data.ovh_cloud_project_database_capabilities.capabilities",
82+
"options.0.name",
83+
),
84+
resource.TestCheckResourceAttrSet(
85+
"data.ovh_cloud_project_database_capabilities.capabilities",
86+
"options.0.type",
87+
),
88+
resource.TestCheckResourceAttrSet(
89+
"data.ovh_cloud_project_database_capabilities.capabilities",
90+
"plans.#",
91+
),
92+
resource.TestCheckResourceAttrSet(
93+
"data.ovh_cloud_project_database_capabilities.capabilities",
94+
"plans.0.backup_retention",
95+
),
96+
resource.TestCheckResourceAttrSet(
97+
"data.ovh_cloud_project_database_capabilities.capabilities",
98+
"plans.0.description",
99+
),
100+
resource.TestCheckResourceAttrSet(
101+
"data.ovh_cloud_project_database_capabilities.capabilities",
102+
"plans.0.name",
103+
),
104+
),
105+
},
106+
},
107+
})
108+
}

0 commit comments

Comments
 (0)