Skip to content

Commit

Permalink
new datasource: ovh_dedicated_installation_templates
Browse files Browse the repository at this point in the history
  • Loading branch information
yann degat committed Dec 11, 2019
1 parent cb2755a commit 346e4b5
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 151 deletions.
43 changes: 43 additions & 0 deletions ovh/data_source_ovh_dedicated_installation_templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ovh

import (
"fmt"
"sort"

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

func dataSourceDedicatedInstallationTemplates() *schema.Resource {
return &schema.Resource{
Read: dataSourceDedicatedInstallationTemplatesRead,
Schema: map[string]*schema.Schema{
// Computed
"result": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}

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

ids := []string{}
err := config.OVHClient.Get("/dedicated/installationTemplate", &ids)

if err != nil {
return fmt.Errorf("Error calling /dedicated/installationTemplate:\n\t %q", err)
}

// sort.Strings sorts in place, returns nothing
sort.Strings(ids)

d.SetId(hashcode.Strings(ids))
d.Set("result", ids)
return nil
}
23 changes: 23 additions & 0 deletions ovh/data_source_ovh_dedicated_installation_templates_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ovh

import (
"testing"

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

func TestAccDedicatedInstallationTemplatesDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCredentials(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: "data ovh_dedicated_installation_templates templates {}",
Check: resource.TestCheckResourceAttrSet(
"data.ovh_dedicated_installation_templates.templates",
"result.#",
),
},
},
})
}
17 changes: 9 additions & 8 deletions ovh/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ func Provider() terraform.ResourceProvider {
},

DataSourcesMap: map[string]*schema.Resource{
"ovh_cloud_region": dataSourcePublicCloudRegion(),
"ovh_cloud_regions": dataSourcePublicCloudRegions(),
"ovh_domain_zone": dataSourceDomainZone(),
"ovh_iploadbalancing": dataSourceIpLoadbalancing(),
"ovh_me_paymentmean_bankaccount": dataSourceMePaymentmeanBankaccount(),
"ovh_me_paymentmean_creditcard": dataSourceMePaymentmeanCreditcard(),
"ovh_me_ssh_key": dataSourceMeSshKey(),
"ovh_me_ssh_keys": dataSourceMeSshKeys(),
"ovh_cloud_region": dataSourcePublicCloudRegion(),
"ovh_cloud_regions": dataSourcePublicCloudRegions(),
"ovh_dedicated_installation_templates": dataSourceDedicatedInstallationTemplates(),
"ovh_domain_zone": dataSourceDomainZone(),
"ovh_iploadbalancing": dataSourceIpLoadbalancing(),
"ovh_me_paymentmean_bankaccount": dataSourceMePaymentmeanBankaccount(),
"ovh_me_paymentmean_creditcard": dataSourceMePaymentmeanCreditcard(),
"ovh_me_ssh_key": dataSourceMeSshKey(),
"ovh_me_ssh_keys": dataSourceMeSshKeys(),

// Legacy naming schema (publiccloud)
"ovh_publiccloud_region": deprecated(dataSourcePublicCloudRegion(),
Expand Down
27 changes: 27 additions & 0 deletions website/docs/d/dedicated_installation_templates.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
layout: "ovh"
page_title: "OVH: dedicated_installation_templates"
sidebar_current: "docs-ovh-datasource-dedicated-installation-templates"
description: |-
Get the list of installation templates available for dedicated servers.
---

# ovh_dedicated_installation_templates

Use this data source to get the list of installation templates available for dedicated servers.

## Example Usage

```hcl
data "ovh_dedicated_installation_templates" "templates" {}
```

## Argument Reference

This datasource takes no argument.

## Attributes Reference

The following attributes are exported:

* `result` - The list of installation templates IDs available for dedicated servers.
Loading

0 comments on commit 346e4b5

Please sign in to comment.