From 346e4b5b6b730aade377704aa90f5405092a229e Mon Sep 17 00:00:00 2001 From: yann degat Date: Fri, 15 Nov 2019 09:28:48 +0000 Subject: [PATCH] new datasource: ovh_dedicated_installation_templates --- ...ce_ovh_dedicated_installation_templates.go | 43 +++ ...h_dedicated_installation_templates_test.go | 23 ++ ovh/provider.go | 17 +- ...cated_installation_templates.html.markdown | 27 ++ website/ovh.erb | 293 +++++++++--------- 5 files changed, 252 insertions(+), 151 deletions(-) create mode 100644 ovh/data_source_ovh_dedicated_installation_templates.go create mode 100644 ovh/data_source_ovh_dedicated_installation_templates_test.go create mode 100644 website/docs/d/dedicated_installation_templates.html.markdown diff --git a/ovh/data_source_ovh_dedicated_installation_templates.go b/ovh/data_source_ovh_dedicated_installation_templates.go new file mode 100644 index 000000000..573ddf575 --- /dev/null +++ b/ovh/data_source_ovh_dedicated_installation_templates.go @@ -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 +} diff --git a/ovh/data_source_ovh_dedicated_installation_templates_test.go b/ovh/data_source_ovh_dedicated_installation_templates_test.go new file mode 100644 index 000000000..24580c89d --- /dev/null +++ b/ovh/data_source_ovh_dedicated_installation_templates_test.go @@ -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.#", + ), + }, + }, + }) +} diff --git a/ovh/provider.go b/ovh/provider.go index 647f493b2..4abefa97d 100644 --- a/ovh/provider.go +++ b/ovh/provider.go @@ -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(), diff --git a/website/docs/d/dedicated_installation_templates.html.markdown b/website/docs/d/dedicated_installation_templates.html.markdown new file mode 100644 index 000000000..e46d5d8fd --- /dev/null +++ b/website/docs/d/dedicated_installation_templates.html.markdown @@ -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. diff --git a/website/ovh.erb b/website/ovh.erb index a1c607ed0..9729e83d2 100644 --- a/website/ovh.erb +++ b/website/ovh.erb @@ -1,155 +1,162 @@ -<% wrap_layout :inner do %> - <% content_for :sidebar do %> - +<% end %> - <%= yield %> - <% end %> +<%= yield %> +<% end %>