Skip to content

Commit a8763b7

Browse files
authored
Merge pull request #101 from yanndegat/dev/ovh_dedicated_installation_template
new datasource: ovh_dedicated_installation_templates
2 parents cb2755a + 346e4b5 commit a8763b7

5 files changed

+252
-151
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package ovh
2+
3+
import (
4+
"fmt"
5+
"sort"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
8+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
9+
)
10+
11+
func dataSourceDedicatedInstallationTemplates() *schema.Resource {
12+
return &schema.Resource{
13+
Read: dataSourceDedicatedInstallationTemplatesRead,
14+
Schema: map[string]*schema.Schema{
15+
// Computed
16+
"result": {
17+
Type: schema.TypeList,
18+
Computed: true,
19+
Elem: &schema.Schema{
20+
Type: schema.TypeString,
21+
},
22+
},
23+
},
24+
}
25+
}
26+
27+
func dataSourceDedicatedInstallationTemplatesRead(d *schema.ResourceData, meta interface{}) error {
28+
config := meta.(*Config)
29+
30+
ids := []string{}
31+
err := config.OVHClient.Get("/dedicated/installationTemplate", &ids)
32+
33+
if err != nil {
34+
return fmt.Errorf("Error calling /dedicated/installationTemplate:\n\t %q", err)
35+
}
36+
37+
// sort.Strings sorts in place, returns nothing
38+
sort.Strings(ids)
39+
40+
d.SetId(hashcode.Strings(ids))
41+
d.Set("result", ids)
42+
return nil
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ovh
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccDedicatedInstallationTemplatesDataSource_basic(t *testing.T) {
10+
resource.Test(t, resource.TestCase{
11+
PreCheck: func() { testAccPreCheckCredentials(t) },
12+
Providers: testAccProviders,
13+
Steps: []resource.TestStep{
14+
{
15+
Config: "data ovh_dedicated_installation_templates templates {}",
16+
Check: resource.TestCheckResourceAttrSet(
17+
"data.ovh_dedicated_installation_templates.templates",
18+
"result.#",
19+
),
20+
},
21+
},
22+
})
23+
}

ovh/provider.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ func Provider() terraform.ResourceProvider {
4141
},
4242

4343
DataSourcesMap: map[string]*schema.Resource{
44-
"ovh_cloud_region": dataSourcePublicCloudRegion(),
45-
"ovh_cloud_regions": dataSourcePublicCloudRegions(),
46-
"ovh_domain_zone": dataSourceDomainZone(),
47-
"ovh_iploadbalancing": dataSourceIpLoadbalancing(),
48-
"ovh_me_paymentmean_bankaccount": dataSourceMePaymentmeanBankaccount(),
49-
"ovh_me_paymentmean_creditcard": dataSourceMePaymentmeanCreditcard(),
50-
"ovh_me_ssh_key": dataSourceMeSshKey(),
51-
"ovh_me_ssh_keys": dataSourceMeSshKeys(),
44+
"ovh_cloud_region": dataSourcePublicCloudRegion(),
45+
"ovh_cloud_regions": dataSourcePublicCloudRegions(),
46+
"ovh_dedicated_installation_templates": dataSourceDedicatedInstallationTemplates(),
47+
"ovh_domain_zone": dataSourceDomainZone(),
48+
"ovh_iploadbalancing": dataSourceIpLoadbalancing(),
49+
"ovh_me_paymentmean_bankaccount": dataSourceMePaymentmeanBankaccount(),
50+
"ovh_me_paymentmean_creditcard": dataSourceMePaymentmeanCreditcard(),
51+
"ovh_me_ssh_key": dataSourceMeSshKey(),
52+
"ovh_me_ssh_keys": dataSourceMeSshKeys(),
5253

5354
// Legacy naming schema (publiccloud)
5455
"ovh_publiccloud_region": deprecated(dataSourcePublicCloudRegion(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
layout: "ovh"
3+
page_title: "OVH: dedicated_installation_templates"
4+
sidebar_current: "docs-ovh-datasource-dedicated-installation-templates"
5+
description: |-
6+
Get the list of installation templates available for dedicated servers.
7+
---
8+
9+
# ovh_dedicated_installation_templates
10+
11+
Use this data source to get the list of installation templates available for dedicated servers.
12+
13+
## Example Usage
14+
15+
```hcl
16+
data "ovh_dedicated_installation_templates" "templates" {}
17+
```
18+
19+
## Argument Reference
20+
21+
This datasource takes no argument.
22+
23+
## Attributes Reference
24+
25+
The following attributes are exported:
26+
27+
* `result` - The list of installation templates IDs available for dedicated servers.

0 commit comments

Comments
 (0)