-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new datasource: ovh_dedicated_installation_templates
- Loading branch information
yann degat
committed
Dec 11, 2019
1 parent
cb2755a
commit 346e4b5
Showing
5 changed files
with
252 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
ovh/data_source_ovh_dedicated_installation_templates_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.#", | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
website/docs/d/dedicated_installation_templates.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.