From 445740c98af72e8e5de5920c6fd682788d738090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20B=C3=A9rot-Armand?= Date: Fri, 25 Nov 2022 09:26:50 +0000 Subject: [PATCH] Reduce vm --- outscale/data_source_outscale_vm.go | 437 +--------- outscale/data_source_outscale_vms.go | 21 +- outscale/data_source_outscale_vms_test.go | 2 +- outscale/resource_outscale_vm.go | 919 +++++++++++----------- 4 files changed, 462 insertions(+), 917 deletions(-) diff --git a/outscale/data_source_outscale_vm.go b/outscale/data_source_outscale_vm.go index 31bda10ca..04a54494e 100644 --- a/outscale/data_source_outscale_vm.go +++ b/outscale/data_source_outscale_vm.go @@ -17,7 +17,7 @@ import ( func dataSourceOutscaleOAPIVM() *schema.Resource { return &schema.Resource{ Read: dataSourceOutscaleOAPIVMRead, - Schema: getDataSourceOAPIVMSchemas(), + Schema: GetDataSourceSchema(VMSchema()), } } func dataSourceOutscaleOAPIVMRead(d *schema.ResourceData, meta interface{}) error { @@ -229,25 +229,6 @@ func getOAPIVMSecurityGroups(groupSet []oscgo.SecurityGroupLight) []map[string]i return res } -func getDataSourceOAPIVMSchemas() map[string]*schema.Schema { - wholeSchema := map[string]*schema.Schema{ - "filter": dataSourceFiltersSchema(), - } - - attrsSchema := getOApiVMAttributesSchema() - - for k, v := range attrsSchema { - wholeSchema[k] = v - } - - wholeSchema["request_id"] = &schema.Schema{ - Type: schema.TypeString, - Computed: true, - } - - return wholeSchema -} - func buildOutscaleOAPIDataSourceVMFilters(set *schema.Set) *oscgo.FiltersVm { filters := new(oscgo.FiltersVm) @@ -273,419 +254,3 @@ func buildOutscaleOAPIDataSourceVMFilters(set *schema.Set) *oscgo.FiltersVm { } return filters } - -func getOApiVMAttributesSchema() map[string]*schema.Schema { - return map[string]*schema.Schema{ - // Attributes - "architecture": { - Type: schema.TypeString, - Computed: true, - }, - "block_device_mappings_created": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "bsu": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "delete_on_vm_deletion": { - Type: schema.TypeBool, - Computed: true, - }, - "link_date": { - Type: schema.TypeString, - Computed: true, - }, - "state": { - Type: schema.TypeInt, - Computed: true, - }, - "volume_id": { - Type: schema.TypeFloat, - Computed: true, - }, - }, - }, - }, - "device_name": { - Type: schema.TypeString, - Optional: true, - }, - }, - }, - }, - "bsu_optimized": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - "client_token": { - Type: schema.TypeString, - Computed: true, - }, - "creation_date": { - Type: schema.TypeString, - Computed: true, - }, - "deletion_protection": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - "hypervisor": { - Type: schema.TypeString, - Computed: true, - }, - "image_id": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Computed: true, - }, - "is_source_dest_checked": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - "keypair_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "security_group_ids": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "security_group_names": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "launch_number": { - Type: schema.TypeInt, - Computed: true, - }, - "nested_virtualization": { - Type: schema.TypeBool, - Computed: true, - }, - "net_id": { - Type: schema.TypeString, - Computed: true, - }, - "nics": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "delete_on_vm_deletion": { - Type: schema.TypeBool, - Computed: true, - Optional: true, - }, - "description": { - Type: schema.TypeString, - Computed: true, - Optional: true, - }, - "device_number": { - Type: schema.TypeInt, - Computed: true, - Optional: true, - }, - "nic_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "private_ips": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "is_primary": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - "link_public_ip": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "public_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip_account_id": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "private_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "private_ip": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - }, - }, - }, - "secondary_private_ip_count": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - }, - "security_group_ids": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "account_id": { - Type: schema.TypeString, - Computed: true, - }, - - "is_source_dest_checked": { - Type: schema.TypeBool, - Computed: true, - }, - - "subnet_id": { - Type: schema.TypeString, - Computed: true, - Optional: true, - }, - "link_nic": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "delete_on_vm_deletion": { - Type: schema.TypeBool, - Computed: true, - }, - "device_number": { - Type: schema.TypeString, - Computed: true, - }, - "link_nic_id": { - Type: schema.TypeString, - Computed: true, - }, - "state": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "link_public_ip": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "public_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip_account_id": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "mac_address": { - Type: schema.TypeString, - Computed: true, - }, - "net_id": { - Type: schema.TypeString, - Computed: true, - }, - - "private_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "security_groups_names": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "security_groups": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "security_group_id": { - Type: schema.TypeString, - Computed: true, - }, - "security_group_name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "state": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "os_family": { - Type: schema.TypeString, - Computed: true, - }, - "performance": { - Type: schema.TypeString, - Computed: true, - }, - "placement_subregion_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "placement_tenancy": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "private_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "private_ip": { - Type: schema.TypeString, - Computed: true, - }, - "product_codes": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "public_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip": { - Type: schema.TypeString, - Computed: true, - }, - "reservation_id": { - Type: schema.TypeString, - Computed: true, - }, - "root_device_name": { - Type: schema.TypeString, - Computed: true, - }, - "root_device_type": { - Type: schema.TypeString, - Computed: true, - }, - "security_groups": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "security_group_id": { - Type: schema.TypeString, - Computed: true, - }, - "security_group_name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "state": { - Type: schema.TypeString, - Computed: true, - }, - "state_reason": { - Type: schema.TypeString, - Computed: true, - }, - "subnet_id": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Computed: true, - }, - "tags": { - Type: schema.TypeList, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "key": { - Type: schema.TypeString, - Computed: true, - }, - "value": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - Computed: true, - }, - "user_data": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "vm_id": { - Type: schema.TypeString, - Computed: true, - Optional: true, - }, - "vm_initiated_shutdown_behavior": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "vm_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "request_id": { - Type: schema.TypeString, - Computed: true, - }, - "private_ips": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - } -} diff --git a/outscale/data_source_outscale_vms.go b/outscale/data_source_outscale_vms.go index 1103704fa..7e3bc50bf 100644 --- a/outscale/data_source_outscale_vms.go +++ b/outscale/data_source_outscale_vms.go @@ -17,29 +17,10 @@ func datasourceOutscaleOApiVMS() *schema.Resource { return &schema.Resource{ Read: dataSourceOutscaleOApiVMSRead, - Schema: datasourceOutscaleOApiVMSSchema(), + Schema: GetDataSourcesSchema("vms", VMSchema()), } } -func datasourceOutscaleOApiVMSSchema() map[string]*schema.Schema { - wholeSchema := map[string]*schema.Schema{ - "filter": dataSourceFiltersSchema(), - "vms": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: getOApiVMAttributesSchema(), - }, - }, - "request_id": { - Type: schema.TypeString, - Computed: true, - }, - } - - return wholeSchema -} - func dataSourceOutscaleOApiVMSRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*OutscaleClient).OSCAPI diff --git a/outscale/data_source_outscale_vms_test.go b/outscale/data_source_outscale_vms_test.go index 821808c34..662f30638 100644 --- a/outscale/data_source_outscale_vms_test.go +++ b/outscale/data_source_outscale_vms_test.go @@ -34,7 +34,7 @@ func testAccOAPIVMSDataSourceConfig(omi, vmType string) string { resource "outscale_vm" "basic" { image_id = "%s" vm_type = "%s" - keypair_name = "terraform-basic" + #keypair_name = "terraform-basic" } data "outscale_vms" "basic_web" { diff --git a/outscale/resource_outscale_vm.go b/outscale/resource_outscale_vm.go index 1215f36b4..92089e028 100644 --- a/outscale/resource_outscale_vm.go +++ b/outscale/resource_outscale_vm.go @@ -18,507 +18,506 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOApiVM() *schema.Resource { - return &schema.Resource{ - Create: resourceOAPIVMCreate, - Read: resourceOAPIVMRead, - Update: resourceOAPIVMUpdate, - Delete: resourceOAPIVMDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(10 * time.Minute), - Update: schema.DefaultTimeout(10 * time.Minute), - Delete: schema.DefaultTimeout(10 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "block_device_mappings": { - Type: schema.TypeList, - Optional: true, - //ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "bsu": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "delete_on_vm_deletion": { - Type: schema.TypeBool, - Optional: true, - }, - "iops": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { - iopsVal := val.(int) - if iopsVal < utils.MinIops || iopsVal > utils.MaxIops { - errs = append(errs, fmt.Errorf("%q must be between %d and %d inclusive, got: %d", key, utils.MinIops, utils.MaxIops, iopsVal)) - } - return - }, - }, - "snapshot_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "volume_size": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { - vSize := val.(int) - if vSize < 1 || vSize > utils.MaxSize { - errs = append(errs, fmt.Errorf("%q must be between 1 and %d gibibytes inclusive, got: %d", key, utils.MaxSize, vSize)) - } - return - }, +func VMSchema() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "block_device_mappings": { + Type: schema.TypeList, + Optional: true, + //ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bsu": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "delete_on_vm_deletion": { + Type: schema.TypeBool, + Optional: true, + }, + "iops": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + iopsVal := val.(int) + if iopsVal < utils.MinIops || iopsVal > utils.MaxIops { + errs = append(errs, fmt.Errorf("%q must be between %d and %d inclusive, got: %d", key, utils.MinIops, utils.MaxIops, iopsVal)) + } + return }, - "volume_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + }, + "snapshot_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "volume_size": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + vSize := val.(int) + if vSize < 1 || vSize > utils.MaxSize { + errs = append(errs, fmt.Errorf("%q must be between 1 and %d gibibytes inclusive, got: %d", key, utils.MaxSize, vSize)) + } + return }, }, + "volume_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, }, - "device_name": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "no_device": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "virtual_device_name": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, + }, + "device_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "no_device": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "virtual_device_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, }, }, }, - "bsu_optimized": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - "client_token": { - Type: schema.TypeString, - Computed: true, - }, - "creation_date": { - Type: schema.TypeString, - Computed: true, - }, - "deletion_protection": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - "image_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "keypair_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, + }, + "bsu_optimized": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "client_token": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "deletion_protection": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "image_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "keypair_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "nics": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + ForceNew: true, + Set: func(v interface{}) int { + return v.(map[string]interface{})["device_number"].(int) }, - "nics": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - ForceNew: true, - Set: func(v interface{}) int { - return v.(map[string]interface{})["device_number"].(int) - }, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "delete_on_vm_deletion": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - ForceNew: true, - }, - "description": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ForceNew: true, - }, - "device_number": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - }, - "nic_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - "private_ips": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "is_primary": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - ForceNew: true, - }, - "link_public_ip": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "public_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip_account_id": { - Type: schema.TypeString, - Computed: true, - }, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "delete_on_vm_deletion": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + ForceNew: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "device_number": { + Type: schema.TypeInt, + Required: true, + ForceNew: true, + }, + "nic_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "private_ips": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "is_primary": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + ForceNew: true, + }, + "link_public_ip": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "public_dns_name": { + Type: schema.TypeString, + Computed: true, + }, + "public_ip": { + Type: schema.TypeString, + Computed: true, + }, + "public_ip_account_id": { + Type: schema.TypeString, + Computed: true, }, }, }, - "private_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "private_ip": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, + }, + "private_dns_name": { + Type: schema.TypeString, + Computed: true, + }, + "private_ip": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, }, }, }, - "secondary_private_ip_count": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - }, - "account_id": { - Type: schema.TypeString, - Computed: true, - }, + }, + "secondary_private_ip_count": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, + "account_id": { + Type: schema.TypeString, + Computed: true, + }, - "is_source_dest_checked": { - Type: schema.TypeBool, - Computed: true, - }, + "is_source_dest_checked": { + Type: schema.TypeBool, + Computed: true, + }, - "subnet_id": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ForceNew: true, - }, - "link_nic": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "delete_on_vm_deletion": { - Type: schema.TypeBool, - Computed: true, - }, - "device_number": { - Type: schema.TypeString, - Computed: true, - }, - "link_nic_id": { - Type: schema.TypeString, - Computed: true, - }, - "state": { - Type: schema.TypeString, - Computed: true, - }, + "subnet_id": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "link_nic": { + Type: schema.TypeList, + MaxItems: 1, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "delete_on_vm_deletion": { + Type: schema.TypeBool, + Computed: true, + }, + "device_number": { + Type: schema.TypeString, + Computed: true, + }, + "link_nic_id": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, }, }, }, - "link_public_ip": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "public_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip_account_id": { - Type: schema.TypeString, - Computed: true, - }, + }, + "link_public_ip": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "public_dns_name": { + Type: schema.TypeString, + Computed: true, + }, + "public_ip": { + Type: schema.TypeString, + Computed: true, + }, + "public_ip_account_id": { + Type: schema.TypeString, + Computed: true, }, }, }, - "mac_address": { - Type: schema.TypeString, - Computed: true, - }, - "net_id": { - Type: schema.TypeString, - Computed: true, - }, + }, + "mac_address": { + Type: schema.TypeString, + Computed: true, + }, + "net_id": { + Type: schema.TypeString, + Computed: true, + }, - "private_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "security_group_ids": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "security_groups": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "security_group_id": { - Type: schema.TypeString, - Computed: true, - }, - "security_group_name": { - Type: schema.TypeString, - Computed: true, - }, + "private_dns_name": { + Type: schema.TypeString, + Computed: true, + }, + "security_group_ids": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "security_groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "security_group_id": { + Type: schema.TypeString, + Computed: true, + }, + "security_group_name": { + Type: schema.TypeString, + Computed: true, }, }, }, - "state": { - Type: schema.TypeString, - Computed: true, - }, + }, + "state": { + Type: schema.TypeString, + Computed: true, }, }, }, - "placement_subregion_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "placement_tenancy": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "private_ips": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "security_group_ids": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "security_group_names": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "subnet_id": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Computed: true, - }, + }, + "placement_subregion_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "placement_tenancy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "private_ips": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "security_group_ids": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "security_group_names": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "subnet_id": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + Computed: true, + }, - "security_groups": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "security_group_id": { - Type: schema.TypeString, - Computed: true, - }, - "security_group_name": { - Type: schema.TypeString, - Computed: true, - }, + "security_groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "security_group_id": { + Type: schema.TypeString, + Computed: true, + }, + "security_group_name": { + Type: schema.TypeString, + Computed: true, }, }, }, - "architecture": { - Type: schema.TypeString, - Computed: true, - }, - "block_device_mappings_created": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "bsu": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "delete_on_vm_deletion": { - Type: schema.TypeBool, - Computed: true, - }, - "link_date": { - Type: schema.TypeString, - Computed: true, - }, - "state": { - Type: schema.TypeInt, - Computed: true, - }, - "volume_id": { - Type: schema.TypeFloat, - Computed: true, - }, + }, + "architecture": { + Type: schema.TypeString, + Computed: true, + }, + "block_device_mappings_created": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bsu": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "delete_on_vm_deletion": { + Type: schema.TypeBool, + Computed: true, + }, + "link_date": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeInt, + Computed: true, + }, + "volume_id": { + Type: schema.TypeFloat, + Computed: true, }, }, }, - "device_name": { - Type: schema.TypeString, - Optional: true, - }, + }, + "device_name": { + Type: schema.TypeString, + Optional: true, }, }, }, - "hypervisor": { - Type: schema.TypeString, - Computed: true, - }, - "is_source_dest_checked": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - "launch_number": { - Type: schema.TypeInt, - Computed: true, - }, - "nested_virtualization": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "net_id": { - Type: schema.TypeString, - Computed: true, - }, - "os_family": { - Type: schema.TypeString, - Computed: true, - }, - "performance": { - Type: schema.TypeString, - Computed: true, - Optional: true, - }, - "private_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "private_ip": { - Type: schema.TypeString, - Computed: true, - }, - "product_codes": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "public_dns_name": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip": { - Type: schema.TypeString, - Computed: true, - }, - "reservation_id": { - Type: schema.TypeString, - Computed: true, - }, - "root_device_name": { - Type: schema.TypeString, - Computed: true, - }, - "root_device_type": { - Type: schema.TypeString, - Computed: true, - }, - "state": { - Type: schema.TypeString, - Optional: true, - Default: "running", - }, - "state_reason": { - Type: schema.TypeString, - Computed: true, - }, - "user_data": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "vm_id": { - Type: schema.TypeString, - Computed: true, - Optional: true, - }, - "vm_initiated_shutdown_behavior": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "vm_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "request_id": { - Type: schema.TypeString, - Computed: true, - }, - "admin_password": { - Type: schema.TypeString, - Computed: true, - }, - "get_admin_password": { - Type: schema.TypeBool, - Optional: true, - }, - "tags": tagsListOAPISchema(), }, + "hypervisor": { + Type: schema.TypeString, + Computed: true, + }, + "is_source_dest_checked": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "launch_number": { + Type: schema.TypeInt, + Computed: true, + }, + "nested_virtualization": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "net_id": { + Type: schema.TypeString, + Computed: true, + }, + "os_family": { + Type: schema.TypeString, + Computed: true, + }, + "performance": { + Type: schema.TypeString, + Computed: true, + Optional: true, + }, + "private_dns_name": { + Type: schema.TypeString, + Computed: true, + }, + "private_ip": { + Type: schema.TypeString, + Computed: true, + }, + "product_codes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "public_dns_name": { + Type: schema.TypeString, + Computed: true, + }, + "public_ip": { + Type: schema.TypeString, + Computed: true, + }, + "reservation_id": { + Type: schema.TypeString, + Computed: true, + }, + "root_device_name": { + Type: schema.TypeString, + Computed: true, + }, + "root_device_type": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Optional: true, + Default: "running", + }, + "state_reason": { + Type: schema.TypeString, + Computed: true, + }, + "user_data": { + Type: schema.TypeString, + Optional: true, + }, + "vm_id": { + Type: schema.TypeString, + Computed: true, + Optional: true, + }, + "vm_initiated_shutdown_behavior": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "vm_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "admin_password": { + Type: schema.TypeString, + Computed: true, + }, + "get_admin_password": { + Type: schema.TypeBool, + Optional: true, + }, + "tags": tagsListOAPISchema(), + } +} + +func resourceOutscaleOApiVM() *schema.Resource { + return &schema.Resource{ + Create: resourceOAPIVMCreate, + Read: resourceOAPIVMRead, + Update: resourceOAPIVMUpdate, + Delete: resourceOAPIVMDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + + Schema: GetResourceSchema(VMSchema()), } }