Skip to content

Commit

Permalink
Update dedicated server (and (me_)_installation_template ) (#639)
Browse files Browse the repository at this point in the history
* remove default_language from data and resource (type too)

* remove ssh_key_name from data, resource and type
deleted data_me_ssh_key*, resource_me_ssh_key* files

* deleted data/resource me_ssh_key(s) docs

* remove available_languages from data, resource and type

* remove available_language and language from docs data/resource  me_installation_template

* remove deprecated stuff
add hard_raid_configuration as deprecated

* add data source dedicated_installation_template
update type installation template

* re-order data schema (dedicated_installation_template &
me_installation_template)
  • Loading branch information
bigbigbang authored May 3, 2024
1 parent 77cd6cd commit d6bf283
Show file tree
Hide file tree
Showing 21 changed files with 631 additions and 747 deletions.
4 changes: 2 additions & 2 deletions .cds/terraform-provider-ovh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,14 @@ workflow:
pipeline: terraform-provider-ovh-testacc
when:
- success
Tests_TestAccDedicatedInstallationTemplates:
Tests_TestAccDedicatedInstallationTemplate:
application: terraform-provider-ovh
depends_on:
- terraform-provider-ovh-pre-sweepers
environment: acctests
one_at_a_time: true
parameters:
testargs: -run TestAccDedicatedInstallationTemplates
testargs: -run TestAccDedicatedInstallationTemplate
pipeline: terraform-provider-ovh-testacc
when:
- success
Expand Down
276 changes: 276 additions & 0 deletions ovh/data_dedicated_installation_template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
package ovh

import (
"fmt"
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/go-ovh/ovh"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)

func dataSourceDedicatedInstallationTemplate() *schema.Resource {
return &schema.Resource{
Read: dataSourceDedicatedInstallationTemplateRead,
Schema: map[string]*schema.Schema{
"template_name": {
Type: schema.TypeString,
Required: true,
Description: "Template name",
},

// Computed properties
"bit_format": {
Type: schema.TypeInt,
Computed: true,
Description: "Template bit format (32 or 64)",
},
"category": {
Type: schema.TypeString,
Computed: true,
Description: "Category of this template (informative only)",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description of the template",
},
"distribution": {
Type: schema.TypeString,
Computed: true,
Description: "Distribution this template is based on",
},
"end_of_install": {
Type: schema.TypeString,
Computed: true,
Description: "After this date, install of this template will not be possible at OVH",
},
"family": {
Type: schema.TypeString,
Computed: true,
Description: "Template family type (bsd,linux,solaris,windows)",
},
"filesystems": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Description: "Filesystems available",
},
"hard_raid_configuration": {
Type: schema.TypeBool,
Computed: true,
Description: "Distribution supports hardware raid configuration through the OVH API",
},
"inputs": {
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"mandatory": {
Type: schema.TypeBool,
Computed: true,
},
"enum": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"default": {
Type: schema.TypeString,
Computed: true,
},
},
},
Computed: true,
},
"license": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"os": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"usage": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
},
},
"lvm_ready": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether this distribution supports Logical Volumes (Linux LVM)",
},
"no_partitioning": {
Type: schema.TypeBool,
Computed: true,
Description: "Template supports RAID0 and RAID1 on 2 disks",
},
"project": {
Type: schema.TypeList,
Computed: true,
Description: "Distribution project details",
Elem: &schema.Resource{
Description: "A structure describing some interesting facts about an OS template project",
Schema: map[string]*schema.Schema{
"usage": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"version": {
Type: schema.TypeString,
Computed: true,
Description: "OS template project item version",
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: "OS template project item url",
},
"release_notes": {
Type: schema.TypeString,
Computed: true,
Description: "OS template project item release notes",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "OS template project item name",
},
"governance": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Description: "OS template project item governance",
},
},
},
},
"os": {
Type: schema.TypeList,
Computed: true,
Description: "OS template project OS details",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"version": {
Type: schema.TypeString,
Computed: true,
Description: "OS template project item version",
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: "OS template project item url",
},
"release_notes": {
Type: schema.TypeString,
Computed: true,
Description: "OS template project item release notes",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "OS template project item name",
},
"governance": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Description: "OS template project item governance",
},
},
},
},
},
},
},
"soft_raid_only_mirroring": {
Type: schema.TypeBool,
Computed: true,
Description: "Partitioning customization is available but limited to mirroring for this OS template",
},
"subfamily": {
Type: schema.TypeString,
Computed: true,
Description: "Template subfamily type",
},
},
}
}

func dataSourceDedicatedInstallationTemplateRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
template, err := getDedicatedInstallationTemplate(d, config.OVHClient)
if err != nil {
return err
}
if template == nil {
return fmt.Errorf("Your query returned no results. Please change your search criteria")
}

// set attributes
for k, v := range template.ToMap() {
d.Set(k, v)
}

name := d.Get("template_name").(string)
d.SetId(name)

return nil
}

func getDedicatedInstallationTemplate(d *schema.ResourceData, client *ovh.Client) (*InstallationTemplate, error) {
r := &InstallationTemplate{}

endpoint := fmt.Sprintf(
"/dedicated/installationTemplate/%s",
url.PathEscape(d.Get("template_name").(string)),
)

if err := client.Get(endpoint, r); err != nil {
return nil, helpers.CheckDeleted(d, err, endpoint)
}

return r, nil
}
42 changes: 42 additions & 0 deletions ovh/data_dedicated_installation_template_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ovh

import (
"regexp"
"testing"

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

func TestAccDedicatedInstallationTemplateDataSource_basic(t *testing.T) {
testAccInstallationTemplateDatasourceConfig_404 := `data "ovh_dedicated_installation_template" "notemplate" {
template_name = "42"
}`
testAccInstallationTemplateDatasourceConfig_Basic := `data "ovh_dedicated_installation_template" "template" {
template_name= "debian12_64"
}`
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCredentials(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccInstallationTemplateDatasourceConfig_Basic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.ovh_dedicated_installation_template.template",
"template_name",
"debian12_64",
),
resource.TestCheckResourceAttr(
"data.ovh_dedicated_installation_template.template",
"family",
"linux",
),
),
},
{
Config: testAccInstallationTemplateDatasourceConfig_404,
ExpectError: regexp.MustCompile("Your query returned no results. Please change your search criteria"),
},
},
})
}
Loading

0 comments on commit d6bf283

Please sign in to comment.