From 055f3ec7465e26afb18d2813a8e93ef17f0130d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20B=C3=A9rot-Armand?= Date: Mon, 21 Nov 2022 12:28:23 +0000 Subject: [PATCH 1/2] Rename func : remove OutscaleAPI --- outscale/config.go | 8 +- outscale/data_source_outscale_access_key.go | 12 +- .../data_source_outscale_access_key_test.go | 4 +- outscale/data_source_outscale_access_keys.go | 10 +- .../data_source_outscale_access_keys_test.go | 4 +- outscale/data_source_outscale_accounts.go | 2 +- .../data_source_outscale_api_access_policy.go | 8 +- ..._source_outscale_api_access_policy_test.go | 6 +- .../data_source_outscale_api_access_rule.go | 12 +- ...ta_source_outscale_api_access_rule_test.go | 14 +- .../data_source_outscale_api_access_rules.go | 10 +- ...a_source_outscale_api_access_rules_test.go | 14 +- outscale/data_source_outscale_ca.go | 12 +- outscale/data_source_outscale_ca_test.go | 14 +- outscale/data_source_outscale_cas.go | 10 +- outscale/data_source_outscale_cas_test.go | 14 +- .../data_source_outscale_client_gateway.go | 14 +- ...ata_source_outscale_client_gateway_test.go | 6 +- .../data_source_outscale_client_gateways.go | 12 +- ...ta_source_outscale_client_gateways_test.go | 12 +- outscale/data_source_outscale_dhcp_option.go | 14 +- .../data_source_outscale_dhcp_option_test.go | 8 +- outscale/data_source_outscale_dhcp_options.go | 12 +- .../data_source_outscale_dhcp_options_test.go | 12 +- outscale/data_source_outscale_flexible_gpu.go | 12 +- ...ta_source_outscale_flexible_gpu_catalog.go | 8 +- ...urce_outscale_flexible_gpu_catalog_test.go | 6 +- .../data_source_outscale_flexible_gpu_test.go | 6 +- .../data_source_outscale_flexible_gpus.go | 14 +- ...data_source_outscale_flexible_gpus_test.go | 6 +- outscale/data_source_outscale_image.go | 20 +- .../data_source_outscale_image_export_task.go | 14 +- ..._source_outscale_image_export_task_test.go | 10 +- ...data_source_outscale_image_export_tasks.go | 12 +- ...source_outscale_image_export_tasks_test.go | 8 +- outscale/data_source_outscale_image_test.go | 18 +- outscale/data_source_outscale_images.go | 20 +- outscale/data_source_outscale_images_test.go | 10 +- .../data_source_outscale_internet_service.go | 14 +- ...a_source_outscale_internet_service_test.go | 6 +- .../data_source_outscale_internet_services.go | 16 +- ..._source_outscale_internet_services_test.go | 6 +- outscale/data_source_outscale_keypair.go | 14 +- outscale/data_source_outscale_keypair_test.go | 10 +- outscale/data_source_outscale_keypairs.go | 12 +- .../data_source_outscale_keypairs_test.go | 10 +- .../data_source_outscale_load_balancer.go | 20 +- ...ce_outscale_load_balancer_listener_rule.go | 8 +- ...e_outscale_load_balancer_listener_rules.go | 8 +- ...data_source_outscale_load_balancer_tags.go | 12 +- ...source_outscale_load_balancer_tags_test.go | 10 +- ...data_source_outscale_load_balancer_test.go | 10 +- ...source_outscale_load_balancer_vm_health.go | 8 +- .../data_source_outscale_load_balancer_vms.go | 8 +- .../data_source_outscale_load_balancers.go | 16 +- ...ata_source_outscale_load_balancers_test.go | 8 +- outscale/data_source_outscale_nat_service.go | 18 +- .../data_source_outscale_nat_service_test.go | 10 +- outscale/data_source_outscale_nat_services.go | 16 +- .../data_source_outscale_nat_services_test.go | 8 +- outscale/data_source_outscale_net.go | 14 +- .../data_source_outscale_net_access_point.go | 12 +- ...urce_outscale_net_access_point_services.go | 12 +- ...outscale_net_access_point_services_test.go | 6 +- ...a_source_outscale_net_access_point_test.go | 6 +- .../data_source_outscale_net_access_points.go | 14 +- ..._source_outscale_net_access_points_test.go | 6 +- .../data_source_outscale_net_attributes.go | 10 +- ...ata_source_outscale_net_attributes_test.go | 10 +- outscale/data_source_outscale_net_peering.go | 18 +- .../data_source_outscale_net_peering_test.go | 10 +- outscale/data_source_outscale_net_peerings.go | 32 +-- .../data_source_outscale_net_peerings_test.go | 6 +- outscale/data_source_outscale_net_test.go | 10 +- outscale/data_source_outscale_nets.go | 12 +- outscale/data_source_outscale_nets_test.go | 6 +- outscale/data_source_outscale_nic.go | 14 +- outscale/data_source_outscale_nic_test.go | 32 +-- outscale/data_source_outscale_nics.go | 16 +- outscale/data_source_outscale_nics_test.go | 6 +- outscale/data_source_outscale_product_type.go | 12 +- .../data_source_outscale_product_type_test.go | 6 +- .../data_source_outscale_product_types.go | 10 +- ...data_source_outscale_product_types_test.go | 6 +- .../data_source_outscale_public_catalog.go | 8 +- ...ata_source_outscale_public_catalog_test.go | 6 +- outscale/data_source_outscale_public_ip.go | 19 +- .../data_source_outscale_public_ip_test.go | 24 +- outscale/data_source_outscale_public_ips.go | 17 +- .../data_source_outscale_public_ips_test.go | 12 +- outscale/data_source_outscale_quota.go | 12 +- outscale/data_source_outscale_quota_test.go | 6 +- outscale/data_source_outscale_quotas.go | 10 +- outscale/data_source_outscale_quotas_test.go | 6 +- outscale/data_source_outscale_regions.go | 8 +- outscale/data_source_outscale_regions_test.go | 10 +- outscale/data_source_outscale_route_table.go | 20 +- .../data_source_outscale_route_table_test.go | 12 +- outscale/data_source_outscale_route_tables.go | 18 +- .../data_source_outscale_route_tables_test.go | 6 +- .../data_source_outscale_security_group.go | 18 +- ...ata_source_outscale_security_group_test.go | 20 +- .../data_source_outscale_security_groups.go | 18 +- ...ta_source_outscale_security_groups_test.go | 6 +- ...data_source_outscale_server_certificate.go | 12 +- ...source_outscale_server_certificate_test.go | 6 +- ...ata_source_outscale_server_certificates.go | 10 +- ...ource_outscale_server_certificates_test.go | 6 +- outscale/data_source_outscale_snapshot.go | 23 +- ...ta_source_outscale_snapshot_export_task.go | 14 +- ...urce_outscale_snapshot_export_task_test.go | 10 +- ...a_source_outscale_snapshot_export_tasks.go | 12 +- ...rce_outscale_snapshot_export_tasks_test.go | 8 +- .../data_source_outscale_snapshot_test.go | 18 +- outscale/data_source_outscale_snapshots.go | 18 +- .../data_source_outscale_snapshots_test.go | 6 +- outscale/data_source_outscale_subnet.go | 14 +- outscale/data_source_outscale_subnet_test.go | 20 +- outscale/data_source_outscale_subnets.go | 12 +- outscale/data_source_outscale_subnets_test.go | 12 +- outscale/data_source_outscale_subregions.go | 12 +- .../data_source_outscale_subregions_test.go | 18 +- outscale/data_source_outscale_tag.go | 12 +- outscale/data_source_outscale_tag_test.go | 6 +- outscale/data_source_outscale_tags.go | 12 +- outscale/data_source_outscale_tags_test.go | 6 +- .../data_source_outscale_virtual_gateway.go | 14 +- ...ta_source_outscale_virtual_gateway_test.go | 6 +- .../data_source_outscale_virtual_gateways.go | 12 +- ...a_source_outscale_virtual_gateways_test.go | 6 +- outscale/data_source_outscale_vm.go | 36 +-- outscale/data_source_outscale_vm_state.go | 26 +- .../data_source_outscale_vm_state_test.go | 10 +- outscale/data_source_outscale_vm_states.go | 22 +- .../data_source_outscale_vm_states_test.go | 6 +- outscale/data_source_outscale_vm_test.go | 6 +- outscale/data_source_outscale_vm_types.go | 20 +- .../data_source_outscale_vm_types_test.go | 6 +- outscale/data_source_outscale_vms.go | 26 +- outscale/data_source_outscale_vms_test.go | 6 +- outscale/data_source_outscale_volume.go | 18 +- outscale/data_source_outscale_volume_test.go | 18 +- outscale/data_source_outscale_volumes.go | 16 +- outscale/data_source_outscale_volumes_test.go | 24 +- .../data_source_outscale_vpn_connection.go | 14 +- ...ata_source_outscale_vpn_connection_test.go | 12 +- .../data_source_outscale_vpn_connections.go | 12 +- ...ta_source_outscale_vpn_connections_test.go | 12 +- outscale/dictionary.go | 166 ++++++------ .../import_outscale_net_attributes_test.go | 4 +- outscale/instance_set_set.go | 40 +-- outscale/oapi_tags.go | 47 ++-- outscale/provider.go | 248 +++++++++--------- outscale/resource_outscale_access_key.go | 30 +-- outscale/resource_outscale_access_key_test.go | 58 ++-- .../resource_outscale_api_access_policy.go | 28 +- outscale/resource_outscale_api_access_rule.go | 30 +-- .../resource_outscale_api_access_rule_test.go | 18 +- outscale/resource_outscale_ca.go | 30 +-- outscale/resource_outscale_ca_test.go | 24 +- outscale/resource_outscale_client_gateway.go | 36 +-- .../resource_outscale_client_gateway_test.go | 8 +- outscale/resource_outscale_dhcp_option.go | 36 +-- .../resource_outscale_dhcp_option_test.go | 60 ++--- outscale/resource_outscale_flexible_gpu.go | 30 +-- .../resource_outscale_flexible_gpu_link.go | 22 +- ...esource_outscale_flexible_gpu_link_test.go | 6 +- .../resource_outscale_flexible_gpu_test.go | 6 +- outscale/resource_outscale_image.go | 80 +++--- .../resource_outscale_image_export_task.go | 46 ++-- ...esource_outscale_image_export_task_test.go | 14 +- ...source_outscale_image_launch_permission.go | 40 +-- ...e_outscale_image_launch_permission_test.go | 56 ++-- outscale/resource_outscale_image_test.go | 18 +- .../resource_outscale_internet_service.go | 38 +-- ...resource_outscale_internet_service_link.go | 34 +-- ...rce_outscale_internet_service_link_test.go | 32 +-- ...resource_outscale_internet_service_test.go | 22 +- outscale/resource_outscale_keypair.go | 32 +-- outscale/resource_outscale_keypair_test.go | 48 ++-- outscale/resource_outscale_load_balancer.go | 48 ++-- ...ource_outscale_load_balancer_attributes.go | 38 +-- ..._outscale_load_balancer_attributes_test.go | 10 +- ...ce_outscale_load_balancer_listener_rule.go | 30 +-- .../resource_outscale_load_balancer_policy.go | 26 +- ...urce_outscale_load_balancer_policy_test.go | 2 +- .../resource_outscale_load_balancer_test.go | 28 +- .../resource_outscale_load_balancer_vms.go | 22 +- ...esource_outscale_load_balancer_vms_test.go | 10 +- outscale/resource_outscale_nat_service.go | 50 ++-- .../resource_outscale_nat_service_test.go | 28 +- outscale/resource_outscale_net.go | 40 +-- .../resource_outscale_net_access_point.go | 36 +-- ...resource_outscale_net_access_point_test.go | 6 +- outscale/resource_outscale_net_attributes.go | 32 +-- .../resource_outscale_net_attributes_test.go | 14 +- outscale/resource_outscale_net_peering.go | 48 ++-- ...source_outscale_net_peering_acceptation.go | 22 +- ...e_outscale_net_peering_acceptation_test.go | 14 +- .../resource_outscale_net_peering_test.go | 40 +-- outscale/resource_outscale_net_test.go | 26 +- outscale/resource_outscale_nic.go | 60 ++--- outscale/resource_outscale_nic_link.go | 28 +- outscale/resource_outscale_nic_link_test.go | 24 +- outscale/resource_outscale_nic_private_ip.go | 22 +- .../resource_outscale_nic_private_ip_test.go | 16 +- outscale/resource_outscale_nic_test.go | 26 +- outscale/resource_outscale_public_ip.go | 46 ++-- outscale/resource_outscale_public_ip_link.go | 60 ++--- .../resource_outscale_public_ip_link_test.go | 28 +- outscale/resource_outscale_public_ip_test.go | 64 ++--- outscale/resource_outscale_route.go | 58 ++-- outscale/resource_outscale_route_table.go | 64 ++--- .../resource_outscale_route_table_link.go | 30 +-- ...resource_outscale_route_table_link_test.go | 28 +- .../resource_outscale_route_table_test.go | 76 +++--- outscale/resource_outscale_route_test.go | 62 ++--- outscale/resource_outscale_security_group.go | 54 ++-- .../resource_outscale_security_group_rule.go | 28 +- ...ource_outscale_security_group_rule_test.go | 34 +-- .../resource_outscale_security_group_test.go | 18 +- .../resource_outscale_server_certificate.go | 30 +-- ...source_outscale_server_certificate_test.go | 22 +- outscale/resource_outscale_snapshot.go | 50 ++-- .../resource_outscale_snapshot_attributes.go | 20 +- ...ource_outscale_snapshot_attributes_test.go | 8 +- .../resource_outscale_snapshot_export_task.go | 46 ++-- ...urce_outscale_snapshot_export_task_test.go | 14 +- outscale/resource_outscale_snapshot_test.go | 42 +-- outscale/resource_outscale_subnet.go | 64 ++--- outscale/resource_outscale_subnet_test.go | 18 +- outscale/resource_outscale_tags.go | 28 +- outscale/resource_outscale_tags_test.go | 91 ++----- outscale/resource_outscale_virtual_gateway.go | 42 +-- .../resource_outscale_virtual_gateway_link.go | 26 +- ...urce_outscale_virtual_gateway_link_test.go | 36 +-- ...scale_virtual_gateway_route_propagation.go | 20 +- ..._virtual_gateway_route_propagation_test.go | 16 +- .../resource_outscale_virtual_gateway_test.go | 58 ++-- outscale/resource_outscale_vm.go | 50 ++-- outscale/resource_outscale_vm_test.go | 243 +++++++---------- outscale/resource_outscale_volume.go | 48 ++-- outscale/resource_outscale_volume_test.go | 32 +-- outscale/resource_outscale_volumes_link.go | 32 +-- .../resource_outscale_volumes_link_test.go | 26 +- outscale/resource_outscale_vpn_connection.go | 38 +-- .../resource_outscale_vpn_connection_route.go | 36 +-- ...urce_outscale_vpn_connection_route_test.go | 32 +-- .../resource_outscale_vpn_connection_test.go | 54 ++-- 249 files changed, 2836 insertions(+), 2962 deletions(-) diff --git a/outscale/config.go b/outscale/config.go index 7676415a5..faeb1622c 100644 --- a/outscale/config.go +++ b/outscale/config.go @@ -21,13 +21,13 @@ type Config struct { X509key string } -// OutscaleClient client -type OutscaleClient struct { +// Client client +type Client struct { OSCAPI *oscgo.APIClient } // Client ... -func (c *Config) Client() (*OutscaleClient, error) { +func (c *Config) Client() (*Client, error) { tlsconfig := &tls.Config{InsecureSkipVerify: false} cert, err := tls.LoadX509KeyPair(c.X509cert, c.X509key) if err == nil { @@ -61,7 +61,7 @@ func (c *Config) Client() (*OutscaleClient, error) { oscClient := oscgo.NewAPIClient(oscConfig) - client := &OutscaleClient{ + client := &Client{ OSCAPI: oscClient, } diff --git a/outscale/data_source_outscale_access_key.go b/outscale/data_source_outscale_access_key.go index 552ba6faa..585e3233b 100644 --- a/outscale/data_source_outscale_access_key.go +++ b/outscale/data_source_outscale_access_key.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleAccessKey() *schema.Resource { +func dataSourceAccessKey() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleAccessKeyRead, + Read: dataSourceAccessKeyRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "access_key_id": { @@ -48,8 +48,8 @@ func dataSourceOutscaleAccessKey() *schema.Resource { } } -func dataSourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceAccessKeyRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") accessKeyID, accessKeyOk := d.GetOk("access_key_id") @@ -61,7 +61,7 @@ func dataSourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) e filterReq := &oscgo.FiltersAccessKeys{} if filtersOk { - filterReq = buildOutscaleDataSourceAccessKeyFilters(filters.(*schema.Set)) + filterReq = buildDataSourceAccessKeyFilters(filters.(*schema.Set)) } if accessKeyOk { filterReq.SetAccessKeyIds([]string{accessKeyID.(string)}) @@ -115,7 +115,7 @@ func dataSourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) e return nil } -func buildOutscaleDataSourceAccessKeyFilters(set *schema.Set) *oscgo.FiltersAccessKeys { +func buildDataSourceAccessKeyFilters(set *schema.Set) *oscgo.FiltersAccessKeys { var filters oscgo.FiltersAccessKeys for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_access_key_test.go b/outscale/data_source_outscale_access_key_test.go index 981ad247a..930c9f813 100644 --- a/outscale/data_source_outscale_access_key_test.go +++ b/outscale/data_source_outscale_access_key_test.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleDataSourceAccessKey_basic(t *testing.T) { +func TestAccDataSourceAccessKey_basic(t *testing.T) { t.Parallel() dataSourceName := "outscale_access_key.outscale_access_key" @@ -28,7 +28,7 @@ func TestAccOutscaleDataSourceAccessKey_basic(t *testing.T) { }) } -func TestAccOutscaleDataSourceAccessKey_withFilters(t *testing.T) { +func TestAccDataSourceAccessKey_withFilters(t *testing.T) { t.Parallel() dataSourceName := "outscale_access_key.outscale_access_key" diff --git a/outscale/data_source_outscale_access_keys.go b/outscale/data_source_outscale_access_keys.go index f32cf1a02..79ffcf200 100644 --- a/outscale/data_source_outscale_access_keys.go +++ b/outscale/data_source_outscale_access_keys.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleAccessKeys() *schema.Resource { +func dataSourceAccessKeys() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleAccessKeysRead, + Read: dataSourceAccessKeysRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "access_key_ids": { @@ -67,8 +67,8 @@ func dataSourceOutscaleAccessKeys() *schema.Resource { } } -func dataSourceOutscaleAccessKeysRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceAccessKeysRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") accessKeyID, accessKeyOk := d.GetOk("access_key_ids") @@ -80,7 +80,7 @@ func dataSourceOutscaleAccessKeysRead(d *schema.ResourceData, meta interface{}) filterReq := &oscgo.FiltersAccessKeys{} if filtersOk { - filterReq = buildOutscaleDataSourceAccessKeyFilters(filters.(*schema.Set)) + filterReq = buildDataSourceAccessKeyFilters(filters.(*schema.Set)) } if accessKeyOk { filterReq.SetAccessKeyIds(expandStringValueList(accessKeyID.([]interface{}))) diff --git a/outscale/data_source_outscale_access_keys_test.go b/outscale/data_source_outscale_access_keys_test.go index 170987e65..2fe1ea64a 100644 --- a/outscale/data_source_outscale_access_keys_test.go +++ b/outscale/data_source_outscale_access_keys_test.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleDataSourceAccessKeys_basic(t *testing.T) { +func TestAccDataSourceAccessKeys_basic(t *testing.T) { t.Parallel() dataSourceName := "data.outscale_access_keys.outscale_access_key" @@ -25,7 +25,7 @@ func TestAccOutscaleDataSourceAccessKeys_basic(t *testing.T) { }) } -func TestAccOutscaleDataSourceAccessKeys_withFilters(t *testing.T) { +func TestAccDataSourceAccessKeys_withFilters(t *testing.T) { t.Parallel() dataSourceName := "data.outscale_access_keys.outscale_access_key" diff --git a/outscale/data_source_outscale_accounts.go b/outscale/data_source_outscale_accounts.go index 00928280d..4cc421809 100644 --- a/outscale/data_source_outscale_accounts.go +++ b/outscale/data_source_outscale_accounts.go @@ -95,7 +95,7 @@ func dataSourceAccounts() *schema.Resource { func dataSourceAccountsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI req := oscgo.ReadAccountsRequest{} diff --git a/outscale/data_source_outscale_api_access_policy.go b/outscale/data_source_outscale_api_access_policy.go index 2f87ee01c..c794b71c8 100644 --- a/outscale/data_source_outscale_api_access_policy.go +++ b/outscale/data_source_outscale_api_access_policy.go @@ -11,9 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIApiAccessPolicy() *schema.Resource { +func dataSourceApiAccessPolicy() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIApiAccessPolicyRead, + Read: dataSourceApiAccessPolicyRead, Schema: map[string]*schema.Schema{ "max_access_key_expiration_seconds": { Type: schema.TypeInt, @@ -31,8 +31,8 @@ func dataSourceOutscaleOAPIApiAccessPolicy() *schema.Resource { } } -func dataSourceOutscaleOAPIApiAccessPolicyRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceApiAccessPolicyRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadApiAccessPolicyRequest{} diff --git a/outscale/data_source_outscale_api_access_policy_test.go b/outscale/data_source_outscale_api_access_policy_test.go index 226d76e52..a9e079dfb 100644 --- a/outscale/data_source_outscale_api_access_policy_test.go +++ b/outscale/data_source_outscale_api_access_policy_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIApiAccessPolicy_basic(t *testing.T) { +func TestAccDataSourceApiAccessPolicy_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -16,13 +16,13 @@ func TestAccDataSourceOutscaleOAPIApiAccessPolicy_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIApiAccessPolicyConfig(), + Config: testAccDataSourceApiAccessPolicyConfig(), }, }, }) } -func testAccDataSourceOutscaleOAPIApiAccessPolicyConfig() string { +func testAccDataSourceApiAccessPolicyConfig() string { return fmt.Sprintf(` data "outscale_api_access_policy" "api_access_policy" {} `) diff --git a/outscale/data_source_outscale_api_access_rule.go b/outscale/data_source_outscale_api_access_rule.go index eb41a37e0..c6e386a7f 100644 --- a/outscale/data_source_outscale_api_access_rule.go +++ b/outscale/data_source_outscale_api_access_rule.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIApiAccessRule() *schema.Resource { +func dataSourceApiAccessRule() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIApiAccessRuleRead, + Read: dataSourceApiAccessRuleRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "api_access_rule_id": { @@ -48,8 +48,8 @@ func dataSourceOutscaleOAPIApiAccessRule() *schema.Resource { } } -func dataSourceOutscaleOAPIApiAccessRuleRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceApiAccessRuleRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") if !filtersOk { @@ -57,7 +57,7 @@ func dataSourceOutscaleOAPIApiAccessRuleRead(d *schema.ResourceData, meta interf } req := oscgo.ReadApiAccessRulesRequest{ - Filters: buildOutscaleApiAccessRuleFilters(filters.(*schema.Set)), + Filters: buildApiAccessRuleFilters(filters.(*schema.Set)), } var resp oscgo.ReadApiAccessRulesResponse @@ -112,7 +112,7 @@ func dataSourceOutscaleOAPIApiAccessRuleRead(d *schema.ResourceData, meta interf return nil } -func buildOutscaleApiAccessRuleFilters(set *schema.Set) *oscgo.FiltersApiAccessRule { +func buildApiAccessRuleFilters(set *schema.Set) *oscgo.FiltersApiAccessRule { var filters oscgo.FiltersApiAccessRule for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_api_access_rule_test.go b/outscale/data_source_outscale_api_access_rule_test.go index 910600ce8..2dcc75450 100644 --- a/outscale/data_source_outscale_api_access_rule_test.go +++ b/outscale/data_source_outscale_api_access_rule_test.go @@ -13,27 +13,27 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccDataOutscaleOAPIApiAccessRule_basic(t *testing.T) { +func TestAccDataApiAccessRule_basic(t *testing.T) { t.Parallel() resourceName := "outscale_api_access_rule.rule_data" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccDataCheckOutscaleApiAccessRuleDestroy, + CheckDestroy: testAccDataCheckApiAccessRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccDataOutscaleOAPIApiAccessRuleConfig(utils.TestCaPem), + Config: testAccDataApiAccessRuleConfig(utils.TestCaPem), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleApiAccessRuleExists(resourceName), + testAccCheckApiAccessRuleExists(resourceName), ), }, }, }) } -func testAccDataCheckOutscaleApiAccessRuleDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccDataCheckApiAccessRuleDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_api_access_rule" { @@ -70,7 +70,7 @@ func testAccDataCheckOutscaleApiAccessRuleDestroy(s *terraform.State) error { return nil } -func testAccDataOutscaleOAPIApiAccessRuleConfig(ca_pem string) string { +func testAccDataApiAccessRuleConfig(ca_pem string) string { return fmt.Sprintf(` resource "outscale_ca" "ca_rule" { ca_pem = %[1]q diff --git a/outscale/data_source_outscale_api_access_rules.go b/outscale/data_source_outscale_api_access_rules.go index fc33a279d..dc0cdfd06 100644 --- a/outscale/data_source_outscale_api_access_rules.go +++ b/outscale/data_source_outscale_api_access_rules.go @@ -11,9 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIApiAccessRules() *schema.Resource { +func dataSourceApiAccessRules() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIApiAccessRulesRead, + Read: dataSourceApiAccessRulesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "api_access_rules": { @@ -55,13 +55,13 @@ func dataSourceOutscaleOAPIApiAccessRules() *schema.Resource { } } -func dataSourceOutscaleOAPIApiAccessRulesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceApiAccessRulesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") req := oscgo.ReadApiAccessRulesRequest{} if filtersOk { - req.Filters = buildOutscaleApiAccessRuleFilters(filters.(*schema.Set)) + req.Filters = buildApiAccessRuleFilters(filters.(*schema.Set)) } var resp oscgo.ReadApiAccessRulesResponse diff --git a/outscale/data_source_outscale_api_access_rules_test.go b/outscale/data_source_outscale_api_access_rules_test.go index 905f93013..74a1082ae 100644 --- a/outscale/data_source_outscale_api_access_rules_test.go +++ b/outscale/data_source_outscale_api_access_rules_test.go @@ -13,26 +13,26 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccDataOutscaleOAPIApiAccessRules_basic(t *testing.T) { +func TestAccDataApiAccessRules_basic(t *testing.T) { t.Parallel() resourceName := "outscale_api_access_rule.rule_data" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccDataCheckOutscaleApiAccessRuleDestroy, + CheckDestroy: testAccDataCheckApiAccessRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccDataOutscaleOAPIApiAccessRulesConfig(utils.TestCaPem), + Config: testAccDataApiAccessRulesConfig(utils.TestCaPem), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleApiAccessRuleExists(resourceName), + testAccCheckApiAccessRuleExists(resourceName), ), }, }, }) } -func testAccDataCheckOutscaleApiAccessRulesDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccDataCheckApiAccessRulesDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_api_access_rule" { @@ -69,7 +69,7 @@ func testAccDataCheckOutscaleApiAccessRulesDestroy(s *terraform.State) error { return nil } -func testAccDataOutscaleOAPIApiAccessRulesConfig(ca_pem string) string { +func testAccDataApiAccessRulesConfig(ca_pem string) string { return fmt.Sprintf(` resource "outscale_ca" "ca_rule" { ca_pem = %[1]q diff --git a/outscale/data_source_outscale_ca.go b/outscale/data_source_outscale_ca.go index db56afa76..5b5469a6e 100644 --- a/outscale/data_source_outscale_ca.go +++ b/outscale/data_source_outscale_ca.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPICa() *schema.Resource { +func dataSourceCa() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPICaRead, + Read: dataSourceCaRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "ca_pem": { @@ -41,8 +41,8 @@ func dataSourceOutscaleOAPICa() *schema.Resource { } } -func dataSourceOutscaleOAPICaRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceCaRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") if !filtersOk { @@ -51,7 +51,7 @@ func dataSourceOutscaleOAPICaRead(d *schema.ResourceData, meta interface{}) erro params := oscgo.ReadCasRequest{} if filtersOk { - params.Filters = buildOutscaleOAPIDataSourceCaFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceCaFilters(filters.(*schema.Set)) } var resp oscgo.ReadCasResponse var err error @@ -93,7 +93,7 @@ func dataSourceOutscaleOAPICaRead(d *schema.ResourceData, meta interface{}) erro return nil } -func buildOutscaleOAPIDataSourceCaFilters(set *schema.Set) *oscgo.FiltersCa { +func buildDataSourceCaFilters(set *schema.Set) *oscgo.FiltersCa { var filters oscgo.FiltersCa for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_ca_test.go b/outscale/data_source_outscale_ca_test.go index 94c575bce..bd40632ad 100644 --- a/outscale/data_source_outscale_ca_test.go +++ b/outscale/data_source_outscale_ca_test.go @@ -12,26 +12,26 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func TestAccDataOutscaleOAPICa_basic(t *testing.T) { +func TestAccDataCa_basic(t *testing.T) { resourceName := "outscale_ca.ca_test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccDataCheckOutscaleCaDestroy, + CheckDestroy: testAccDataCheckCaDestroy, Steps: []resource.TestStep{ { - Config: testAccDataOutscaleOAPICaConfig(utils.TestCaPem), + Config: testAccDataCaConfig(utils.TestCaPem), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleCaExists(resourceName), + testAccCheckCaExists(resourceName), ), }, }, }) } -func testAccDataCheckOutscaleCaDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccDataCheckCaDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_ca" { @@ -70,7 +70,7 @@ func testAccDataCheckOutscaleCaDestroy(s *terraform.State) error { return nil } -func testAccDataOutscaleOAPICaConfig(ca_pem string) string { +func testAccDataCaConfig(ca_pem string) string { return fmt.Sprintf(` resource "outscale_ca" "ca_test" { ca_pem = %[1]q diff --git a/outscale/data_source_outscale_cas.go b/outscale/data_source_outscale_cas.go index 26779039a..d7efc51f9 100644 --- a/outscale/data_source_outscale_cas.go +++ b/outscale/data_source_outscale_cas.go @@ -11,9 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPICas() *schema.Resource { +func dataSourceCas() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPICasRead, + Read: dataSourceCasRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "cas": { @@ -44,14 +44,14 @@ func dataSourceOutscaleOAPICas() *schema.Resource { } } -func dataSourceOutscaleOAPICasRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceCasRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") params := oscgo.ReadCasRequest{} if filtersOk { - params.Filters = buildOutscaleOAPIDataSourceCaFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceCaFilters(filters.(*schema.Set)) } var resp oscgo.ReadCasResponse var err error diff --git a/outscale/data_source_outscale_cas_test.go b/outscale/data_source_outscale_cas_test.go index cad46c45a..937232f36 100644 --- a/outscale/data_source_outscale_cas_test.go +++ b/outscale/data_source_outscale_cas_test.go @@ -12,26 +12,26 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func TestAccDataOutscaleOAPICas_basic(t *testing.T) { +func TestAccDataCas_basic(t *testing.T) { resName := "outscale_ca.ca_test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccDataCheckOutscaleCasDestroy, + CheckDestroy: testAccDataCheckCasDestroy, Steps: []resource.TestStep{ { - Config: testAccDataOutscaleOAPICasConfig(utils.TestCaPem), + Config: testAccDataCasConfig(utils.TestCaPem), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleCaExists(resName), + testAccCheckCaExists(resName), ), }, }, }) } -func testAccDataCheckOutscaleCasDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccDataCheckCasDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_ca" { @@ -70,7 +70,7 @@ func testAccDataCheckOutscaleCasDestroy(s *terraform.State) error { return nil } -func testAccDataOutscaleOAPICasConfig(ca_pem string) string { +func testAccDataCasConfig(ca_pem string) string { return fmt.Sprintf(` resource "outscale_ca" "ca_test" { ca_pem = %[1]q diff --git a/outscale/data_source_outscale_client_gateway.go b/outscale/data_source_outscale_client_gateway.go index e5f11a91e..5e15de902 100644 --- a/outscale/data_source_outscale_client_gateway.go +++ b/outscale/data_source_outscale_client_gateway.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleClientGateway() *schema.Resource { +func dataSourceClientGateway() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleClientGatewayRead, + Read: dataSourceClientGatewayRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "bgp_asn": { @@ -47,8 +47,8 @@ func dataSourceOutscaleClientGateway() *schema.Resource { } } -func dataSourceOutscaleClientGatewayRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceClientGatewayRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") clientGatewayID, clientGatewayOk := d.GetOk("client_gateway_id") @@ -66,7 +66,7 @@ func dataSourceOutscaleClientGatewayRead(d *schema.ResourceData, meta interface{ } if filtersOk { - params.Filters = buildOutscaleDataSourceClientGatewayFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceClientGatewayFilters(filters.(*schema.Set)) } var resp oscgo.ReadClientGatewaysResponse @@ -108,7 +108,7 @@ func dataSourceOutscaleClientGatewayRead(d *schema.ResourceData, meta interface{ if err := d.Set("state", clientGateway.GetState()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(clientGateway.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(clientGateway.GetTags())); err != nil { return err } @@ -117,7 +117,7 @@ func dataSourceOutscaleClientGatewayRead(d *schema.ResourceData, meta interface{ return nil } -func buildOutscaleDataSourceClientGatewayFilters(set *schema.Set) *oscgo.FiltersClientGateway { +func buildDataSourceClientGatewayFilters(set *schema.Set) *oscgo.FiltersClientGateway { var filters oscgo.FiltersClientGateway for _, v := range set.List() { log.Printf("[DEBUG] gateway filters %+v", v) diff --git a/outscale/data_source_outscale_client_gateway_test.go b/outscale/data_source_outscale_client_gateway_test.go index a03e6fe3c..9093f2293 100644 --- a/outscale/data_source_outscale_client_gateway_test.go +++ b/outscale/data_source_outscale_client_gateway_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleGatewayDatasource_basic(t *testing.T) { +func TestAccGatewayDatasource_basic(t *testing.T) { t.Parallel() rBgpAsn := acctest.RandIntRange(64512, 65534) value := fmt.Sprintf("testacc-%s", acctest.RandString(5)) @@ -24,7 +24,7 @@ func TestAccOutscaleGatewayDatasource_basic(t *testing.T) { }) } -func TestAccOutscaleGatewayDatasource_withFilters(t *testing.T) { +func TestAccGatewayDatasource_withFilters(t *testing.T) { t.Parallel() // datasourceName := "data.outscale_client_gateway.test" rBgpAsn := acctest.RandIntRange(64512, 65534) @@ -41,7 +41,7 @@ func TestAccOutscaleGatewayDatasource_withFilters(t *testing.T) { }) } -func TestAccOutscaleGatewayDatasource_withFiltersNoLocalhost(t *testing.T) { +func TestAccGatewayDatasource_withFiltersNoLocalhost(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/outscale/data_source_outscale_client_gateways.go b/outscale/data_source_outscale_client_gateways.go index 58742de8b..d2418fc0a 100644 --- a/outscale/data_source_outscale_client_gateways.go +++ b/outscale/data_source_outscale_client_gateways.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleClientGateways() *schema.Resource { +func dataSourceClientGateways() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleClientGatewaysRead, + Read: dataSourceClientGatewaysRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "client_gateway_ids": { @@ -61,8 +61,8 @@ func dataSourceOutscaleClientGateways() *schema.Resource { } } -func dataSourceOutscaleClientGatewaysRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceClientGatewaysRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") clientGatewayIDs, clientGatewayOk := d.GetOk("client_gateway_ids") @@ -80,7 +80,7 @@ func dataSourceOutscaleClientGatewaysRead(d *schema.ResourceData, meta interface } if filtersOk { - params.Filters = buildOutscaleDataSourceClientGatewayFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceClientGatewayFilters(filters.(*schema.Set)) } var resp oscgo.ReadClientGatewaysResponse @@ -119,7 +119,7 @@ func flattenClientGateways(clientGateways []oscgo.ClientGateway) []map[string]in "connection_type": clientGateway.GetConnectionType(), "public_ip": clientGateway.GetPublicIp(), "state": clientGateway.GetState(), - "tags": tagsOSCAPIToMap(clientGateway.GetTags()), + "tags": tagsToMap(clientGateway.GetTags()), } } return clientGatewaysMap diff --git a/outscale/data_source_outscale_client_gateways_test.go b/outscale/data_source_outscale_client_gateways_test.go index 59175acb2..b23b69a1f 100644 --- a/outscale/data_source_outscale_client_gateways_test.go +++ b/outscale/data_source_outscale_client_gateways_test.go @@ -6,31 +6,31 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleClientGatewaysDatasource_basic(t *testing.T) { +func TestAccClientGatewaysDatasource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleClientGatewaysDatasourceConfigBasic, + Config: testAccClientGatewaysDatasourceConfigBasic, }, }, }) } -func TestAccOutscaleClientGatewaysDatasource_withFilters(t *testing.T) { +func TestAccClientGatewaysDatasource_withFilters(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleClientGatewaysDatasourceConfigWithFilters, + Config: testAccClientGatewaysDatasourceConfigWithFilters, }, }, }) } -const testAccOutscaleClientGatewaysDatasourceConfigBasic = ` +const testAccClientGatewaysDatasourceConfigBasic = ` resource "outscale_client_gateway" "foo1" { bgp_asn = 3 public_ip = "172.0.0.1" @@ -53,7 +53,7 @@ const testAccOutscaleClientGatewaysDatasourceConfigBasic = ` } ` -const testAccOutscaleClientGatewaysDatasourceConfigWithFilters = ` +const testAccClientGatewaysDatasourceConfigWithFilters = ` resource "outscale_client_gateway" "foo1" { bgp_asn = 3 public_ip = "172.0.0.1" diff --git a/outscale/data_source_outscale_dhcp_option.go b/outscale/data_source_outscale_dhcp_option.go index c6be87f9c..df12d2198 100644 --- a/outscale/data_source_outscale_dhcp_option.go +++ b/outscale/data_source_outscale_dhcp_option.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleDHCPOption() *schema.Resource { +func dataSourceDHCPOption() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleDHCPOptionRead, + Read: dataSourceDHCPOptionRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -62,8 +62,8 @@ func dataSourceOutscaleDHCPOption() *schema.Resource { } } -func dataSourceOutscaleDHCPOptionRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceDHCPOptionRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") dhcpID, dhcpIDOk := d.GetOk("dhcp_options_set_id") @@ -78,7 +78,7 @@ func dataSourceOutscaleDHCPOptionRead(d *schema.ResourceData, meta interface{}) } } if filtersOk { - params.Filters = buildOutscaleDataSourceDHCPOptionFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceDHCPOptionFilters(filters.(*schema.Set)) } var resp oscgo.ReadDhcpOptionsResponse @@ -123,7 +123,7 @@ func dataSourceOutscaleDHCPOptionRead(d *schema.ResourceData, meta interface{}) if err := d.Set("dhcp_options_set_id", dhcpOption.GetDhcpOptionsSetId()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(dhcpOption.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(dhcpOption.GetTags())); err != nil { return err } @@ -132,7 +132,7 @@ func dataSourceOutscaleDHCPOptionRead(d *schema.ResourceData, meta interface{}) return nil } -func buildOutscaleDataSourceDHCPOptionFilters(set *schema.Set) *oscgo.FiltersDhcpOptions { +func buildDataSourceDHCPOptionFilters(set *schema.Set) *oscgo.FiltersDhcpOptions { var filters oscgo.FiltersDhcpOptions for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_dhcp_option_test.go b/outscale/data_source_outscale_dhcp_option_test.go index 996de273c..f67e29e16 100644 --- a/outscale/data_source_outscale_dhcp_option_test.go +++ b/outscale/data_source_outscale_dhcp_option_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleDHCPOption_basic(t *testing.T) { +func TestAccDHCPOption_basic(t *testing.T) { t.Parallel() resourceName := "outscale_dhcp_option.foo" dataSourceName := "data.outscale_dhcp_option.test" @@ -22,7 +22,7 @@ func TestAccOutscaleDHCPOption_basic(t *testing.T) { Config: testAccClientDHCPOptionBasic(value), Check: resource.ComposeTestCheckFunc( // resource validations - testAccCheckOutscaleDHCPOptionExists(resourceName), + testAccCheckDHCPOptionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "domain_name"), resource.TestCheckResourceAttrSet(resourceName, "domain_name_servers.#"), resource.TestCheckResourceAttrSet(resourceName, "ntp_servers.#"), @@ -45,7 +45,7 @@ func TestAccOutscaleDHCPOption_basic(t *testing.T) { }) } -func TestAccOutscaleDHCPOption_withFilters(t *testing.T) { +func TestAccDHCPOption_withFilters(t *testing.T) { t.Parallel() resourceName := "outscale_dhcp_option.foo" dataSourceName := "data.outscale_dhcp_option.test" @@ -59,7 +59,7 @@ func TestAccOutscaleDHCPOption_withFilters(t *testing.T) { Config: testAccClientDHCPOptionWithFilters(value), Check: resource.ComposeTestCheckFunc( // resource validations - testAccCheckOutscaleDHCPOptionExists(resourceName), + testAccCheckDHCPOptionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "domain_name"), resource.TestCheckResourceAttrSet(resourceName, "domain_name_servers.#"), resource.TestCheckResourceAttrSet(resourceName, "ntp_servers.#"), diff --git a/outscale/data_source_outscale_dhcp_options.go b/outscale/data_source_outscale_dhcp_options.go index 9fca893bd..37cd944f2 100644 --- a/outscale/data_source_outscale_dhcp_options.go +++ b/outscale/data_source_outscale_dhcp_options.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleDHCPOptions() *schema.Resource { +func dataSourceDHCPOptions() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleDHCPOptionsRead, + Read: dataSourceDHCPOptionsRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -75,8 +75,8 @@ func dataSourceOutscaleDHCPOptions() *schema.Resource { } } -func dataSourceOutscaleDHCPOptionsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceDHCPOptionsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") dhcpIDs, dhcpIDOk := d.GetOk("dhcp_options_set_ids") @@ -91,7 +91,7 @@ func dataSourceOutscaleDHCPOptionsRead(d *schema.ResourceData, meta interface{}) } } if filtersOk { - params.Filters = buildOutscaleDataSourceDHCPOptionFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceDHCPOptionFilters(filters.(*schema.Set)) } var resp oscgo.ReadDhcpOptionsResponse @@ -131,7 +131,7 @@ func flattenDHCPOption(dhcpOptions []oscgo.DhcpOptionsSet) []map[string]interfac "ntp_servers": dhcpOption.GetNtpServers(), "default": dhcpOption.GetDefault(), "dhcp_options_set_id": dhcpOption.GetDhcpOptionsSetId(), - "tags": tagsOSCAPIToMap(dhcpOption.GetTags()), + "tags": tagsToMap(dhcpOption.GetTags()), } } return dhcpOptionsMap diff --git a/outscale/data_source_outscale_dhcp_options_test.go b/outscale/data_source_outscale_dhcp_options_test.go index c90d9022c..2f4cb1e64 100644 --- a/outscale/data_source_outscale_dhcp_options_test.go +++ b/outscale/data_source_outscale_dhcp_options_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleDHCPOptionsDatasource_basic(t *testing.T) { +func TestAccDHCPOptionsDatasource_basic(t *testing.T) { t.Parallel() value := fmt.Sprintf("test-acc-value-%s", acctest.RandString(5)) @@ -17,13 +17,13 @@ func TestAccOutscaleDHCPOptionsDatasource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleDHCPOptionsDatasourceConfigBasic(value), + Config: testAccDHCPOptionsDatasourceConfigBasic(value), }, }, }) } -func TestAccOutscaleDHCPOptionsDatasource_withFilters(t *testing.T) { +func TestAccDHCPOptionsDatasource_withFilters(t *testing.T) { t.Parallel() value := fmt.Sprintf("test-acc-value-%s", acctest.RandString(5)) @@ -32,13 +32,13 @@ func TestAccOutscaleDHCPOptionsDatasource_withFilters(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleDHCPOptionsDatasourceConfigWithFilters(value), + Config: testAccDHCPOptionsDatasourceConfigWithFilters(value), }, }, }) } -func testAccOutscaleDHCPOptionsDatasourceConfigBasic(value string) string { +func testAccDHCPOptionsDatasourceConfigBasic(value string) string { return fmt.Sprintf(` resource "outscale_dhcp_option" "foo1" { domain_name = "test.fr" @@ -73,7 +73,7 @@ func testAccOutscaleDHCPOptionsDatasourceConfigBasic(value string) string { `, value) } -func testAccOutscaleDHCPOptionsDatasourceConfigWithFilters(value string) string { +func testAccDHCPOptionsDatasourceConfigWithFilters(value string) string { return fmt.Sprintf(` resource "outscale_dhcp_option" "foo1" { domain_name = "test.fr" diff --git a/outscale/data_source_outscale_flexible_gpu.go b/outscale/data_source_outscale_flexible_gpu.go index c870a94b7..fd9aaab9b 100644 --- a/outscale/data_source_outscale_flexible_gpu.go +++ b/outscale/data_source_outscale_flexible_gpu.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIFlexibleGpu() *schema.Resource { +func dataSourceFlexibleGpu() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIFlexibleGpuRead, + Read: dataSourceFlexibleGpuRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "request_id": { @@ -55,9 +55,9 @@ func dataSourceOutscaleOAPIFlexibleGpu() *schema.Resource { } } -func dataSourceOutscaleOAPIFlexibleGpuRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceFlexibleGpuRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") flexID, IDOk := d.GetOk("flexible_gpu_id") @@ -72,7 +72,7 @@ func dataSourceOutscaleOAPIFlexibleGpuRead(d *schema.ResourceData, meta interfac FlexibleGpuIds: &[]string{flexID.(string)}, } - req.SetFilters(buildOutscaleOAPIDataSourceFlexibleGpuFilters(filters.(*schema.Set))) + req.SetFilters(buildDataSourceFlexibleGpuFilters(filters.(*schema.Set))) var resp oscgo.ReadFlexibleGpusResponse var err error @@ -122,7 +122,7 @@ func dataSourceOutscaleOAPIFlexibleGpuRead(d *schema.ResourceData, meta interfac return nil } -func buildOutscaleOAPIDataSourceFlexibleGpuFilters(set *schema.Set) oscgo.FiltersFlexibleGpu { +func buildDataSourceFlexibleGpuFilters(set *schema.Set) oscgo.FiltersFlexibleGpu { var filters oscgo.FiltersFlexibleGpu for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_flexible_gpu_catalog.go b/outscale/data_source_outscale_flexible_gpu_catalog.go index bf4e99ee0..fb41fdcf0 100644 --- a/outscale/data_source_outscale_flexible_gpu_catalog.go +++ b/outscale/data_source_outscale_flexible_gpu_catalog.go @@ -11,9 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIFlexibleGpuCatalog() *schema.Resource { +func dataSourceFlexibleGpuCatalog() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIFlexibleGpuCatalogRead, + Read: dataSourceFlexibleGpuCatalogRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "flexible_gpu_catalog": { @@ -53,8 +53,8 @@ func dataSourceOutscaleOAPIFlexibleGpuCatalog() *schema.Resource { } } -func dataSourceOutscaleOAPIFlexibleGpuCatalogRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceFlexibleGpuCatalogRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadFlexibleGpuCatalogRequest{} diff --git a/outscale/data_source_outscale_flexible_gpu_catalog_test.go b/outscale/data_source_outscale_flexible_gpu_catalog_test.go index bd6a138ee..3273099b1 100644 --- a/outscale/data_source_outscale_flexible_gpu_catalog_test.go +++ b/outscale/data_source_outscale_flexible_gpu_catalog_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIFlexibleGpuCatalog_basic(t *testing.T) { +func TestAccDataSourceFlexibleGpuCatalog_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -16,13 +16,13 @@ func TestAccDataSourceOutscaleOAPIFlexibleGpuCatalog_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIFlexibleGpuCatalogConfig(), + Config: testAccDataSourceFlexibleGpuCatalogConfig(), }, }, }) } -func testAccDataSourceOutscaleOAPIFlexibleGpuCatalogConfig() string { +func testAccDataSourceFlexibleGpuCatalogConfig() string { return fmt.Sprintf(` data "outscale_flexible_gpu_catalog" "catalog-fGPU" { } `) diff --git a/outscale/data_source_outscale_flexible_gpu_test.go b/outscale/data_source_outscale_flexible_gpu_test.go index 0affcbf40..9a86ed96f 100644 --- a/outscale/data_source_outscale_flexible_gpu_test.go +++ b/outscale/data_source_outscale_flexible_gpu_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIFlexibleGpu_basic(t *testing.T) { +func TestAccDataSourceFlexibleGpu_basic(t *testing.T) { t.Parallel() region := fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) @@ -19,13 +19,13 @@ func TestAccDataSourceOutscaleOAPIFlexibleGpu_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIFlexibleGpuConfig(region, region), + Config: testAccDataSourceFlexibleGpuConfig(region, region), }, }, }) } -func testAccDataSourceOutscaleOAPIFlexibleGpuConfig(region, region1 string) string { +func testAccDataSourceFlexibleGpuConfig(region, region1 string) string { return fmt.Sprintf(` resource "outscale_flexible_gpu" "fGPU-1" { model_name = "nvidia-k2" diff --git a/outscale/data_source_outscale_flexible_gpus.go b/outscale/data_source_outscale_flexible_gpus.go index 9e4954fcc..ee7519bdb 100644 --- a/outscale/data_source_outscale_flexible_gpus.go +++ b/outscale/data_source_outscale_flexible_gpus.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIFlexibleGpus() *schema.Resource { +func dataSourceFlexibleGpus() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIFlexibleGpusRead, + Read: dataSourceFlexibleGpusRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -62,9 +62,9 @@ func dataSourceOutscaleOAPIFlexibleGpus() *schema.Resource { } } -func dataSourceOutscaleOAPIFlexibleGpusRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceFlexibleGpusRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") _, IDOk := d.GetOk("flexible_gpu_id") @@ -73,7 +73,7 @@ func dataSourceOutscaleOAPIFlexibleGpusRead(d *schema.ResourceData, meta interfa } req := oscgo.ReadFlexibleGpusRequest{} - req.SetFilters(buildOutscaleOAPIDataSourceFlexibleGpuFilters(filters.(*schema.Set))) + req.SetFilters(buildDataSourceFlexibleGpuFilters(filters.(*schema.Set))) var resp oscgo.ReadFlexibleGpusResponse var err error @@ -101,10 +101,10 @@ func dataSourceOutscaleOAPIFlexibleGpusRead(d *schema.ResourceData, meta interfa d.SetId(resource.UniqueId()) - return setOAPIFlexibleGpuAttributes(d, flexgps) + return setFlexibleGpuAttributes(d, flexgps) } -func setOAPIFlexibleGpuAttributes(d *schema.ResourceData, fg []oscgo.FlexibleGpu) error { +func setFlexibleGpuAttributes(d *schema.ResourceData, fg []oscgo.FlexibleGpu) error { fgpus := make([]map[string]interface{}, len(fg)) for k, v := range fg { diff --git a/outscale/data_source_outscale_flexible_gpus_test.go b/outscale/data_source_outscale_flexible_gpus_test.go index 06fcdbf88..be7fe9bef 100644 --- a/outscale/data_source_outscale_flexible_gpus_test.go +++ b/outscale/data_source_outscale_flexible_gpus_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIFlexibleGpus_basic(t *testing.T) { +func TestAccDataSourceFlexibleGpus_basic(t *testing.T) { t.Parallel() region := fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) @@ -19,13 +19,13 @@ func TestAccDataSourceOutscaleOAPIFlexibleGpus_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIFlexibleGpusConfig(region, region), + Config: testAccDataSourceFlexibleGpusConfig(region, region), }, }, }) } -func testAccDataSourceOutscaleOAPIFlexibleGpusConfig(region, region1 string) string { +func testAccDataSourceFlexibleGpusConfig(region, region1 string) string { return fmt.Sprintf(` resource "outscale_flexible_gpu" "fGPU-1" { model_name = "nvidia-k2" diff --git a/outscale/data_source_outscale_image.go b/outscale/data_source_outscale_image.go index 8878ae387..22c679dea 100644 --- a/outscale/data_source_outscale_image.go +++ b/outscale/data_source_outscale_image.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIImage() *schema.Resource { +func dataSourceImage() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIImageRead, + Read: dataSourceImageRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -194,8 +194,8 @@ func dataSourceOutscaleOAPIImage() *schema.Resource { } } -func dataSourceOutscaleOAPIImageRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceImageRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") executableUsers, executableUsersOk := d.GetOk("permission") @@ -207,7 +207,7 @@ func dataSourceOutscaleOAPIImageRead(d *schema.ResourceData, meta interface{}) e filtersReq := &oscgo.FiltersImage{} if filtersOk { - filtersReq = buildOutscaleOAPIDataSourceImagesFilters(filters.(*schema.Set)) + filtersReq = buildDataSourceImagesFilters(filters.(*schema.Set)) } if imageIDOk { filtersReq.SetImageIds([]string{imageID.(string)}) @@ -284,19 +284,19 @@ func dataSourceOutscaleOAPIImageRead(d *schema.ResourceData, meta interface{}) e if err := set("state", image.State); err != nil { return err } - if err := set("block_device_mappings", omiOAPIBlockDeviceMappings(*image.BlockDeviceMappings)); err != nil { + if err := set("block_device_mappings", omiBlockDeviceMappings(*image.BlockDeviceMappings)); err != nil { return err } if err := set("product_codes", image.ProductCodes); err != nil { return err } - if err := set("state_comment", omiOAPIStateReason(image.StateComment)); err != nil { + if err := set("state_comment", omiStateReason(image.StateComment)); err != nil { return err } - if err := set("permissions_to_launch", omiOAPIPermissionToLuch(image.PermissionsToLaunch)); err != nil { + if err := set("permissions_to_launch", omiPermissionToLuch(image.PermissionsToLaunch)); err != nil { return err } - if err := set("tags", getOapiTagSet(image.Tags)); err != nil { + if err := set("tags", getTagSet(image.GetTags())); err != nil { return err } @@ -304,7 +304,7 @@ func dataSourceOutscaleOAPIImageRead(d *schema.ResourceData, meta interface{}) e }) } -func omiOAPIPermissionToLuch(p *oscgo.PermissionsOnResource) (res []map[string]interface{}) { +func omiPermissionToLuch(p *oscgo.PermissionsOnResource) (res []map[string]interface{}) { for _, v := range *p.AccountIds { res = append(res, map[string]interface{}{ "account_id": v, diff --git a/outscale/data_source_outscale_image_export_task.go b/outscale/data_source_outscale_image_export_task.go index 578d52041..f2bd23210 100644 --- a/outscale/data_source_outscale_image_export_task.go +++ b/outscale/data_source_outscale_image_export_task.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIImageExportTask() *schema.Resource { +func dataSourceImageExportTask() *schema.Resource { return &schema.Resource{ - Read: dataSourceOAPISnapshotImageTaskRead, + Read: dataSourceSnapshotImageTaskRead, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -86,14 +86,14 @@ func dataSourceOutscaleOAPIImageExportTask() *schema.Resource { } } -func dataSourceOAPISnapshotImageTaskRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSnapshotImageTaskRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") filtersReq := &oscgo.FiltersExportTask{} if filtersOk { - filtersReq = buildOutscaleOSCAPIDataSourceImageExportTaskFilters(filters.(*schema.Set)) + filtersReq = buildDataSourceImageExportTaskFilters(filters.(*schema.Set)) } var resp oscgo.ReadImageExportTasksResponse @@ -152,7 +152,7 @@ func dataSourceOAPISnapshotImageTaskRead(d *schema.ResourceData, meta interface{ if err = d.Set("osu_export", exp); err != nil { return err } - if err = d.Set("tags", tagsOSCAPIToMap(v.GetTags())); err != nil { + if err = d.Set("tags", tagsToMap(v.GetTags())); err != nil { return err } d.SetId(v.GetTaskId()) @@ -160,7 +160,7 @@ func dataSourceOAPISnapshotImageTaskRead(d *schema.ResourceData, meta interface{ return nil } -func buildOutscaleOSCAPIDataSourceImageExportTaskFilters(set *schema.Set) *oscgo.FiltersExportTask { +func buildDataSourceImageExportTaskFilters(set *schema.Set) *oscgo.FiltersExportTask { var filters oscgo.FiltersExportTask for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_image_export_task_test.go b/outscale/data_source_outscale_image_export_task_test.go index 2c56b61fc..ba6cbb387 100644 --- a/outscale/data_source_outscale_image_export_task_test.go +++ b/outscale/data_source_outscale_image_export_task_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIImageExportTaskDataSource_basic(t *testing.T) { +func TestAccImageExportTaskDataSource_basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") imageName := acctest.RandomWithPrefix("test-image-name") @@ -24,9 +24,9 @@ func TestAccOutscaleOAPIImageExportTaskDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIImageExportTaskDataSourceConfig(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccImageExportTaskDataSourceConfig(omi, "tinav4.c2r2p2", region, imageName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleImageExportTaskDataSourceID("data.outscale_image_export_task.test"), + testAccCheckImageExportTaskDataSourceID("data.outscale_image_export_task.test"), ), }, }, @@ -36,7 +36,7 @@ func TestAccOutscaleOAPIImageExportTaskDataSource_basic(t *testing.T) { } } -func testAccCheckOutscaleImageExportTaskDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckImageExportTaskDataSourceID(n string) resource.TestCheckFunc { // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -51,7 +51,7 @@ func testAccCheckOutscaleImageExportTaskDataSourceID(n string) resource.TestChec } } -func testAccOutscaleOAPIImageExportTaskDataSourceConfig(omi, vmType, region, imageName string) string { +func testAccImageExportTaskDataSourceConfig(omi, vmType, region, imageName string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%s" diff --git a/outscale/data_source_outscale_image_export_tasks.go b/outscale/data_source_outscale_image_export_tasks.go index dd471f430..b3d2af24f 100644 --- a/outscale/data_source_outscale_image_export_tasks.go +++ b/outscale/data_source_outscale_image_export_tasks.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIImageExportTasks() *schema.Resource { +func dataSourceImageExportTasks() *schema.Resource { return &schema.Resource{ - Read: dataSourceOAPIImageExportTasksRead, + Read: dataSourceImageExportTasksRead, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -93,14 +93,14 @@ func dataSourceOutscaleOAPIImageExportTasks() *schema.Resource { } } -func dataSourceOAPIImageExportTasksRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceImageExportTasksRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") filtersReq := &oscgo.FiltersExportTask{} if filtersOk { - filtersReq = buildOutscaleOSCAPIDataSourceImageExportTaskFilters(filters.(*schema.Set)) + filtersReq = buildDataSourceImageExportTaskFilters(filters.(*schema.Set)) } var resp oscgo.ReadImageExportTasksResponse @@ -151,7 +151,7 @@ func dataSourceOAPIImageExportTasksRead(d *schema.ResourceData, meta interface{} snapshot["image_id"] = v.GetImageId() snapshot["osu_export"] = exp - snapshot["tags"] = tagsOSCAPIToMap(v.GetTags()) + snapshot["tags"] = tagsToMap(v.GetTags()) snapshots[k] = snapshot } diff --git a/outscale/data_source_outscale_image_export_tasks_test.go b/outscale/data_source_outscale_image_export_tasks_test.go index baee706e0..0f8927fbe 100644 --- a/outscale/data_source_outscale_image_export_tasks_test.go +++ b/outscale/data_source_outscale_image_export_tasks_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIImageExportTasksDataSource_basic(t *testing.T) { +func TestAccImageExportTasksDataSource_basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") imageName := acctest.RandomWithPrefix("test-image-name") @@ -23,9 +23,9 @@ func TestAccOutscaleOAPIImageExportTasksDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIImageExportTasksDataSourceConfig(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccImageExportTasksDataSourceConfig(omi, "tinav4.c2r2p2", region, imageName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleImageExportTaskDataSourceID("outscale_image_export_task.outscale_image_export_task"), + testAccCheckImageExportTaskDataSourceID("outscale_image_export_task.outscale_image_export_task"), ), }, }, @@ -35,7 +35,7 @@ func TestAccOutscaleOAPIImageExportTasksDataSource_basic(t *testing.T) { } } -func testAccOutscaleOAPIImageExportTasksDataSourceConfig(omi, vmType, region, imageName string) string { +func testAccImageExportTasksDataSourceConfig(omi, vmType, region, imageName string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%s" diff --git a/outscale/data_source_outscale_image_test.go b/outscale/data_source_outscale_image_test.go index 6d14b2437..853951c12 100644 --- a/outscale/data_source_outscale_image_test.go +++ b/outscale/data_source_outscale_image_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIImageDataSource_Instance(t *testing.T) { +func TestAccImageDataSource_Instance(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -23,9 +23,9 @@ func TestAccOutscaleOAPIImageDataSource_Instance(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIImageConfigBasic(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccCheckImageConfigBasic(omi, "tinav4.c2r2p2", region, imageName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIImageDataSourceID("data.outscale_image.nat_ami"), + testAccCheckImageDataSourceID("data.outscale_image.nat_ami"), resource.TestCheckResourceAttr("data.outscale_image.nat_ami", "architecture", "x86_64"), ), }, @@ -33,7 +33,7 @@ func TestAccOutscaleOAPIImageDataSource_Instance(t *testing.T) { }) } -func TestAccOutscaleOAPIImageDataSource_basic(t *testing.T) { +func TestAccImageDataSource_basic(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -46,16 +46,16 @@ func TestAccOutscaleOAPIImageDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIImageDataSourceBasicConfig(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccCheckImageDataSourceBasicConfig(omi, "tinav4.c2r2p2", region, imageName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIImageDataSourceID("data.outscale_image.omi"), + testAccCheckImageDataSourceID("data.outscale_image.omi"), ), }, }, }) } -func testAccCheckOutscaleOAPIImageDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckImageDataSourceID(n string) resource.TestCheckFunc { // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -70,7 +70,7 @@ func testAccCheckOutscaleOAPIImageDataSourceID(n string) resource.TestCheckFunc } } -func testAccCheckOutscaleOAPIImageDataSourceBasicConfig(omi, vmType, region, imageName string) string { +func testAccCheckImageDataSourceBasicConfig(omi, vmType, region, imageName string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%[1]s" @@ -93,7 +93,7 @@ func testAccCheckOutscaleOAPIImageDataSourceBasicConfig(omi, vmType, region, ima `, omi, vmType, region, imageName) } -func testAccCheckOutscaleOAPIImageConfigBasic(omi, vmType, region, imageName string) string { +func testAccCheckImageConfigBasic(omi, vmType, region, imageName string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%[1]s" diff --git a/outscale/data_source_outscale_images.go b/outscale/data_source_outscale_images.go index 5b71e467f..f290fb7da 100644 --- a/outscale/data_source_outscale_images.go +++ b/outscale/data_source_outscale_images.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIImages() *schema.Resource { +func dataSourceImages() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIImagesRead, + Read: dataSourceImagesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -211,8 +211,8 @@ func dataSourceOutscaleOAPIImages() *schema.Resource { } } -func dataSourceOutscaleOAPIImagesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceImagesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI executableUsers, executableUsersOk := d.GetOk("permissions") filters, filtersOk := d.GetOk("filter") @@ -223,7 +223,7 @@ func dataSourceOutscaleOAPIImagesRead(d *schema.ResourceData, meta interface{}) filtersReq := &oscgo.FiltersImage{} if filtersOk { - filtersReq = buildOutscaleOAPIDataSourceImagesFilters(filters.(*schema.Set)) + filtersReq = buildDataSourceImagesFilters(filters.(*schema.Set)) } if ownersOk { filtersReq.SetAccountIds([]string{aids.(string)}) @@ -269,11 +269,11 @@ func dataSourceOutscaleOAPIImagesRead(d *schema.ResourceData, meta interface{}) "root_device_name": image.GetRootDeviceName(), "root_device_type": image.GetRootDeviceType(), "state": image.GetState(), - "block_device_mappings": omiOAPIBlockDeviceMappings(*image.BlockDeviceMappings), + "block_device_mappings": omiBlockDeviceMappings(*image.BlockDeviceMappings), "product_codes": image.GetProductCodes(), - "state_comment": omiOAPIStateReason(image.StateComment), - "permissions_to_launch": omiOAPIPermissionToLuch(image.PermissionsToLaunch), - "tags": getOapiTagSet(image.Tags), + "state_comment": omiStateReason(image.StateComment), + "permissions_to_launch": omiPermissionToLuch(image.PermissionsToLaunch), + "tags": getTagSet(image.GetTags()), } } @@ -281,7 +281,7 @@ func dataSourceOutscaleOAPIImagesRead(d *schema.ResourceData, meta interface{}) }) } -func buildOutscaleOAPIDataSourceImagesFilters(set *schema.Set) *oscgo.FiltersImage { +func buildDataSourceImagesFilters(set *schema.Set) *oscgo.FiltersImage { filters := &oscgo.FiltersImage{} for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_images_test.go b/outscale/data_source_outscale_images_test.go index ef9fb081f..67a365a86 100644 --- a/outscale/data_source_outscale_images_test.go +++ b/outscale/data_source_outscale_images_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIImagesDataSource_Instance(t *testing.T) { +func TestAccImagesDataSource_Instance(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -23,16 +23,16 @@ func TestAccOutscaleOAPIImagesDataSource_Instance(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIImagesDataSourceConfig(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccCheckImagesDataSourceConfig(omi, "tinav4.c2r2p2", region, imageName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIImagesDataSourceID("data.outscale_images.nat_ami"), + testAccCheckImagesDataSourceID("data.outscale_images.nat_ami"), ), }, }, }) } -func testAccCheckOutscaleOAPIImagesDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckImagesDataSourceID(n string) resource.TestCheckFunc { // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -47,7 +47,7 @@ func testAccCheckOutscaleOAPIImagesDataSourceID(n string) resource.TestCheckFunc } } -func testAccCheckOutscaleOAPIImagesDataSourceConfig(omi, vmType, region, imageName string) string { +func testAccCheckImagesDataSourceConfig(omi, vmType, region, imageName string) string { return fmt.Sprintf(` resource "outscale_vm" "basic_one" { image_id = "%[1]s" diff --git a/outscale/data_source_outscale_internet_service.go b/outscale/data_source_outscale_internet_service.go index daa1fb0ec..534ae483b 100644 --- a/outscale/data_source_outscale_internet_service.go +++ b/outscale/data_source_outscale_internet_service.go @@ -13,9 +13,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func datasourceOutscaleOAPIInternetService() *schema.Resource { +func dataSourceInternetService() *schema.Resource { return &schema.Resource{ - Read: datasourceOutscaleOAPIInternetServiceRead, + Read: dataSourceInternetServiceRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "state": { @@ -39,8 +39,8 @@ func datasourceOutscaleOAPIInternetService() *schema.Resource { } } -func datasourceOutscaleOAPIInternetServiceRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceInternetServiceRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") internetID, insternetIDOk := d.GetOk("internet_service_id") @@ -60,7 +60,7 @@ func datasourceOutscaleOAPIInternetServiceRead(d *schema.ResourceData, meta inte } if filtersOk { - params.Filters = buildOutscaleOSCAPIDataSourceInternetServiceFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceInternetServiceFilters(filters.(*schema.Set)) } var resp oscgo.ReadInternetServicesResponse @@ -101,10 +101,10 @@ func datasourceOutscaleOAPIInternetServiceRead(d *schema.ResourceData, meta inte d.SetId(result.GetInternetServiceId()) - return d.Set("tags", tagsOSCAPIToMap(result.GetTags())) + return d.Set("tags", tagsToMap(result.GetTags())) } -func buildOutscaleOSCAPIDataSourceInternetServiceFilters(set *schema.Set) *oscgo.FiltersInternetService { +func buildDataSourceInternetServiceFilters(set *schema.Set) *oscgo.FiltersInternetService { var filters oscgo.FiltersInternetService for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_internet_service_test.go b/outscale/data_source_outscale_internet_service_test.go index e06aa905b..f6d7329fa 100644 --- a/outscale/data_source_outscale_internet_service_test.go +++ b/outscale/data_source_outscale_internet_service_test.go @@ -6,14 +6,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIInternetServiceDatasource_basic(t *testing.T) { +func TestAccInternetServiceDatasource_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIInternetServiceDatasourceConfig, + Config: testAccInternetServiceDatasourceConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("data.outscale_internet_service.outscale_internet_serviced", "internet_service_id"), ), @@ -22,7 +22,7 @@ func TestAccOutscaleOAPIInternetServiceDatasource_basic(t *testing.T) { }) } -const testAccOutscaleOAPIInternetServiceDatasourceConfig = ` +const testAccInternetServiceDatasourceConfig = ` resource "outscale_internet_service" "outscale_internet_service" {} data "outscale_internet_service" "outscale_internet_serviced" { diff --git a/outscale/data_source_outscale_internet_services.go b/outscale/data_source_outscale_internet_services.go index 55aacf73d..a4554324b 100644 --- a/outscale/data_source_outscale_internet_services.go +++ b/outscale/data_source_outscale_internet_services.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func datasourceOutscaleOAPIInternetServices() *schema.Resource { +func dataSourceInternetServices() *schema.Resource { return &schema.Resource{ - Read: datasourceOutscaleOAPIInternetServicesRead, + Read: dataSourceInternetServicesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "internet_service_ids": { @@ -54,8 +54,8 @@ func datasourceOutscaleOAPIInternetServices() *schema.Resource { } } -func datasourceOutscaleOAPIInternetServicesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceInternetServicesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") internetID, internetIDOk := d.GetOk("internet_service_ids") @@ -78,7 +78,7 @@ func datasourceOutscaleOAPIInternetServicesRead(d *schema.ResourceData, meta int } if filtersOk { - params.Filters = buildOutscaleOSCAPIDataSourceInternetServiceFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceInternetServiceFilters(filters.(*schema.Set)) } var resp oscgo.ReadInternetServicesResponse @@ -105,10 +105,10 @@ func datasourceOutscaleOAPIInternetServicesRead(d *schema.ResourceData, meta int d.SetId(resource.UniqueId()) result := resp.GetInternetServices() - return internetServicesOAPIDescriptionAttributes(d, result) + return internetServicesDescriptionAttributes(d, result) } -func internetServicesOAPIDescriptionAttributes(d *schema.ResourceData, internetServices []oscgo.InternetService) error { +func internetServicesDescriptionAttributes(d *schema.ResourceData, internetServices []oscgo.InternetService) error { i := make([]map[string]interface{}, len(internetServices)) for k, v := range internetServices { @@ -124,7 +124,7 @@ func internetServicesOAPIDescriptionAttributes(d *schema.ResourceData, internetS im["internet_service_id"] = v.GetInternetServiceId() } if v.Tags != nil { - im["tags"] = tagsOSCAPIToMap(v.GetTags()) + im["tags"] = tagsToMap(v.GetTags()) } i[k] = im } diff --git a/outscale/data_source_outscale_internet_services_test.go b/outscale/data_source_outscale_internet_services_test.go index 0f77a91cf..8014589b7 100644 --- a/outscale/data_source_outscale_internet_services_test.go +++ b/outscale/data_source_outscale_internet_services_test.go @@ -6,20 +6,20 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIInternetServicesDatasource_basic(t *testing.T) { +func TestAccInternetServicesDatasource_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIInternetServicesDatasourceConfig, + Config: testAccInternetServicesDatasourceConfig, }, }, }) } -const testAccOutscaleOAPIInternetServicesDatasourceConfig = ` +const testAccInternetServicesDatasourceConfig = ` resource "outscale_internet_service" "gateway" {} data "outscale_internet_services" "outscale_internet_services" { diff --git a/outscale/data_source_outscale_keypair.go b/outscale/data_source_outscale_keypair.go index b52970b53..0def63962 100644 --- a/outscale/data_source_outscale_keypair.go +++ b/outscale/data_source_outscale_keypair.go @@ -13,8 +13,8 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func datasourceOutscaleOApiKeyPairRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceKeyPairRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadKeypairsRequest{ Filters: &oscgo.FiltersKeypair{KeypairNames: &[]string{d.Id()}}, } @@ -29,7 +29,7 @@ func datasourceOutscaleOApiKeyPairRead(d *schema.ResourceData, meta interface{}) filters, filtersOk := d.GetOk("filter") if filtersOk { - req.SetFilters(buildOutscaleOAPIKeyPairsDataSourceFilters(filters.(*schema.Set))) + req.SetFilters(buildKeyPairsDataSourceFilters(filters.(*schema.Set))) } var resp oscgo.ReadKeypairsResponse @@ -55,7 +55,7 @@ func datasourceOutscaleOApiKeyPairRead(d *schema.ResourceData, meta interface{}) } errString = err.Error() - return fmt.Errorf("Error retrieving OAPIKeyPair: %s", errString) + return fmt.Errorf("Error retrieving KeyPair: %s", errString) } if len(resp.GetKeypairs()) < 1 { @@ -78,9 +78,9 @@ func datasourceOutscaleOApiKeyPairRead(d *schema.ResourceData, meta interface{}) return nil } -func datasourceOutscaleOAPIKeyPair() *schema.Resource { +func dataSourceKeyPair() *schema.Resource { return &schema.Resource{ - Read: datasourceOutscaleOApiKeyPairRead, + Read: dataSourceKeyPairRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -102,7 +102,7 @@ func datasourceOutscaleOAPIKeyPair() *schema.Resource { } } -func buildOutscaleOAPIKeyPairsDataSourceFilters(set *schema.Set) oscgo.FiltersKeypair { +func buildKeyPairsDataSourceFilters(set *schema.Set) oscgo.FiltersKeypair { var filters oscgo.FiltersKeypair for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_keypair_test.go b/outscale/data_source_outscale_keypair_test.go index 116432790..498b39b69 100644 --- a/outscale/data_source_outscale_keypair_test.go +++ b/outscale/data_source_outscale_keypair_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIKeypairDataSource_Instance(t *testing.T) { +func TestAccKeypairDataSource_Instance(t *testing.T) { t.Parallel() keyPairName := fmt.Sprintf("acc-test-keypair-%d", acctest.RandIntRange(0, 400)) @@ -18,9 +18,9 @@ func TestAccOutscaleOAPIKeypairDataSource_Instance(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIKeypairDataSourceConfig(keyPairName), + Config: testAccCheckKeypairDataSourceConfig(keyPairName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIKeypairDataSourceID("data.outscale_keypair.nat_ami"), + testAccCheckKeypairDataSourceID("data.outscale_keypair.nat_ami"), resource.TestCheckResourceAttr("data.outscale_keypair.nat_ami", "keypair_name", keyPairName), ), }, @@ -28,7 +28,7 @@ func TestAccOutscaleOAPIKeypairDataSource_Instance(t *testing.T) { }) } -func testAccCheckOutscaleOAPIKeypairDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckKeypairDataSourceID(n string) resource.TestCheckFunc { // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -43,7 +43,7 @@ func testAccCheckOutscaleOAPIKeypairDataSourceID(n string) resource.TestCheckFun } } -func testAccCheckOutscaleOAPIKeypairDataSourceConfig(keypairName string) string { +func testAccCheckKeypairDataSourceConfig(keypairName string) string { return fmt.Sprintf(` resource "outscale_keypair" "a_key_pair" { keypair_name = "%s" diff --git a/outscale/data_source_outscale_keypairs.go b/outscale/data_source_outscale_keypairs.go index b7a6b93b7..7d36f8ebb 100644 --- a/outscale/data_source_outscale_keypairs.go +++ b/outscale/data_source_outscale_keypairs.go @@ -12,8 +12,8 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func datasourceOutscaleOAPiKeyPairsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceKeyPairsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadKeypairsRequest{ Filters: &oscgo.FiltersKeypair{}, } @@ -34,7 +34,7 @@ func datasourceOutscaleOAPiKeyPairsRead(d *schema.ResourceData, meta interface{} filters, filtersOk := d.GetOk("filter") if filtersOk { - req.SetFilters(buildOutscaleOAPIKeyPairsDataSourceFilters(filters.(*schema.Set))) + req.SetFilters(buildKeyPairsDataSourceFilters(filters.(*schema.Set))) } var resp oscgo.ReadKeypairsResponse @@ -60,7 +60,7 @@ func datasourceOutscaleOAPiKeyPairsRead(d *schema.ResourceData, meta interface{} } errString = err.Error() - return fmt.Errorf("Error retrieving OAPIKeyPair: %s", errString) + return fmt.Errorf("Error retrieving KeyPair: %s", errString) } if len(resp.GetKeypairs()) < 1 { @@ -84,9 +84,9 @@ func datasourceOutscaleOAPiKeyPairsRead(d *schema.ResourceData, meta interface{} return d.Set("keypairs", keypairs) } -func datasourceOutscaleOAPIKeyPairs() *schema.Resource { +func dataSourceKeyPairs() *schema.Resource { return &schema.Resource{ - Read: datasourceOutscaleOAPiKeyPairsRead, + Read: dataSourceKeyPairsRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), diff --git a/outscale/data_source_outscale_keypairs_test.go b/outscale/data_source_outscale_keypairs_test.go index 2578a0083..1bc8e7e7d 100644 --- a/outscale/data_source_outscale_keypairs_test.go +++ b/outscale/data_source_outscale_keypairs_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIKeypairsDataSource_Instance(t *testing.T) { +func TestAccKeypairsDataSource_Instance(t *testing.T) { t.Parallel() keyPairName := fmt.Sprintf("testacc-keypair-%d", acctest.RandIntRange(0, 400)) resource.Test(t, resource.TestCase{ @@ -17,9 +17,9 @@ func TestAccOutscaleOAPIKeypairsDataSource_Instance(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIKeypairsDataSourceConfig(keyPairName), + Config: testAccCheckKeypairsDataSourceConfig(keyPairName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIKeypairsDataSourceID("data.outscale_keypairs.nat_ami"), + testAccCheckKeypairsDataSourceID("data.outscale_keypairs.nat_ami"), resource.TestCheckResourceAttr("data.outscale_keypairs.nat_ami", "keypairs.0.keypair_name", keyPairName), ), }, @@ -27,7 +27,7 @@ func TestAccOutscaleOAPIKeypairsDataSource_Instance(t *testing.T) { }) } -func testAccCheckOutscaleOAPIKeypairsDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckKeypairsDataSourceID(n string) resource.TestCheckFunc { // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -42,7 +42,7 @@ func testAccCheckOutscaleOAPIKeypairsDataSourceID(n string) resource.TestCheckFu } } -func testAccCheckOutscaleOAPIKeypairsDataSourceConfig(keyPairName string) string { +func testAccCheckKeypairsDataSourceConfig(keyPairName string) string { return fmt.Sprintf(` resource "outscale_keypair" "a_key_pair" { keypair_name = "%s" diff --git a/outscale/data_source_outscale_load_balancer.go b/outscale/data_source_outscale_load_balancer.go index 850f36537..87fbc25fb 100644 --- a/outscale/data_source_outscale_load_balancer.go +++ b/outscale/data_source_outscale_load_balancer.go @@ -43,7 +43,7 @@ func attrLBchema() map[string]*schema.Schema { Elem: &schema.Schema{Type: schema.TypeString}, }, "source_security_group": lb_sg_schema(), - "tags": tagsListOAPISchema2(true), + "tags": tagsListSchema2(true), "dns_name": { Type: schema.TypeString, Computed: true, @@ -179,14 +179,14 @@ func getDataSourceSchemas(attrsSchema map[string]*schema.Schema) map[string]*sch } -func dataSourceOutscaleOAPILoadBalancer() *schema.Resource { +func dataSourceLoadBalancer() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPILoadBalancerRead, + Read: dataSourceLoadBalancerRead, Schema: getDataSourceSchemas(attrLBchema()), } } -func buildOutscaleDataSourceLBFilters(set *schema.Set) *oscgo.FiltersLoadBalancer { +func buildDataSourceLBFilters(set *schema.Set) *oscgo.FiltersLoadBalancer { filters := new(oscgo.FiltersLoadBalancer) for _, v := range set.List() { @@ -221,7 +221,7 @@ func readLbs_(conn *oscgo.APIClient, d *schema.ResourceData, t schema.ValueType) } if filtersOk { - filter = buildOutscaleDataSourceLBFilters(filters.(*schema.Set)) + filter = buildDataSourceLBFilters(filters.(*schema.Set)) } else if t == schema.TypeString { elbName := ename.(string) filter = &oscgo.FiltersLoadBalancer{ @@ -277,8 +277,8 @@ func readLbs0(conn *oscgo.APIClient, d *schema.ResourceData) (*oscgo.LoadBalance return &lbs[0], resp, nil } -func dataSourceOutscaleOAPILoadBalancerRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceLoadBalancerRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI lb, _, err := readLbs0(conn, d) @@ -288,11 +288,11 @@ func dataSourceOutscaleOAPILoadBalancerRead(d *schema.ResourceData, meta interfa d.Set("subregion_names", flattenStringList(lb.SubregionNames)) d.Set("dns_name", lb.DnsName) - d.Set("health_check", flattenOAPIHealthCheck(lb.HealthCheck)) - d.Set("access_log", flattenOAPIAccessLog(lb.AccessLog)) + d.Set("health_check", flattenHealthCheck(lb.HealthCheck)) + d.Set("access_log", flattenAccessLog(lb.AccessLog)) d.Set("backend_vm_ids", flattenStringList(lb.BackendVmIds)) - if err := d.Set("listeners", flattenOAPIListeners(lb.Listeners)); err != nil { + if err := d.Set("listeners", flattenListeners(lb.Listeners)); err != nil { return err } d.Set("load_balancer_name", lb.LoadBalancerName) diff --git a/outscale/data_source_outscale_load_balancer_listener_rule.go b/outscale/data_source_outscale_load_balancer_listener_rule.go index d5c2fe4b3..3d3162a8e 100644 --- a/outscale/data_source_outscale_load_balancer_listener_rule.go +++ b/outscale/data_source_outscale_load_balancer_listener_rule.go @@ -56,15 +56,15 @@ func attrLBListenerRule() map[string]*schema.Schema { } } -func dataSourceOutscaleOAPILoadBalancerLDRule() *schema.Resource { +func dataSourceLoadBalancerLDRule() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPILoadBalancerLDRuleRead, + Read: dataSourceLoadBalancerLDRuleRead, Schema: getDataSourceSchemas(attrLBListenerRule()), } } -func dataSourceOutscaleOAPILoadBalancerLDRuleRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceLoadBalancerLDRuleRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI lrNamei, nameOk := d.GetOk("listener_rule_name") filters, filtersOk := d.GetOk("filter") diff --git a/outscale/data_source_outscale_load_balancer_listener_rules.go b/outscale/data_source_outscale_load_balancer_listener_rules.go index 29314ce0b..59499721b 100644 --- a/outscale/data_source_outscale_load_balancer_listener_rules.go +++ b/outscale/data_source_outscale_load_balancer_listener_rules.go @@ -64,15 +64,15 @@ func attrLBListenerRules() map[string]*schema.Schema { } } -func dataSourceOutscaleOAPILoadBalancerLDRules() *schema.Resource { +func dataSourceLoadBalancerLDRules() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPILoadBalancerLDRulesRead, + Read: dataSourceLoadBalancerLDRulesRead, Schema: getDataSourceSchemas(attrLBListenerRules()), } } -func dataSourceOutscaleOAPILoadBalancerLDRulesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceLoadBalancerLDRulesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI lrNamei, nameOk := d.GetOk("listener_rule_name") filters, filtersOk := d.GetOk("filter") diff --git a/outscale/data_source_outscale_load_balancer_tags.go b/outscale/data_source_outscale_load_balancer_tags.go index ddd52c047..109c1bb0f 100644 --- a/outscale/data_source_outscale_load_balancer_tags.go +++ b/outscale/data_source_outscale_load_balancer_tags.go @@ -12,16 +12,16 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPILBUTags() *schema.Resource { +func dataSourceLBUTags() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPILBUTagsRead, + Read: dataSourceLBUTagsRead, - Schema: getDataSourceSchemas(getDSOAPILBUTagsSchema()), + Schema: getDataSourceSchemas(getDSLBUTagsSchema()), } } -func dataSourceOutscaleOAPILBUTagsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceLBUTagsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI ename, nameOk := d.GetOk("load_balancer_names") if !nameOk { @@ -69,7 +69,7 @@ func dataSourceOutscaleOAPILBUTagsRead(d *schema.ResourceData, meta interface{}) return nil } -func getDSOAPILBUTagsSchema() map[string]*schema.Schema { +func getDSLBUTagsSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ "load_balancer_names": { Type: schema.TypeList, diff --git a/outscale/data_source_outscale_load_balancer_tags_test.go b/outscale/data_source_outscale_load_balancer_tags_test.go index a80544afb..25a47ad02 100644 --- a/outscale/data_source_outscale_load_balancer_tags_test.go +++ b/outscale/data_source_outscale_load_balancer_tags_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIDSLoadBalancerTags_basic(t *testing.T) { +func TestAccDSLoadBalancerTags_basic(t *testing.T) { t.Parallel() r := acctest.RandString(4) region := os.Getenv("OUTSCALE_REGION") @@ -23,9 +23,9 @@ func TestAccOutscaleOAPIDSLoadBalancerTags_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: getTestAccDSODSutscaleOAPILBUDSTagsConfig(r, zone), + Config: getTestAccDSODSutscaleLBUDSTagsConfig(r, zone), Check: resource.ComposeTestCheckFunc( - testAccCheckODSutscaleOAPILBUDSTagsExists("data.outscale_load_balancer_tags.testds"), + testAccCheckODSutscaleLBUDSTagsExists("data.outscale_load_balancer_tags.testds"), resource.TestCheckResourceAttr( "data.outscale_load_balancer_tags.testds", "tags.#", "1"), )}, @@ -33,7 +33,7 @@ func TestAccOutscaleOAPIDSLoadBalancerTags_basic(t *testing.T) { }) } -func testAccCheckODSutscaleOAPILBUDSTagsExists(n string) resource.TestCheckFunc { +func testAccCheckODSutscaleLBUDSTagsExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -48,7 +48,7 @@ func testAccCheckODSutscaleOAPILBUDSTagsExists(n string) resource.TestCheckFunc } } -func getTestAccDSODSutscaleOAPILBUDSTagsConfig(r string, zone string) string { +func getTestAccDSODSutscaleLBUDSTagsConfig(r string, zone string) string { return fmt.Sprintf(` resource "outscale_load_balancer" "bar" { subregion_names = ["%s"] diff --git a/outscale/data_source_outscale_load_balancer_test.go b/outscale/data_source_outscale_load_balancer_test.go index de82d02ec..645aae0dc 100644 --- a/outscale/data_source_outscale_load_balancer_test.go +++ b/outscale/data_source_outscale_load_balancer_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIDSLBU_basic(t *testing.T) { +func TestAccDSLBU_basic(t *testing.T) { t.Parallel() var conf oscgo.LoadBalancer @@ -22,12 +22,12 @@ func TestAccOutscaleOAPIDSLBU_basic(t *testing.T) { }, IDRefreshName: "outscale_load_balancer.bar", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPILBUDestroy, + CheckDestroy: testAccCheckLBUDestroy, Steps: []resource.TestStep{ { - Config: testAccDSOutscaleOAPILBUConfig(zone), + Config: testAccDSLBUConfig(zone), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILBUExists("outscale_load_balancer.bar", &conf), + testAccCheckLBUExists("outscale_load_balancer.bar", &conf), resource.TestCheckResourceAttr( "data.outscale_load_balancer.test", "subregion_names.#", "1"), resource.TestCheckResourceAttr( @@ -37,7 +37,7 @@ func TestAccOutscaleOAPIDSLBU_basic(t *testing.T) { }) } -func testAccDSOutscaleOAPILBUConfig(zone string) string { +func testAccDSLBUConfig(zone string) string { return fmt.Sprintf(` resource "outscale_load_balancer" "bar" { subregion_names = ["%s"] diff --git a/outscale/data_source_outscale_load_balancer_vm_health.go b/outscale/data_source_outscale_load_balancer_vm_health.go index fd0418f37..6bbefe29a 100644 --- a/outscale/data_source_outscale_load_balancer_vm_health.go +++ b/outscale/data_source_outscale_load_balancer_vm_health.go @@ -15,9 +15,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleLoadBalancerVmsHeals() *schema.Resource { +func dataSourceLoadBalancerVmsHeals() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleLoadBalancerVmsHealRead, + Read: dataSourceLoadBalancerVmsHealRead, Schema: getDataSourceSchemas(map[string]*schema.Schema{ "load_balancer_name": { Type: schema.TypeString, @@ -63,9 +63,9 @@ func dataSourceOutscaleLoadBalancerVmsHeals() *schema.Resource { } } -func dataSourceOutscaleLoadBalancerVmsHealRead(d *schema.ResourceData, +func dataSourceLoadBalancerVmsHealRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI ename, ok := d.GetOk("load_balancer_name") if ok == false { diff --git a/outscale/data_source_outscale_load_balancer_vms.go b/outscale/data_source_outscale_load_balancer_vms.go index 043dbb8d1..296469566 100644 --- a/outscale/data_source_outscale_load_balancer_vms.go +++ b/outscale/data_source_outscale_load_balancer_vms.go @@ -4,9 +4,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func dataSourceOutscaleLoadBalancerVms() *schema.Resource { +func dataSourceLoadBalancerVms() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleLoadBalancerVmsRead, + Read: dataSourceLoadBalancerVmsRead, Schema: getDataSourceSchemas(map[string]*schema.Schema{ "load_balancer_name": { Type: schema.TypeString, @@ -28,9 +28,9 @@ func dataSourceOutscaleLoadBalancerVms() *schema.Resource { } } -func dataSourceOutscaleLoadBalancerVmsRead(d *schema.ResourceData, +func dataSourceLoadBalancerVmsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI lb, _, err := readLbs0(conn, d) if err != nil { diff --git a/outscale/data_source_outscale_load_balancers.go b/outscale/data_source_outscale_load_balancers.go index ee7c53fcf..7bc14d7e3 100644 --- a/outscale/data_source_outscale_load_balancers.go +++ b/outscale/data_source_outscale_load_balancers.go @@ -141,7 +141,7 @@ func attrLBSchema() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema2(true), + "tags": tagsListSchema2(true), "security_groups": { Type: schema.TypeList, Computed: true, @@ -190,16 +190,16 @@ func attrLBSchema() map[string]*schema.Schema { } } -func dataSourceOutscaleOAPILoadBalancers() *schema.Resource { +func dataSourceLoadBalancers() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPILoadBalancersRead, + Read: dataSourceLoadBalancersRead, Schema: getDataSourceSchemas(attrLBSchema()), } } -func dataSourceOutscaleOAPILoadBalancersRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceLoadBalancersRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI resp, _, err := readLbs_(conn, d, schema.TypeList) if err != nil { @@ -216,11 +216,11 @@ func dataSourceOutscaleOAPILoadBalancersRead(d *schema.ResourceData, meta interf l["subregion_names"] = v.SubregionNames l["dns_name"] = *v.DnsName - l["access_log"] = flattenOAPIAccessLog(v.AccessLog) - l["health_check"] = flattenOAPIHealthCheck(v.HealthCheck) + l["access_log"] = flattenAccessLog(v.AccessLog) + l["health_check"] = flattenHealthCheck(v.HealthCheck) l["backend_vm_ids"] = flattenStringList(v.BackendVmIds) if v.Listeners != nil { - l["listeners"] = flattenOAPIListeners(v.Listeners) + l["listeners"] = flattenListeners(v.Listeners) } else { l["listeners"] = make([]interface{}, 0) } diff --git a/outscale/data_source_outscale_load_balancers_test.go b/outscale/data_source_outscale_load_balancers_test.go index 818bca60c..56fb88f5d 100644 --- a/outscale/data_source_outscale_load_balancers_test.go +++ b/outscale/data_source_outscale_load_balancers_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIDSLBSU_basic(t *testing.T) { +func TestAccDSLBSU_basic(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") zone := fmt.Sprintf("%sa", region) @@ -21,10 +21,10 @@ func TestAccOutscaleOAPIDSLBSU_basic(t *testing.T) { }, IDRefreshName: "outscale_load_balancer.bar", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPILBUDestroy, + CheckDestroy: testAccCheckLBUDestroy, Steps: []resource.TestStep{ { - Config: testAccDSOutscaleOAPILBsUConfig(zone, numLbu), + Config: testAccDSLBsUConfig(zone, numLbu), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_load_balancers.test", "load_balancer.#", "1"), )}, @@ -32,7 +32,7 @@ func TestAccOutscaleOAPIDSLBSU_basic(t *testing.T) { }) } -func testAccDSOutscaleOAPILBsUConfig(zone string, numLbu int) string { +func testAccDSLBsUConfig(zone string, numLbu int) string { return fmt.Sprintf(` resource "outscale_load_balancer" "bar" { subregion_names = ["%s"] diff --git a/outscale/data_source_outscale_nat_service.go b/outscale/data_source_outscale_nat_service.go index 56e73c880..69ae9cd56 100644 --- a/outscale/data_source_outscale_nat_service.go +++ b/outscale/data_source_outscale_nat_service.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPINatService() *schema.Resource { +func dataSourceNatService() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPINatServiceRead, + Read: dataSourceNatServiceRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -61,8 +61,8 @@ func dataSourceOutscaleOAPINatService() *schema.Resource { } } -func dataSourceOutscaleOAPINatServiceRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceNatServiceRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") natGatewayID, natGatewayIDOK := d.GetOk("nat_service_id") @@ -74,7 +74,7 @@ func dataSourceOutscaleOAPINatServiceRead(d *schema.ResourceData, meta interface params := oscgo.ReadNatServicesRequest{} if filtersOk { - params.SetFilters(buildOutscaleOAPINatServiceDataSourceFilters(filters.(*schema.Set))) + params.SetFilters(buildNatServiceDataSourceFilters(filters.(*schema.Set))) } if natGatewayIDOK && natGatewayID.(string) != "" { filter := oscgo.FiltersNatService{} @@ -110,11 +110,11 @@ func dataSourceOutscaleOAPINatServiceRead(d *schema.ResourceData, meta interface "specific search criteria") } - return ngOAPIDescriptionAttributes(d, resp.GetNatServices()[0]) + return ngDescriptionAttributes(d, resp.GetNatServices()[0]) } // populate the numerous fields that the image description returns. -func ngOAPIDescriptionAttributes(d *schema.ResourceData, ng oscgo.NatService) error { +func ngDescriptionAttributes(d *schema.ResourceData, ng oscgo.NatService) error { d.SetId(ng.GetNatServiceId()) @@ -156,14 +156,14 @@ func ngOAPIDescriptionAttributes(d *schema.ResourceData, ng oscgo.NatService) er if err := d.Set("public_ips", addresses); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(ng.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(ng.GetTags())); err != nil { return err } return nil } -func buildOutscaleOAPINatServiceDataSourceFilters(set *schema.Set) oscgo.FiltersNatService { +func buildNatServiceDataSourceFilters(set *schema.Set) oscgo.FiltersNatService { var filters oscgo.FiltersNatService for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_nat_service_test.go b/outscale/data_source_outscale_nat_service_test.go index f07f24add..597bb9574 100644 --- a/outscale/data_source_outscale_nat_service_test.go +++ b/outscale/data_source_outscale_nat_service_test.go @@ -8,16 +8,16 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPINatServiceDataSource_Instance(t *testing.T) { +func TestAccNatServiceDataSource_Instance(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPINatServiceDataSourceConfig, + Config: testAccCheckNatServiceDataSourceConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleNatServiceDataSourceID("data.outscale_nat_service.nat"), + testAccCheckNatServiceDataSourceID("data.outscale_nat_service.nat"), resource.TestCheckResourceAttrSet("data.outscale_nat_service.nat", "subnet_id"), ), }, @@ -25,7 +25,7 @@ func TestAccOutscaleOAPINatServiceDataSource_Instance(t *testing.T) { }) } -func testAccCheckOutscaleNatServiceDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckNatServiceDataSourceID(n string) resource.TestCheckFunc { // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -40,7 +40,7 @@ func testAccCheckOutscaleNatServiceDataSourceID(n string) resource.TestCheckFunc } } -const testAccCheckOutscaleOAPINatServiceDataSourceConfig = ` +const testAccCheckNatServiceDataSourceConfig = ` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" tags { diff --git a/outscale/data_source_outscale_nat_services.go b/outscale/data_source_outscale_nat_services.go index 1fa0d22f8..3199d15b9 100644 --- a/outscale/data_source_outscale_nat_services.go +++ b/outscale/data_source_outscale_nat_services.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPINatServices() *schema.Resource { +func dataSourceNatServices() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPINatServicesRead, + Read: dataSourceNatServicesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -74,8 +74,8 @@ func dataSourceOutscaleOAPINatServices() *schema.Resource { } } -func dataSourceOutscaleOAPINatServicesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceNatServicesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") natGatewayID, natGatewayIDOK := d.GetOk("nat_service_ids") @@ -86,7 +86,7 @@ func dataSourceOutscaleOAPINatServicesRead(d *schema.ResourceData, meta interfac params := oscgo.ReadNatServicesRequest{} if filtersOk { - params.SetFilters(buildOutscaleOAPINatServiceDataSourceFilters(filters.(*schema.Set))) + params.SetFilters(buildNatServiceDataSourceFilters(filters.(*schema.Set))) } if natGatewayIDOK { ids := make([]string, len(natGatewayID.([]interface{}))) @@ -122,11 +122,11 @@ func dataSourceOutscaleOAPINatServicesRead(d *schema.ResourceData, meta interfac return fmt.Errorf("your query returned no results, please change your search criteria and try again") } - return ngsOAPIDescriptionAttributes(d, resp.GetNatServices()) + return ngsDescriptionAttributes(d, resp.GetNatServices()) } // populate the numerous fields that the image description returns. -func ngsOAPIDescriptionAttributes(d *schema.ResourceData, ngs []oscgo.NatService) error { +func ngsDescriptionAttributes(d *schema.ResourceData, ngs []oscgo.NatService) error { d.SetId(resource.UniqueId()) addngs := make([]map[string]interface{}, len(ngs)) @@ -161,7 +161,7 @@ func ngsOAPIDescriptionAttributes(d *schema.ResourceData, ngs []oscgo.NatService addng["net_id"] = v.GetNetId() } if v.GetTags() != nil { - addng["tags"] = tagsOSCAPIToMap(v.GetTags()) + addng["tags"] = tagsToMap(v.GetTags()) } addngs[k] = addng diff --git a/outscale/data_source_outscale_nat_services_test.go b/outscale/data_source_outscale_nat_services_test.go index b14a6813b..0a48e58b7 100644 --- a/outscale/data_source_outscale_nat_services_test.go +++ b/outscale/data_source_outscale_nat_services_test.go @@ -6,16 +6,16 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPINatServicesDataSource_Instance(t *testing.T) { +func TestAccNatServicesDataSource_Instance(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPINatServicesDataSourceConfig, + Config: testAccCheckNatServicesDataSourceConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleNatServiceDataSourceID("data.outscale_nat_services.nat"), + testAccCheckNatServiceDataSourceID("data.outscale_nat_services.nat"), resource.TestCheckResourceAttr("data.outscale_nat_services.nat", "nat_services.#", "1"), resource.TestCheckResourceAttrSet("data.outscale_nat_services.nat", "nat_services.0.subnet_id"), ), @@ -24,7 +24,7 @@ func TestAccOutscaleOAPINatServicesDataSource_Instance(t *testing.T) { }) } -const testAccCheckOutscaleOAPINatServicesDataSourceConfig = ` +const testAccCheckNatServicesDataSourceConfig = ` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_net.go b/outscale/data_source_outscale_net.go index 3ea28a3cd..01ab16dca 100644 --- a/outscale/data_source_outscale_net.go +++ b/outscale/data_source_outscale_net.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIVpc() *schema.Resource { +func dataSourceVpc() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIVpcRead, + Read: dataSourceVpcRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -54,13 +54,13 @@ func dataSourceOutscaleOAPIVpc() *schema.Resource { } } -func dataSourceOutscaleOAPIVpcRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVpcRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadNetsRequest{} if v, ok := d.GetOk("filter"); ok { - req.SetFilters(buildOutscaleOAPIDataSourceNetFilters(v.(*schema.Set))) + req.SetFilters(buildDataSourceNetFilters(v.(*schema.Set))) } if id := d.Get("net_id"); id != "" { @@ -109,10 +109,10 @@ func dataSourceOutscaleOAPIVpcRead(d *schema.ResourceData, meta interface{}) err return err } - return d.Set("tags", tagsOSCAPIToMap(net.GetTags())) + return d.Set("tags", tagsToMap(net.GetTags())) } -func buildOutscaleOAPIDataSourceNetFilters(set *schema.Set) oscgo.FiltersNet { +func buildDataSourceNetFilters(set *schema.Set) oscgo.FiltersNet { var filters oscgo.FiltersNet for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_net_access_point.go b/outscale/data_source_outscale_net_access_point.go index 9b3d3f4c6..14171ad5a 100644 --- a/outscale/data_source_outscale_net_access_point.go +++ b/outscale/data_source_outscale_net_access_point.go @@ -56,16 +56,16 @@ func napdSchema() map[string]*schema.Schema { } } -func dataSourceOutscaleNetAccessPoint() *schema.Resource { +func dataSourceNetAccessPoint() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleNetAccessPointRead, + Read: dataSourceNetAccessPointRead, Schema: getDataSourceSchemas(napdSchema()), } } -func dataSourceOutscaleNetAccessPointRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceNetAccessPointRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI napid, napidOk := d.GetOk("net_access_point_ids") filters, filtersOk := d.GetOk("filter") @@ -76,7 +76,7 @@ func dataSourceOutscaleNetAccessPointRead(d *schema.ResourceData, meta interface } if filtersOk { - filter = buildOutscaleDataSourcesNAPFilters(filters.(*schema.Set)) + filter = buildDataSourcesNAPFilters(filters.(*schema.Set)) } else { filter = &oscgo.FiltersNetAccessPoint{ NetAccessPointIds: &[]string{napid.(string)}, @@ -116,7 +116,7 @@ func dataSourceOutscaleNetAccessPointRead(d *schema.ResourceData, meta interface d.Set("net_id", nap.NetId) d.Set("service_name", nap.ServiceName) d.Set("state", nap.State) - d.Set("tags", tagsOSCAPIToMap(nap.GetTags())) + d.Set("tags", tagsToMap(nap.GetTags())) id := *nap.NetAccessPointId d.SetId(id) diff --git a/outscale/data_source_outscale_net_access_point_services.go b/outscale/data_source_outscale_net_access_point_services.go index 6ce50f83a..c8635cb00 100644 --- a/outscale/data_source_outscale_net_access_point_services.go +++ b/outscale/data_source_outscale_net_access_point_services.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPINetAccessPointServices() *schema.Resource { +func dataSourceNetAccessPointServices() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPINetAccessPointServicesRead, + Read: dataSourceNetAccessPointServicesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "services": { @@ -46,14 +46,14 @@ func dataSourceOutscaleOAPINetAccessPointServices() *schema.Resource { } } -func dataSourceOutscaleOAPINetAccessPointServicesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceNetAccessPointServicesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") filtersReq := oscgo.FiltersService{} if filtersOk { - filtersReq = buildOutscaleDataSourcesNAPSFilters(filters.(*schema.Set)) + filtersReq = buildDataSourcesNAPSFilters(filters.(*schema.Set)) } req := oscgo.ReadNetAccessPointServicesRequest{Filters: &filtersReq} @@ -95,7 +95,7 @@ func dataSourceOutscaleOAPINetAccessPointServicesRead(d *schema.ResourceData, me return nil } -func buildOutscaleDataSourcesNAPSFilters(set *schema.Set) oscgo.FiltersService { +func buildDataSourcesNAPSFilters(set *schema.Set) oscgo.FiltersService { var filters oscgo.FiltersService for _, v := range set.List() { diff --git a/outscale/data_source_outscale_net_access_point_services_test.go b/outscale/data_source_outscale_net_access_point_services_test.go index a98790727..a8045f74a 100644 --- a/outscale/data_source_outscale_net_access_point_services_test.go +++ b/outscale/data_source_outscale_net_access_point_services_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPINetAccessPointServices_basic(t *testing.T) { +func TestAccDataSourceNetAccessPointServices_basic(t *testing.T) { t.Parallel() serviceName := fmt.Sprintf("com.outscale.%s.api", os.Getenv("OUTSCALE_REGION")) @@ -19,13 +19,13 @@ func TestAccDataSourceOutscaleOAPINetAccessPointServices_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPINetAccessPointServicesConfig(serviceName, serviceName), + Config: testAccDataSourceNetAccessPointServicesConfig(serviceName, serviceName), }, }, }) } -func testAccDataSourceOutscaleOAPINetAccessPointServicesConfig(sName, sName2 string) string { +func testAccDataSourceNetAccessPointServicesConfig(sName, sName2 string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_net_access_point_test.go b/outscale/data_source_outscale_net_access_point_test.go index 94e64510d..90f049400 100644 --- a/outscale/data_source_outscale_net_access_point_test.go +++ b/outscale/data_source_outscale_net_access_point_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPINetAccessPoint_basic(t *testing.T) { +func TestAccDataSourceNetAccessPoint_basic(t *testing.T) { t.Parallel() serviceName := fmt.Sprintf("com.outscale.%s.api", os.Getenv("OUTSCALE_REGION")) @@ -19,13 +19,13 @@ func TestAccDataSourceOutscaleOAPINetAccessPoint_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPINetAccessPointConfig(serviceName, serviceName), + Config: testAccDataSourceNetAccessPointConfig(serviceName, serviceName), }, }, }) } -func testAccDataSourceOutscaleOAPINetAccessPointConfig(sName, sName2 string) string { +func testAccDataSourceNetAccessPointConfig(sName, sName2 string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_net_access_points.go b/outscale/data_source_outscale_net_access_points.go index d204d0867..bbf74e24c 100644 --- a/outscale/data_source_outscale_net_access_points.go +++ b/outscale/data_source_outscale_net_access_points.go @@ -87,15 +87,15 @@ func napSchema() map[string]*schema.Schema { } } -func dataSourceOutscaleNetAccessPoints() *schema.Resource { +func dataSourceNetAccessPoints() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleNetAccessPointsRead, + Read: dataSourceNetAccessPointsRead, Schema: getDataSourceSchemas(napSchema()), } } -func buildOutscaleDataSourcesNAPFilters(set *schema.Set) *oscgo.FiltersNetAccessPoint { +func buildDataSourcesNAPFilters(set *schema.Set) *oscgo.FiltersNetAccessPoint { filters := new(oscgo.FiltersNetAccessPoint) for _, v := range set.List() { @@ -128,8 +128,8 @@ func buildOutscaleDataSourcesNAPFilters(set *schema.Set) *oscgo.FiltersNetAccess return filters } -func dataSourceOutscaleNetAccessPointsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceNetAccessPointsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI napid, napidOk := d.GetOk("net_access_point_ids") filters, filtersOk := d.GetOk("filter") @@ -140,7 +140,7 @@ func dataSourceOutscaleNetAccessPointsRead(d *schema.ResourceData, meta interfac } if filtersOk { - filter = buildOutscaleDataSourcesNAPFilters(filters.(*schema.Set)) + filter = buildDataSourcesNAPFilters(filters.(*schema.Set)) } else { filter = &oscgo.FiltersNetAccessPoint{ NetAccessPointIds: &[]string{napid.(string)}, @@ -181,7 +181,7 @@ func dataSourceOutscaleNetAccessPointsRead(d *schema.ResourceData, meta interfac n["net_id"] = v.NetId n["service_name"] = v.ServiceName n["state"] = v.State - n["tags"] = tagsOSCAPIToMap(v.GetTags()) + n["tags"] = tagsToMap(v.GetTags()) nap_ret[k] = n } diff --git a/outscale/data_source_outscale_net_access_points_test.go b/outscale/data_source_outscale_net_access_points_test.go index 71e166f3c..a4d2a6547 100644 --- a/outscale/data_source_outscale_net_access_points_test.go +++ b/outscale/data_source_outscale_net_access_points_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPINetAccessPoints_basic(t *testing.T) { +func TestAccDataSourceNetAccessPoints_basic(t *testing.T) { t.Parallel() serviceName := fmt.Sprintf("com.outscale.%s.api", os.Getenv("OUTSCALE_REGION")) @@ -19,13 +19,13 @@ func TestAccDataSourceOutscaleOAPINetAccessPoints_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPINetAccessPointsConfig(serviceName, serviceName), + Config: testAccDataSourceNetAccessPointsConfig(serviceName, serviceName), }, }, }) } -func testAccDataSourceOutscaleOAPINetAccessPointsConfig(sName, sName2 string) string { +func testAccDataSourceNetAccessPointsConfig(sName, sName2 string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_net_attributes.go b/outscale/data_source_outscale_net_attributes.go index c698fec08..fe0809b43 100644 --- a/outscale/data_source_outscale_net_attributes.go +++ b/outscale/data_source_outscale_net_attributes.go @@ -13,9 +13,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func dataSourceOutscaleOAPIVpcAttr() *schema.Resource { +func dataSourceVpcAttr() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIVpcAttrRead, + Read: dataSourceVpcAttrRead, Schema: map[string]*schema.Schema{ //"filter": dataSourceFiltersSchema(), @@ -48,8 +48,8 @@ func dataSourceOutscaleOAPIVpcAttr() *schema.Resource { } } -func dataSourceOutscaleOAPIVpcAttrRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVpcAttrRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters := oscgo.FiltersNet{ NetIds: &[]string{d.Get("net_id").(string)}, @@ -86,5 +86,5 @@ func dataSourceOutscaleOAPIVpcAttrRead(d *schema.ResourceData, meta interface{}) d.Set("net_id", resp.GetNets()[0].GetNetId()) d.Set("state", resp.GetNets()[0].GetState()) - return d.Set("tags", tagsOSCAPIToMap(resp.GetNets()[0].GetTags())) + return d.Set("tags", tagsToMap(resp.GetNets()[0].GetTags())) } diff --git a/outscale/data_source_outscale_net_attributes_test.go b/outscale/data_source_outscale_net_attributes_test.go index db3204bf6..9a6481d44 100644 --- a/outscale/data_source_outscale_net_attributes_test.go +++ b/outscale/data_source_outscale_net_attributes_test.go @@ -8,23 +8,23 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIDSLinAttr_basic(t *testing.T) { +func TestAccDSLinAttr_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIDSLinAttrConfig, + Config: testAccDSLinAttrConfig, Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPIVpcAttrCheck("data.outscale_net_attributes.test"), + testAccDataSourceVpcAttrCheck("data.outscale_net_attributes.test"), ), }, }, }) } -func testAccDataSourceOutscaleOAPIVpcAttrCheck(name string) resource.TestCheckFunc { +func testAccDataSourceVpcAttrCheck(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -41,7 +41,7 @@ func testAccDataSourceOutscaleOAPIVpcAttrCheck(name string) resource.TestCheckFu } } -const testAccOutscaleOAPIDSLinAttrConfig = ` +const testAccDSLinAttrConfig = ` resource "outscale_net" "vpc" { ip_range = "10.0.0.0/16" tags { diff --git a/outscale/data_source_outscale_net_peering.go b/outscale/data_source_outscale_net_peering.go index 7e6be7f31..dcb8c580f 100644 --- a/outscale/data_source_outscale_net_peering.go +++ b/outscale/data_source_outscale_net_peering.go @@ -15,18 +15,18 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func dataSourceOutscaleOAPILinPeeringConnection() *schema.Resource { +func dataSourceLinPeeringConnection() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPILinPeeringConnectionRead, + Read: dataSourceLinPeeringConnectionRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), - "accepter_net": vpcOAPIPeeringConnectionOptionsSchema(), + "accepter_net": vpcPeeringConnectionOptionsSchema(), "net_peering_id": { Type: schema.TypeString, Computed: true, }, - "source_net": vpcOAPIPeeringConnectionOptionsSchema(), + "source_net": vpcPeeringConnectionOptionsSchema(), "state": { Type: schema.TypeMap, Computed: true, @@ -52,8 +52,8 @@ func dataSourceOutscaleOAPILinPeeringConnection() *schema.Resource { } } -func dataSourceOutscaleOAPILinPeeringConnectionRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceLinPeeringConnectionRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI log.Printf("[DEBUG] Reading Net Peering Connections.") @@ -63,7 +63,7 @@ func dataSourceOutscaleOAPILinPeeringConnectionRead(d *schema.ResourceData, meta if !filtersOk { return fmt.Errorf("filters must be assigned") } - req.SetFilters(buildOutscaleOAPILinPeeringConnectionFilters(filters.(*schema.Set))) + req.SetFilters(buildLinPeeringConnectionFilters(filters.(*schema.Set))) var resp oscgo.ReadNetPeeringsResponse var err error @@ -143,7 +143,7 @@ func dataSourceOutscaleOAPILinPeeringConnectionRead(d *schema.ResourceData, meta if err := d.Set("net_peering_id", netPeering.GetNetPeeringId()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(netPeering.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(netPeering.GetTags())); err != nil { return errwrap.Wrapf("Error setting Net Peering tags: {{err}}", err) } @@ -152,7 +152,7 @@ func dataSourceOutscaleOAPILinPeeringConnectionRead(d *schema.ResourceData, meta return nil } -func buildOutscaleOAPILinPeeringConnectionFilters(set *schema.Set) oscgo.FiltersNetPeering { +func buildLinPeeringConnectionFilters(set *schema.Set) oscgo.FiltersNetPeering { var filters oscgo.FiltersNetPeering for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_net_peering_test.go b/outscale/data_source_outscale_net_peering_test.go index 76388baeb..3f718df12 100644 --- a/outscale/data_source_outscale_net_peering_test.go +++ b/outscale/data_source_outscale_net_peering_test.go @@ -8,23 +8,23 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccDataSourceOutscaleOAPILinPeeringConnection_basic(t *testing.T) { +func TestAccDataSourceLinPeeringConnection_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPILinPeeringConnectionConfig, + Config: testAccDataSourceLinPeeringConnectionConfig, Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPILinPeeringConnectionCheck("outscale_net_peering.net_peering"), + testAccDataSourceLinPeeringConnectionCheck("outscale_net_peering.net_peering"), ), }, }, }) } -func testAccDataSourceOutscaleOAPILinPeeringConnectionCheck(name string) resource.TestCheckFunc { +func testAccDataSourceLinPeeringConnectionCheck(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -50,7 +50,7 @@ func testAccDataSourceOutscaleOAPILinPeeringConnectionCheck(name string) resourc } } -const testAccDataSourceOutscaleOAPILinPeeringConnectionConfig = ` +const testAccDataSourceLinPeeringConnectionConfig = ` resource "outscale_net" "net" { ip_range = "10.10.0.0/24" tags { diff --git a/outscale/data_source_outscale_net_peerings.go b/outscale/data_source_outscale_net_peerings.go index cd297b424..c937e97ac 100644 --- a/outscale/data_source_outscale_net_peerings.go +++ b/outscale/data_source_outscale_net_peerings.go @@ -13,9 +13,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func dataSourceOutscaleOAPILinPeeringsConnection() *schema.Resource { +func dataSourceLinPeeringsConnection() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPILinPeeringsConnectionRead, + Read: dataSourceLinPeeringsConnectionRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -24,12 +24,12 @@ func dataSourceOutscaleOAPILinPeeringsConnection() *schema.Resource { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "accepter_net": vpcOAPIPeeringConnectionOptionsSchema(), + "accepter_net": vpcPeeringConnectionOptionsSchema(), "net_peering_id": { Type: schema.TypeString, Computed: true, }, - "source_net": vpcOAPIPeeringConnectionOptionsSchema(), + "source_net": vpcPeeringConnectionOptionsSchema(), "state": { Type: schema.TypeMap, Computed: true, @@ -58,8 +58,8 @@ func dataSourceOutscaleOAPILinPeeringsConnection() *schema.Resource { } } -func dataSourceOutscaleOAPILinPeeringsConnectionRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceLinPeeringsConnectionRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI log.Printf("[DEBUG] Reading VPC Peering Connections.") @@ -69,7 +69,7 @@ func dataSourceOutscaleOAPILinPeeringsConnectionRead(d *schema.ResourceData, met } params := oscgo.ReadNetPeeringsRequest{} - params.SetFilters(buildOutscaleOAPILinPeeringConnectionFilters(filters.(*schema.Set))) + params.SetFilters(buildLinPeeringConnectionFilters(filters.(*schema.Set))) var resp oscgo.ReadNetPeeringsResponse var err error @@ -95,7 +95,7 @@ func dataSourceOutscaleOAPILinPeeringsConnectionRead(d *schema.ResourceData, met return resourceDataAttrSetter(d, func(set AttributeSetter) error { d.SetId(resource.UniqueId()) - if err := set("net_peerings", getOAPINetPeerings(peerings)); err != nil { + if err := set("net_peerings", getNetPeerings(peerings)); err != nil { log.Printf("[DEBUG] Net Peerings ERR %+v", err) return err } @@ -103,20 +103,20 @@ func dataSourceOutscaleOAPILinPeeringsConnectionRead(d *schema.ResourceData, met }) } -func getOAPINetPeerings(peerings []oscgo.NetPeering) (res []map[string]interface{}) { +func getNetPeerings(peerings []oscgo.NetPeering) (res []map[string]interface{}) { for _, p := range peerings { res = append(res, map[string]interface{}{ - "accepter_net": getOAPINetPeeringAccepterNet(p.GetAccepterNet()), + "accepter_net": getNetPeeringAccepterNet(p.GetAccepterNet()), "net_peering_id": p.GetNetPeeringId(), - "source_net": getOAPINetPeeringSourceNet(p.GetSourceNet()), - "state": getOAPINetPeeringState(p.GetState()), - //"tags": getOapiTagSet(p.Tags), + "source_net": getNetPeeringSourceNet(p.GetSourceNet()), + "state": getNetPeeringState(p.GetState()), + //"tags": getTagSet(p.Tags), }) } return res } -func getOAPINetPeeringAccepterNet(a oscgo.AccepterNet) map[string]interface{} { +func getNetPeeringAccepterNet(a oscgo.AccepterNet) map[string]interface{} { return map[string]interface{}{ "ip_range": a.GetIpRange(), "account_id": a.GetAccountId(), @@ -124,7 +124,7 @@ func getOAPINetPeeringAccepterNet(a oscgo.AccepterNet) map[string]interface{} { } } -func getOAPINetPeeringSourceNet(a oscgo.SourceNet) map[string]interface{} { +func getNetPeeringSourceNet(a oscgo.SourceNet) map[string]interface{} { return map[string]interface{}{ "ip_range": a.GetIpRange(), "account_id": a.GetAccountId(), @@ -132,7 +132,7 @@ func getOAPINetPeeringSourceNet(a oscgo.SourceNet) map[string]interface{} { } } -func getOAPINetPeeringState(a oscgo.NetPeeringState) map[string]interface{} { +func getNetPeeringState(a oscgo.NetPeeringState) map[string]interface{} { return map[string]interface{}{ "name": a.Name, "message": a.Message, diff --git a/outscale/data_source_outscale_net_peerings_test.go b/outscale/data_source_outscale_net_peerings_test.go index a01e34f98..f6bbcba0d 100644 --- a/outscale/data_source_outscale_net_peerings_test.go +++ b/outscale/data_source_outscale_net_peerings_test.go @@ -6,14 +6,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPILinPeeringsConnection_basic(t *testing.T) { +func TestAccDataSourceLinPeeringsConnection_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPILinPeeringsConnectionConfig, + Config: testAccDataSourceLinPeeringsConnectionConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_net_peerings.outscale_net_peerings", "net_peerings.#", "1"), ), @@ -22,7 +22,7 @@ func TestAccDataSourceOutscaleOAPILinPeeringsConnection_basic(t *testing.T) { }) } -const testAccDataSourceOutscaleOAPILinPeeringsConnectionConfig = ` +const testAccDataSourceLinPeeringsConnectionConfig = ` resource "outscale_net" "outscale_net" { ip_range = "10.10.0.0/24" tags { diff --git a/outscale/data_source_outscale_net_test.go b/outscale/data_source_outscale_net_test.go index 11c83fcbd..69f6b81dd 100644 --- a/outscale/data_source_outscale_net_test.go +++ b/outscale/data_source_outscale_net_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccDataSourceOutscaleOAPIVpc_basic(t *testing.T) { +func TestAccDataSourceVpc_basic(t *testing.T) { t.Parallel() rand.Seed(time.Now().UTC().UnixNano()) rInt := rand.Intn(16) @@ -21,16 +21,16 @@ func TestAccDataSourceOutscaleOAPIVpc_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIVpcConfig(ipRange, tag), + Config: testAccDataSourceVpcConfig(ipRange, tag), Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPIVpcCheck("data.outscale_net.by_id", ipRange, tag), + testAccDataSourceVpcCheck("data.outscale_net.by_id", ipRange, tag), ), }, }, }) } -func testAccDataSourceOutscaleOAPIVpcCheck(name, ipRange, tag string) resource.TestCheckFunc { +func testAccDataSourceVpcCheck(name, ipRange, tag string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -60,7 +60,7 @@ func testAccDataSourceOutscaleOAPIVpcCheck(name, ipRange, tag string) resource.T } } -func testAccDataSourceOutscaleOAPIVpcConfig(ipRange, tag string) string { +func testAccDataSourceVpcConfig(ipRange, tag string) string { return fmt.Sprintf(` resource "outscale_net" "test" { ip_range = "%s" diff --git a/outscale/data_source_outscale_nets.go b/outscale/data_source_outscale_nets.go index 1d1c39990..9156edbb5 100644 --- a/outscale/data_source_outscale_nets.go +++ b/outscale/data_source_outscale_nets.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIVpcs() *schema.Resource { +func dataSourceVpcs() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIVpcsRead, + Read: dataSourceVpcsRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -64,8 +64,8 @@ func dataSourceOutscaleOAPIVpcs() *schema.Resource { } } -func dataSourceOutscaleOAPIVpcsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVpcsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadNetsRequest{} @@ -77,7 +77,7 @@ func dataSourceOutscaleOAPIVpcsRead(d *schema.ResourceData, meta interface{}) er } if filtersOk { - req.SetFilters(buildOutscaleOAPIDataSourceNetFilters(filters.(*schema.Set))) + req.SetFilters(buildDataSourceNetFilters(filters.(*schema.Set))) } if netIdsOk { @@ -123,7 +123,7 @@ func dataSourceOutscaleOAPIVpcsRead(d *schema.ResourceData, meta interface{}) er net["tenancy"] = v.GetTenancy() net["state"] = v.GetState() if v.Tags != nil { - net["tags"] = tagsOSCAPIToMap(v.GetTags()) + net["tags"] = tagsToMap(v.GetTags()) } nets[i] = net diff --git a/outscale/data_source_outscale_nets_test.go b/outscale/data_source_outscale_nets_test.go index 2023cf7aa..53b3b2a3b 100644 --- a/outscale/data_source_outscale_nets_test.go +++ b/outscale/data_source_outscale_nets_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIVpcs_basic(t *testing.T) { +func TestAccDataSourceVpcs_basic(t *testing.T) { rand.Seed(time.Now().UTC().UnixNano()) rInt := rand.Intn(16) @@ -20,7 +20,7 @@ func TestAccDataSourceOutscaleOAPIVpcs_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIVpcsConfig(ipRange, tag), + Config: testAccDataSourceVpcsConfig(ipRange, tag), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_nets.by_id", "nets.#", "1"), ), @@ -29,7 +29,7 @@ func TestAccDataSourceOutscaleOAPIVpcs_basic(t *testing.T) { }) } -func testAccDataSourceOutscaleOAPIVpcsConfig(ipRange, tag string) string { +func testAccDataSourceVpcsConfig(ipRange, tag string) string { return fmt.Sprintf(` resource "outscale_net" "test" { ip_range = "%s" diff --git a/outscale/data_source_outscale_nic.go b/outscale/data_source_outscale_nic.go index 0c8a5b401..b75945033 100644 --- a/outscale/data_source_outscale_nic.go +++ b/outscale/data_source_outscale_nic.go @@ -16,9 +16,9 @@ import ( ) // Creates a network interface in the specified subnet -func dataSourceOutscaleOAPINic() *schema.Resource { +func dataSourceNic() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPINicRead, + Read: dataSourceNicRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -213,8 +213,8 @@ func dataSourceOutscaleOAPINic() *schema.Resource { } // Read Nic -func dataSourceOutscaleOAPINicRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceNicRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI nicID, okID := d.GetOk("nic_id") filters, okFilters := d.GetOk("filter") @@ -232,7 +232,7 @@ func dataSourceOutscaleOAPINicRead(d *schema.ResourceData, meta interface{}) err } if okFilters { - dnri.SetFilters(buildOutscaleOAPIDataSourceNicFilters(filters.(*schema.Set))) + dnri.SetFilters(buildDataSourceNicFilters(filters.(*schema.Set))) } var resp oscgo.ReadNicsResponse @@ -369,7 +369,7 @@ func dataSourceOutscaleOAPINicRead(d *schema.ResourceData, meta interface{}) err if err := d.Set("state", eni.GetState()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(eni.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(eni.GetTags())); err != nil { return err } if err := d.Set("net_id", eni.GetNetId()); err != nil { @@ -380,7 +380,7 @@ func dataSourceOutscaleOAPINicRead(d *schema.ResourceData, meta interface{}) err return nil } -func buildOutscaleOAPIDataSourceNicFilters(set *schema.Set) oscgo.FiltersNic { +func buildDataSourceNicFilters(set *schema.Set) oscgo.FiltersNic { var filters oscgo.FiltersNic for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_nic_test.go b/outscale/data_source_outscale_nic_test.go index fec5c745a..65c488dcf 100644 --- a/outscale/data_source_outscale_nic_test.go +++ b/outscale/data_source_outscale_nic_test.go @@ -16,7 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIENIDataSource_basic(t *testing.T) { +func TestAccENIDataSource_basic(t *testing.T) { t.Parallel() var conf oscgo.Nic subregion := os.Getenv("OUTSCALE_REGION") @@ -25,20 +25,20 @@ func TestAccOutscaleOAPIENIDataSource_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_nic.outscale_nic", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIENIDestroy, + CheckDestroy: testAccCheckENIDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIENIDataSourceConfig(subregion), + Config: testAccENIDataSourceConfig(subregion), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIENIExists("outscale_nic.outscale_nic", &conf), - testAccCheckOutscaleOAPIENIAttributes(&conf, subregion), + testAccCheckENIExists("outscale_nic.outscale_nic", &conf), + testAccCheckENIAttributes(&conf, subregion), ), }, }, }) } -func TestAccOutscaleOAPIENIDataSource_basicFilter(t *testing.T) { +func TestAccENIDataSource_basicFilter(t *testing.T) { t.Parallel() var conf oscgo.Nic @@ -51,27 +51,27 @@ func TestAccOutscaleOAPIENIDataSource_basicFilter(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_nic.outscale_nic", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIENIDestroy, + CheckDestroy: testAccCheckENIDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIENIDataSourceConfigFilter, + Config: testAccENIDataSourceConfigFilter, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIENIExists("outscale_nic.outscale_nic", &conf), - testAccCheckOutscaleOAPIENIAttributes(&conf, subregion), + testAccCheckENIExists("outscale_nic.outscale_nic", &conf), + testAccCheckENIAttributes(&conf, subregion), ), }, }, }) } -func testAccCheckOutscaleOAPIENIDestroy(s *terraform.State) error { +func testAccCheckENIDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_nic" { continue } var resp oscgo.ReadNicsResponse - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI req := oscgo.ReadNicsRequest{ Filters: &oscgo.FiltersNic{NicIds: &[]string{rs.Primary.ID}}, } @@ -97,13 +97,13 @@ func testAccCheckOutscaleOAPIENIDestroy(s *terraform.State) error { return nil } -func testAccCheckOutscaleOAPINICDestroy(s *terraform.State) error { +func testAccCheckNICDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_nic" { continue } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI dnir := oscgo.ReadNicsRequest{ Filters: &oscgo.FiltersNic{NicIds: &[]string{rs.Primary.ID}}, } @@ -136,7 +136,7 @@ func testAccCheckOutscaleOAPINICDestroy(s *terraform.State) error { return nil } -func testAccOutscaleOAPIENIDataSourceConfig(subregion string) string { +func testAccENIDataSourceConfig(subregion string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -167,7 +167,7 @@ func testAccOutscaleOAPIENIDataSourceConfig(subregion string) string { `, subregion) } -const testAccOutscaleOAPIENIDataSourceConfigFilter = ` +const testAccENIDataSourceConfigFilter = ` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_nics.go b/outscale/data_source_outscale_nics.go index a5021183d..3af489f61 100644 --- a/outscale/data_source_outscale_nics.go +++ b/outscale/data_source_outscale_nics.go @@ -13,14 +13,14 @@ import ( ) // Creates a network interface in the specified subnet -func dataSourceOutscaleOAPINics() *schema.Resource { +func dataSourceNics() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPINicsRead, - Schema: getDSOAPINicsSchema(), + Read: dataSourceNicsRead, + Schema: getDSNicsSchema(), } } -func getDSOAPINicsSchema() map[string]*schema.Schema { +func getDSNicsSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ // This is attribute part for schema Nic "filter": dataSourceFiltersSchema(), @@ -222,8 +222,8 @@ func getDSOAPINicsSchema() map[string]*schema.Schema { } // Read Nic -func dataSourceOutscaleOAPINicsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceNicsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") if !filtersOk { @@ -232,7 +232,7 @@ func dataSourceOutscaleOAPINicsRead(d *schema.ResourceData, meta interface{}) er params := oscgo.ReadNicsRequest{} if filtersOk { - params.SetFilters(buildOutscaleOAPIDataSourceNicFilters(filters.(*schema.Set))) + params.SetFilters(buildDataSourceNicFilters(filters.(*schema.Set))) } var resp oscgo.ReadNicsResponse @@ -264,7 +264,7 @@ func dataSourceOutscaleOAPINicsRead(d *schema.ResourceData, meta interface{}) er return resourceDataAttrSetter(d, func(set AttributeSetter) error { d.SetId(resource.UniqueId()) - if err := set("nics", getOAPIVMNetworkInterfaceSet(nics)); err != nil { + if err := set("nics", getVMNetworkInterfaceSet(nics)); err != nil { return err } diff --git a/outscale/data_source_outscale_nics_test.go b/outscale/data_source_outscale_nics_test.go index cf9ba01a5..323f8b367 100644 --- a/outscale/data_source_outscale_nics_test.go +++ b/outscale/data_source_outscale_nics_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPINicsDataSource(t *testing.T) { +func TestAccNicsDataSource(t *testing.T) { subregion := os.Getenv("OUTSCALE_REGION") resource.Test(t, resource.TestCase{ @@ -16,7 +16,7 @@ func TestAccOutscaleOAPINicsDataSource(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPINicsDataSourceConfig(subregion), + Config: testAccCheckNicsDataSourceConfig(subregion), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_nics.outscale_nics", "nics.#", "1"), ), @@ -25,7 +25,7 @@ func TestAccOutscaleOAPINicsDataSource(t *testing.T) { }) } -func testAccCheckOutscaleOAPINicsDataSourceConfig(subregion string) string { +func testAccCheckNicsDataSourceConfig(subregion string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_product_type.go b/outscale/data_source_outscale_product_type.go index fefe8a86e..36e53e1b9 100644 --- a/outscale/data_source_outscale_product_type.go +++ b/outscale/data_source_outscale_product_type.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIProductType() *schema.Resource { +func dataSourceProductType() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIProductTypeRead, + Read: dataSourceProductTypeRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -39,15 +39,15 @@ func dataSourceOutscaleOAPIProductType() *schema.Resource { } } -func dataSourceOutscaleOAPIProductTypeRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceProductTypeRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadProductTypesRequest{} filters, filtersOk := d.GetOk("filter") if filtersOk { - req.Filters = buildOutscaleOAPIProductTypeDataSourceFilters(filters.(*schema.Set)) + req.Filters = buildProductTypeDataSourceFilters(filters.(*schema.Set)) } var resp oscgo.ReadProductTypesResponse @@ -90,7 +90,7 @@ func dataSourceOutscaleOAPIProductTypeRead(d *schema.ResourceData, meta interfac return nil } -func buildOutscaleOAPIProductTypeDataSourceFilters(set *schema.Set) *oscgo.FiltersProductType { +func buildProductTypeDataSourceFilters(set *schema.Set) *oscgo.FiltersProductType { var filters oscgo.FiltersProductType for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_product_type_test.go b/outscale/data_source_outscale_product_type_test.go index 8154d15cf..28f140746 100644 --- a/outscale/data_source_outscale_product_type_test.go +++ b/outscale/data_source_outscale_product_type_test.go @@ -6,21 +6,21 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIProductType(t *testing.T) { +func TestAccDataSourceProductType(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIProductTypeConfig, + Config: testAccDataSourceProductTypeConfig, Check: resource.ComposeTestCheckFunc(), }, }, }) } -const testAccDataSourceOutscaleOAPIProductTypeConfig = ` +const testAccDataSourceProductTypeConfig = ` data "outscale_product_type" "test" { filter { name = "product_type_ids" diff --git a/outscale/data_source_outscale_product_types.go b/outscale/data_source_outscale_product_types.go index c0ce2f268..16bf412a7 100644 --- a/outscale/data_source_outscale_product_types.go +++ b/outscale/data_source_outscale_product_types.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIProductTypes() *schema.Resource { +func dataSourceProductTypes() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIProductTypesRead, + Read: dataSourceProductTypesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -46,15 +46,15 @@ func dataSourceOutscaleOAPIProductTypes() *schema.Resource { } } -func dataSourceOutscaleOAPIProductTypesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceProductTypesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadProductTypesRequest{} filters, filtersOk := d.GetOk("filter") if filtersOk { - req.Filters = buildOutscaleOAPIProductTypeDataSourceFilters(filters.(*schema.Set)) + req.Filters = buildProductTypeDataSourceFilters(filters.(*schema.Set)) } var resp oscgo.ReadProductTypesResponse diff --git a/outscale/data_source_outscale_product_types_test.go b/outscale/data_source_outscale_product_types_test.go index 3c521fb5e..c371d6af3 100644 --- a/outscale/data_source_outscale_product_types_test.go +++ b/outscale/data_source_outscale_product_types_test.go @@ -6,19 +6,19 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIProductTypes(t *testing.T) { +func TestAccDataSourceProductTypes(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIProductTypesConfig, + Config: testAccDataSourceProductTypesConfig, Check: resource.ComposeTestCheckFunc(), }, }, }) } -const testAccDataSourceOutscaleOAPIProductTypesConfig = ` +const testAccDataSourceProductTypesConfig = ` data "outscale_product_types" "all" {}` diff --git a/outscale/data_source_outscale_public_catalog.go b/outscale/data_source_outscale_public_catalog.go index f6c90fc30..3fc8e36b9 100644 --- a/outscale/data_source_outscale_public_catalog.go +++ b/outscale/data_source_outscale_public_catalog.go @@ -11,9 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIPublicCatalog() *schema.Resource { +func dataSourcePublicCatalog() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIPublicCatalogRead, + Read: dataSourcePublicCatalogRead, Schema: map[string]*schema.Schema{ "catalog": { Type: schema.TypeSet, @@ -71,8 +71,8 @@ func dataSourceOutscaleOAPIPublicCatalog() *schema.Resource { } } -func dataSourceOutscaleOAPIPublicCatalogRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourcePublicCatalogRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadPublicCatalogRequest{} diff --git a/outscale/data_source_outscale_public_catalog_test.go b/outscale/data_source_outscale_public_catalog_test.go index 2e9501c0c..a17cec882 100644 --- a/outscale/data_source_outscale_public_catalog_test.go +++ b/outscale/data_source_outscale_public_catalog_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIPublicCatalog_basic(t *testing.T) { +func TestAccDataSourcePublicCatalog_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -16,13 +16,13 @@ func TestAccDataSourceOutscaleOAPIPublicCatalog_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIPublicCatalogConfig(), + Config: testAccDataSourcePublicCatalogConfig(), }, }, }) } -func testAccDataSourceOutscaleOAPIPublicCatalogConfig() string { +func testAccDataSourcePublicCatalogConfig() string { return fmt.Sprintf(` data "outscale_public_catalog" "catalog" { } `) diff --git a/outscale/data_source_outscale_public_ip.go b/outscale/data_source_outscale_public_ip.go index 0fd302b6e..9c4cbc156 100644 --- a/outscale/data_source_outscale_public_ip.go +++ b/outscale/data_source_outscale_public_ip.go @@ -13,14 +13,14 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIPublicIP() *schema.Resource { +func dataSourcePublicIP() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIPublicIPRead, - Schema: getOAPIPublicIPDataSourceSchema(), + Read: dataSourcePublicIPRead, + Schema: getPublicIPDataSourceSchema(), } } -func getOAPIPublicIPDataSourceSchema() map[string]*schema.Schema { +func getPublicIPDataSourceSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ // Attributes "filter": dataSourceFiltersSchema(), @@ -62,8 +62,8 @@ func getOAPIPublicIPDataSourceSchema() map[string]*schema.Schema { } } -func dataSourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourcePublicIPRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadPublicIpsRequest{ Filters: &oscgo.FiltersPublicIp{}, @@ -79,7 +79,7 @@ func dataSourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{} filters, filtersOk := d.GetOk("filter") if filtersOk { - req.Filters = buildOutscaleOAPIDataSourcePublicIpsFilters(filters.(*schema.Set)) + req.Filters = buildDataSourcePublicIpsFilters(filters.(*schema.Set)) } var response oscgo.ReadPublicIpsResponse @@ -103,7 +103,6 @@ func dataSourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error retrieving EIP: %s", err) } - // Verify Outscale returned our EIP if err := utils.IsResponseEmptyOrMutiple(len(response.GetPublicIps()), "PublicIp"); err != nil { return err } @@ -135,7 +134,7 @@ func dataSourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{} return err } - if err := d.Set("tags", tagsOSCAPIToMap(address.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(address.GetTags())); err != nil { return fmt.Errorf("Error setting PublicIp tags: %s", err) } @@ -146,7 +145,7 @@ func dataSourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{} return nil } -func buildOutscaleOAPIDataSourcePublicIpsFilters(set *schema.Set) *oscgo.FiltersPublicIp { +func buildDataSourcePublicIpsFilters(set *schema.Set) *oscgo.FiltersPublicIp { var filters oscgo.FiltersPublicIp for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_public_ip_test.go b/outscale/data_source_outscale_public_ip_test.go index b25290137..08677e7be 100644 --- a/outscale/data_source_outscale_public_ip_test.go +++ b/outscale/data_source_outscale_public_ip_test.go @@ -9,24 +9,24 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccDataSourceOutscaleOAPIPublicIP(t *testing.T) { +func TestAccDataSourcePublicIP(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIPublicIPConfig, + Config: testAccDataSourcePublicIPConfig, Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPIPublicIPCheck("data.outscale_public_ip.by_public_ip_id"), - testAccDataSourceOutscaleOAPIPublicIPCheck("data.outscale_public_ip.by_public_ip"), + testAccDataSourcePublicIPCheck("data.outscale_public_ip.by_public_ip_id"), + testAccDataSourcePublicIPCheck("data.outscale_public_ip.by_public_ip"), ), }, }, }) } -func TestAccDataSourceOutscaleOAPIPublicIPWithVM(t *testing.T) { +func TestAccDataSourcePublicIPWithVM(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") @@ -35,13 +35,13 @@ func TestAccDataSourceOutscaleOAPIPublicIPWithVM(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIPublicIPConfigwithVM(omi), + Config: testAccDataSourcePublicIPConfigwithVM(omi), }, }, }) } -func testAccDataSourceOutscaleOAPIPublicIPCheck(name string) resource.TestCheckFunc { +func testAccDataSourcePublicIPCheck(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -76,20 +76,20 @@ func testAccDataSourceOutscaleOAPIPublicIPCheck(name string) resource.TestCheckF } } -func TestAccDataSourceOutscaleOAPIPublicIP_withTags(t *testing.T) { +func TestAccDataSourcePublicIP_withTags(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIPublicIPConfigWithTags, + Config: testAccDataSourcePublicIPConfigWithTags, }, }, }) } -const testAccDataSourceOutscaleOAPIPublicIPConfig = ` +const testAccDataSourcePublicIPConfig = ` resource "outscale_public_ip" "test" {} data "outscale_public_ip" "by_public_ip_id" { @@ -104,7 +104,7 @@ const testAccDataSourceOutscaleOAPIPublicIPConfig = ` } ` -const testAccDataSourceOutscaleOAPIPublicIPConfigWithTags = ` +const testAccDataSourcePublicIPConfigWithTags = ` resource "outscale_public_ip" "outscale_public_ip" { tags { key = "name" @@ -125,7 +125,7 @@ const testAccDataSourceOutscaleOAPIPublicIPConfigWithTags = ` } ` -func testAccDataSourceOutscaleOAPIPublicIPConfigwithVM(omi string) string { +func testAccDataSourcePublicIPConfigwithVM(omi string) string { return fmt.Sprintf(` resource "outscale_vm" "outscale_vm" { image_id = "%s" diff --git a/outscale/data_source_outscale_public_ips.go b/outscale/data_source_outscale_public_ips.go index f0ba12b3d..294e21197 100644 --- a/outscale/data_source_outscale_public_ips.go +++ b/outscale/data_source_outscale_public_ips.go @@ -12,14 +12,14 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIPublicIPS() *schema.Resource { +func dataSourcePublicIPS() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscalePublicIPSRead, - Schema: oapiGetPublicIPSDataSourceSchema(), + Read: dataSourcePublicIPSRead, + Schema: getPublicIPSDataSourceSchema(), } } -func oapiGetPublicIPSDataSourceSchema() map[string]*schema.Schema { +func getPublicIPSDataSourceSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ // Attributes "filter": dataSourceFiltersSchema(), @@ -67,15 +67,15 @@ func oapiGetPublicIPSDataSourceSchema() map[string]*schema.Schema { } } -func dataSourceOutscalePublicIPSRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourcePublicIPSRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadPublicIpsRequest{} filters, filtersOk := d.GetOk("filter") if filtersOk { - req.Filters = buildOutscaleOAPIDataSourcePublicIpsFilters(filters.(*schema.Set)) + req.Filters = buildDataSourcePublicIpsFilters(filters.(*schema.Set)) } var resp oscgo.ReadPublicIpsResponse @@ -100,7 +100,6 @@ func dataSourceOutscalePublicIPSRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error retrieving EIP: %s", err) } - // Verify Outscale returned our EIP if len(resp.GetPublicIps()) == 0 { return fmt.Errorf("Unable to find EIP: %#v", resp.GetPublicIps()) } @@ -119,7 +118,7 @@ func dataSourceOutscalePublicIPSRead(d *schema.ResourceData, meta interface{}) e add["nic_account_id"] = v.NicAccountId add["private_ip"] = v.PrivateIp add["public_ip"] = v.PublicIp - add["tags"] = getOapiTagSet(v.Tags) + add["tags"] = getTagSet(v.GetTags()) address[k] = add } diff --git a/outscale/data_source_outscale_public_ips_test.go b/outscale/data_source_outscale_public_ips_test.go index 10662682e..f66781fd8 100644 --- a/outscale/data_source_outscale_public_ips_test.go +++ b/outscale/data_source_outscale_public_ips_test.go @@ -7,14 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIPublicIPS(t *testing.T) { +func TestAccDataSourcePublicIPS(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIPublicIPSConfig, + Config: testAccDataSourcePublicIPSConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( "data.outscale_public_ips.by_public_ips", "public_ips.0.public_ip"), @@ -28,7 +28,7 @@ func TestAccDataSourceOutscaleOAPIPublicIPS(t *testing.T) { }) } -func TestAccDataSourceOutscaleOAPIPublicIPS_withTags(t *testing.T) { +func TestAccDataSourcePublicIPS_withTags(t *testing.T) { t.Parallel() if os.Getenv("TEST_QUOTA") == "true" { resource.Test(t, resource.TestCase{ @@ -36,7 +36,7 @@ func TestAccDataSourceOutscaleOAPIPublicIPS_withTags(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIPublicIPSConfigWithTags, + Config: testAccDataSourcePublicIPSConfigWithTags, }, }, }) @@ -45,7 +45,7 @@ func TestAccDataSourceOutscaleOAPIPublicIPS_withTags(t *testing.T) { } } -const testAccDataSourceOutscaleOAPIPublicIPSConfig = ` +const testAccDataSourcePublicIPSConfig = ` resource "outscale_public_ip" "test" {} resource "outscale_public_ip" "test1" {} resource "outscale_public_ip" "test2" {} @@ -58,7 +58,7 @@ const testAccDataSourceOutscaleOAPIPublicIPSConfig = ` } ` -const testAccDataSourceOutscaleOAPIPublicIPSConfigWithTags = ` +const testAccDataSourcePublicIPSConfigWithTags = ` resource "outscale_public_ip" "outscale_public_ip" { tags { key = "name" diff --git a/outscale/data_source_outscale_quota.go b/outscale/data_source_outscale_quota.go index 67120b89a..c99bd71ce 100644 --- a/outscale/data_source_outscale_quota.go +++ b/outscale/data_source_outscale_quota.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIQuota() *schema.Resource { +func dataSourceQuota() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIQuotaRead, + Read: dataSourceQuotaRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -59,15 +59,15 @@ func dataSourceOutscaleOAPIQuota() *schema.Resource { } } -func dataSourceOutscaleOAPIQuotaRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceQuotaRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadQuotasRequest{} filters, filtersOk := d.GetOk("filter") if filtersOk { - req.Filters = buildOutscaleOAPIQuotaDataSourceFilters(filters.(*schema.Set)) + req.Filters = buildQuotaDataSourceFilters(filters.(*schema.Set)) } var resp oscgo.ReadQuotasResponse @@ -135,7 +135,7 @@ func dataSourceOutscaleOAPIQuotaRead(d *schema.ResourceData, meta interface{}) e return nil } -func buildOutscaleOAPIQuotaDataSourceFilters(set *schema.Set) *oscgo.FiltersQuota { +func buildQuotaDataSourceFilters(set *schema.Set) *oscgo.FiltersQuota { var filters oscgo.FiltersQuota for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_quota_test.go b/outscale/data_source_outscale_quota_test.go index 92ff5c236..de1e8f50d 100644 --- a/outscale/data_source_outscale_quota_test.go +++ b/outscale/data_source_outscale_quota_test.go @@ -6,21 +6,21 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIQuota(t *testing.T) { +func TestAccDataSourceQuota(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIQuotaConfig, + Config: testAccDataSourceQuotaConfig, Check: resource.ComposeTestCheckFunc(), }, }, }) } -const testAccDataSourceOutscaleOAPIQuotaConfig = ` +const testAccDataSourceQuotaConfig = ` data "outscale_quota" "lbu-quota" { filter { name = "quota_names" diff --git a/outscale/data_source_outscale_quotas.go b/outscale/data_source_outscale_quotas.go index 27b50c03f..77a9d5006 100644 --- a/outscale/data_source_outscale_quotas.go +++ b/outscale/data_source_outscale_quotas.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIQuotas() *schema.Resource { +func dataSourceQuotas() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIQuotasRead, + Read: dataSourceQuotasRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -66,15 +66,15 @@ func dataSourceOutscaleOAPIQuotas() *schema.Resource { } } -func dataSourceOutscaleOAPIQuotasRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceQuotasRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadQuotasRequest{} filters, filtersOk := d.GetOk("filter") if filtersOk { - req.Filters = buildOutscaleOAPIQuotaDataSourceFilters(filters.(*schema.Set)) + req.Filters = buildQuotaDataSourceFilters(filters.(*schema.Set)) } var resp oscgo.ReadQuotasResponse diff --git a/outscale/data_source_outscale_quotas_test.go b/outscale/data_source_outscale_quotas_test.go index 7062de18b..da5efb55f 100644 --- a/outscale/data_source_outscale_quotas_test.go +++ b/outscale/data_source_outscale_quotas_test.go @@ -6,20 +6,20 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourcesOutscaleOAPIQuotas(t *testing.T) { +func TestAccDataSourcesQuotas(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourcesOutscaleOAPIQuotasConfig, + Config: testAccDataSourcesQuotasConfig, Check: resource.ComposeTestCheckFunc(), }, }, }) } -const testAccDataSourcesOutscaleOAPIQuotasConfig = ` +const testAccDataSourcesQuotasConfig = ` data "outscale_quotas" "all-quotas" {} ` diff --git a/outscale/data_source_outscale_regions.go b/outscale/data_source_outscale_regions.go index f83998990..fd5c4a195 100644 --- a/outscale/data_source_outscale_regions.go +++ b/outscale/data_source_outscale_regions.go @@ -10,9 +10,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIRegions() *schema.Resource { +func dataSourceRegions() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIRegionsRead, + Read: dataSourceRegionsRead, Schema: map[string]*schema.Schema{ "request_id": { Type: schema.TypeString, @@ -38,8 +38,8 @@ func dataSourceOutscaleOAPIRegions() *schema.Resource { } } -func dataSourceOutscaleOAPIRegionsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceRegionsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var resp oscgo.ReadRegionsResponse var err error diff --git a/outscale/data_source_outscale_regions_test.go b/outscale/data_source_outscale_regions_test.go index 485bef254..15d2ee8b8 100644 --- a/outscale/data_source_outscale_regions_test.go +++ b/outscale/data_source_outscale_regions_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIRegionsDataSource_basic(t *testing.T) { +func TestAccRegionsDataSource_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -17,16 +17,16 @@ func TestAccOutscaleOAPIRegionsDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIRegionsDataSourceConfig, + Config: testAccCheckRegionsDataSourceConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIRegionsDataSourceID("data.outscale_regions.regions"), + testAccCheckRegionsDataSourceID("data.outscale_regions.regions"), ), }, }, }) } -func testAccCheckOutscaleOAPIRegionsDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckRegionsDataSourceID(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -40,6 +40,6 @@ func testAccCheckOutscaleOAPIRegionsDataSourceID(n string) resource.TestCheckFun } } -var testAccCheckOutscaleOAPIRegionsDataSourceConfig = ` +var testAccCheckRegionsDataSourceConfig = ` data "outscale_regions" "regions" {} ` diff --git a/outscale/data_source_outscale_route_table.go b/outscale/data_source_outscale_route_table.go index 4bac0496e..d6f86b0b9 100644 --- a/outscale/data_source_outscale_route_table.go +++ b/outscale/data_source_outscale_route_table.go @@ -15,9 +15,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func dataSourceOutscaleOAPIRouteTable() *schema.Resource { +func dataSourceRouteTable() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIRouteTableRead, + Read: dataSourceRouteTableRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -131,8 +131,8 @@ func dataSourceOutscaleOAPIRouteTable() *schema.Resource { } } -func dataSourceOutscaleOAPIRouteTableRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceRouteTableRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI routeTableID, routeTableIDOk := d.GetOk("route_table_id") filter, filterOk := d.GetOk("filter") @@ -148,7 +148,7 @@ func dataSourceOutscaleOAPIRouteTableRead(d *schema.ResourceData, meta interface } if filterOk { - params.Filters = buildOutscaleOAPIDataSourceRouteTableFilters(filter.(*schema.Set)) + params.Filters = buildDataSourceRouteTableFilters(filter.(*schema.Set)) } var resp oscgo.ReadRouteTablesResponse @@ -175,7 +175,7 @@ func dataSourceOutscaleOAPIRouteTableRead(d *schema.ResourceData, meta interface rt := resp.GetRouteTables()[0] if err := - d.Set("route_propagating_virtual_gateways", setOSCAPIPropagatingVirtualGateways(rt.GetRoutePropagatingVirtualGateways())); err != nil { + d.Set("route_propagating_virtual_gateways", setPropagatingVirtualGateways(rt.GetRoutePropagatingVirtualGateways())); err != nil { return err } if err := d.Set("route_table_id", rt.GetRouteTableId()); err != nil { @@ -184,19 +184,19 @@ func dataSourceOutscaleOAPIRouteTableRead(d *schema.ResourceData, meta interface if err := d.Set("net_id", rt.GetNetId()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(rt.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(rt.GetTags())); err != nil { return err } - if err := d.Set("routes", setOSCAPIRoutes(rt.GetRoutes())); err != nil { + if err := d.Set("routes", setRoutes(rt.GetRoutes())); err != nil { return err } d.SetId(rt.GetRouteTableId()) - return d.Set("link_route_tables", setOSCAPILinkRouteTables(rt.GetLinkRouteTables())) + return d.Set("link_route_tables", setLinkRouteTables(rt.GetLinkRouteTables())) } -func buildOutscaleOAPIDataSourceRouteTableFilters(set *schema.Set) *oscgo.FiltersRouteTable { +func buildDataSourceRouteTableFilters(set *schema.Set) *oscgo.FiltersRouteTable { var filters oscgo.FiltersRouteTable for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_route_table_test.go b/outscale/data_source_outscale_route_table_test.go index 8919f3184..ef59568e9 100644 --- a/outscale/data_source_outscale_route_table_test.go +++ b/outscale/data_source_outscale_route_table_test.go @@ -8,16 +8,16 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccDataSourceOutscaleOAPIRouteTable_basic(t *testing.T) { +func TestAccDataSourceRouteTable_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIRouteTableGroupConfig, + Config: testAccDataSourceRouteTableGroupConfig, Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPIRouteTableCheck("data.outscale_route_table.by_filter"), - testAccDataSourceOutscaleOAPIRouteTableCheck("data.outscale_route_table.by_id"), + testAccDataSourceRouteTableCheck("data.outscale_route_table.by_filter"), + testAccDataSourceRouteTableCheck("data.outscale_route_table.by_id"), ), ExpectNonEmptyPlan: true, }, @@ -25,7 +25,7 @@ func TestAccDataSourceOutscaleOAPIRouteTable_basic(t *testing.T) { }) } -func testAccDataSourceOutscaleOAPIRouteTableCheck(name string) resource.TestCheckFunc { +func testAccDataSourceRouteTableCheck(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -84,7 +84,7 @@ func testAccDataSourceOutscaleOAPIRouteTableCheck(name string) resource.TestChec } } -const testAccDataSourceOutscaleOAPIRouteTableGroupConfig = ` +const testAccDataSourceRouteTableGroupConfig = ` resource "outscale_net" "test" { ip_range = "172.16.0.0/16" diff --git a/outscale/data_source_outscale_route_tables.go b/outscale/data_source_outscale_route_tables.go index 07832a9a2..5345fcee6 100644 --- a/outscale/data_source_outscale_route_tables.go +++ b/outscale/data_source_outscale_route_tables.go @@ -11,9 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIRouteTables() *schema.Resource { +func dataSourceRouteTables() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIRouteTablesRead, + Read: dataSourceRouteTablesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -139,8 +139,8 @@ func dataSourceOutscaleOAPIRouteTables() *schema.Resource { } } -func dataSourceOutscaleOAPIRouteTablesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceRouteTablesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI rtbID, rtbOk := d.GetOk("route_table_id") filter, filterOk := d.GetOk("filter") if !filterOk && !rtbOk { @@ -163,7 +163,7 @@ func dataSourceOutscaleOAPIRouteTablesRead(d *schema.ResourceData, meta interfac } if filterOk { - params.Filters = buildOutscaleOAPIDataSourceRouteTableFilters(filter.(*schema.Set)) + params.Filters = buildDataSourceRouteTableFilters(filter.(*schema.Set)) } var resp oscgo.ReadRouteTablesResponse @@ -196,12 +196,12 @@ func dataSourceOutscaleOAPIRouteTablesRead(d *schema.ResourceData, meta interfac for k, v := range rt { routeTable := make(map[string]interface{}) - routeTable["route_propagating_virtual_gateways"] = setOSCAPIPropagatingVirtualGateways(v.GetRoutePropagatingVirtualGateways()) + routeTable["route_propagating_virtual_gateways"] = setPropagatingVirtualGateways(v.GetRoutePropagatingVirtualGateways()) routeTable["route_table_id"] = v.GetRouteTableId() routeTable["net_id"] = v.GetNetId() - routeTable["tags"] = tagsOSCAPIToMap(v.GetTags()) - routeTable["routes"] = setOSCAPIRoutes(v.GetRoutes()) - routeTable["link_route_tables"] = setOSCAPILinkRouteTables(v.GetLinkRouteTables()) + routeTable["tags"] = tagsToMap(v.GetTags()) + routeTable["routes"] = setRoutes(v.GetRoutes()) + routeTable["link_route_tables"] = setLinkRouteTables(v.GetLinkRouteTables()) routeTables[k] = routeTable } diff --git a/outscale/data_source_outscale_route_tables_test.go b/outscale/data_source_outscale_route_tables_test.go index fa526e3ea..b4b1ace77 100644 --- a/outscale/data_source_outscale_route_tables_test.go +++ b/outscale/data_source_outscale_route_tables_test.go @@ -6,14 +6,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIRouteTables_basic(t *testing.T) { +func TestAccDataSourceRouteTables_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIRouteTablesGroupConfig, + Config: testAccDataSourceRouteTablesGroupConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_route_tables.by_filter", "route_tables.#", "1"), resource.TestCheckResourceAttr("data.outscale_route_tables.by_id", "route_tables.#", "1"), @@ -23,7 +23,7 @@ func TestAccDataSourceOutscaleOAPIRouteTables_basic(t *testing.T) { }) } -const testAccDataSourceOutscaleOAPIRouteTablesGroupConfig = ` +const testAccDataSourceRouteTablesGroupConfig = ` resource "outscale_net" "test" { ip_range = "172.16.0.0/16" diff --git a/outscale/data_source_outscale_security_group.go b/outscale/data_source_outscale_security_group.go index 6a7738523..088af49c8 100644 --- a/outscale/data_source_outscale_security_group.go +++ b/outscale/data_source_outscale_security_group.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPISecurityGroup() *schema.Resource { +func dataSourceSecurityGroup() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPISecurityGroupRead, + Read: dataSourceSecurityGroupRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -157,8 +157,8 @@ func dataSourceOutscaleOAPISecurityGroup() *schema.Resource { } } -func dataSourceOutscaleOAPISecurityGroupRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSecurityGroupRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadSecurityGroupsRequest{} filters, filtersOk := d.GetOk("filter") @@ -177,7 +177,7 @@ func dataSourceOutscaleOAPISecurityGroupRead(d *schema.ResourceData, meta interf } if filtersOk { - req.SetFilters(buildOutscaleOAPIDataSourceSecurityGroupFilters(filters.(*schema.Set))) + req.SetFilters(buildDataSourceSecurityGroupFilters(filters.(*schema.Set))) } var err error @@ -231,16 +231,16 @@ func dataSourceOutscaleOAPISecurityGroupRead(d *schema.ResourceData, meta interf if err := d.Set("account_id", sg.GetAccountId()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(sg.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(sg.GetTags())); err != nil { return err } - if err := d.Set("inbound_rules", flattenOAPISecurityGroupRule(sg.GetInboundRules())); err != nil { + if err := d.Set("inbound_rules", flattenSecurityGroupRule(sg.GetInboundRules())); err != nil { return err } - return d.Set("outbound_rules", flattenOAPISecurityGroupRule(sg.GetOutboundRules())) + return d.Set("outbound_rules", flattenSecurityGroupRule(sg.GetOutboundRules())) } -func buildOutscaleOAPIDataSourceSecurityGroupFilters(set *schema.Set) oscgo.FiltersSecurityGroup { +func buildDataSourceSecurityGroupFilters(set *schema.Set) oscgo.FiltersSecurityGroup { var filters oscgo.FiltersSecurityGroup for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_security_group_test.go b/outscale/data_source_outscale_security_group_test.go index bb11876cf..f9041a3e6 100644 --- a/outscale/data_source_outscale_security_group_test.go +++ b/outscale/data_source_outscale_security_group_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccDataSourceOutscaleOAPISecurityGroup_basic(t *testing.T) { +func TestAccDataSourceSecurityGroup_basic(t *testing.T) { t.Parallel() rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ @@ -17,17 +17,17 @@ func TestAccDataSourceOutscaleOAPISecurityGroup_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISecurityGroupConfig(rInt), + Config: testAccDataSourceSecurityGroupConfig(rInt), Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPISecurityGroupCheck("data.outscale_security_group.by_id"), - //testAccDataSourceOutscaleOAPISecurityGroupCheck("data.outscale_security_group.by_filter"), + testAccDataSourceSecurityGroupCheck("data.outscale_security_group.by_id"), + //testAccDataSourceSecurityGroupCheck("data.outscale_security_group.by_filter"), ), }, }, }) } -func TestAccDataSourceOutscaleOAPISecurityGroupPublic(t *testing.T) { +func TestAccDataSourceSecurityGroupPublic(t *testing.T) { t.Parallel() rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ @@ -35,16 +35,16 @@ func TestAccDataSourceOutscaleOAPISecurityGroupPublic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISecurityGroupPublicConfig(rInt), + Config: testAccDataSourceSecurityGroupPublicConfig(rInt), Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPISecurityGroupCheck("data.outscale_security_group.by_filter_public"), + testAccDataSourceSecurityGroupCheck("data.outscale_security_group.by_filter_public"), ), }, }, }) } -func testAccDataSourceOutscaleOAPISecurityGroupCheck(name string) resource.TestCheckFunc { +func testAccDataSourceSecurityGroupCheck(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -75,7 +75,7 @@ func testAccDataSourceOutscaleOAPISecurityGroupCheck(name string) resource.TestC } } -func testAccDataSourceOutscaleOAPISecurityGroupConfig(rInt int) string { +func testAccDataSourceSecurityGroupConfig(rInt int) string { return fmt.Sprintf(` resource "outscale_net" "vpc" { ip_range = "10.0.0.0/16" @@ -107,7 +107,7 @@ func testAccDataSourceOutscaleOAPISecurityGroupConfig(rInt int) string { #}`, rInt, rInt) } -func testAccDataSourceOutscaleOAPISecurityGroupPublicConfig(rInt int) string { +func testAccDataSourceSecurityGroupPublicConfig(rInt int) string { return fmt.Sprintf(` resource "outscale_security_group" "test" { description = "Used in the terraform acceptance tests" diff --git a/outscale/data_source_outscale_security_groups.go b/outscale/data_source_outscale_security_groups.go index dd8a1e80e..202fb70ef 100644 --- a/outscale/data_source_outscale_security_groups.go +++ b/outscale/data_source_outscale_security_groups.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPISecurityGroups() *schema.Resource { +func dataSourceSecurityGroups() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPISecurityGroupsRead, + Read: dataSourceSecurityGroupsRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -177,8 +177,8 @@ func dataSourceOutscaleOAPISecurityGroups() *schema.Resource { } } -func dataSourceOutscaleOAPISecurityGroupsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSecurityGroupsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadSecurityGroupsRequest{} @@ -205,7 +205,7 @@ func dataSourceOutscaleOAPISecurityGroupsRead(d *schema.ResourceData, meta inter } if filtersOk { - req.SetFilters(buildOutscaleOAPIDataSourceSecurityGroupFilters(filters.(*schema.Set))) + req.SetFilters(buildDataSourceSecurityGroupFilters(filters.(*schema.Set))) } var err error @@ -248,9 +248,9 @@ func dataSourceOutscaleOAPISecurityGroupsRead(d *schema.ResourceData, meta inter s["net_id"] = v.GetNetId() } s["account_id"] = v.GetAccountId() - s["tags"] = tagsOSCAPIToMap(v.GetTags()) - s["inbound_rules"] = flattenOAPISecurityGroupRule(v.GetInboundRules()) - s["outbound_rules"] = flattenOAPISecurityGroupRule(v.GetOutboundRules()) + s["tags"] = tagsToMap(v.GetTags()) + s["inbound_rules"] = flattenSecurityGroupRule(v.GetInboundRules()) + s["outbound_rules"] = flattenSecurityGroupRule(v.GetOutboundRules()) sg[k] = s } @@ -263,7 +263,7 @@ func dataSourceOutscaleOAPISecurityGroupsRead(d *schema.ResourceData, meta inter return err } -func flattenOAPISecurityGroupRule(p []oscgo.SecurityGroupRule) []map[string]interface{} { +func flattenSecurityGroupRule(p []oscgo.SecurityGroupRule) []map[string]interface{} { ips := make([]map[string]interface{}, len(p)) for k, v := range p { diff --git a/outscale/data_source_outscale_security_groups_test.go b/outscale/data_source_outscale_security_groups_test.go index 0d5f911bb..57940a1f9 100644 --- a/outscale/data_source_outscale_security_groups_test.go +++ b/outscale/data_source_outscale_security_groups_test.go @@ -8,14 +8,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPISecurityGroups_vpc(t *testing.T) { +func TestAccDataSourceSecurityGroups_vpc(t *testing.T) { rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISecurityGroupConfigVPC(rInt), + Config: testAccDataSourceSecurityGroupConfigVPC(rInt), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "data.outscale_security_groups.by_id", "security_groups.#", "3"), @@ -27,7 +27,7 @@ func TestAccDataSourceOutscaleOAPISecurityGroups_vpc(t *testing.T) { }) } -func testAccDataSourceOutscaleOAPISecurityGroupConfigVPC(rInt int) string { +func testAccDataSourceSecurityGroupConfigVPC(rInt int) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_server_certificate.go b/outscale/data_source_outscale_server_certificate.go index 50031ee6b..8d469889d 100644 --- a/outscale/data_source_outscale_server_certificate.go +++ b/outscale/data_source_outscale_server_certificate.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func datasourceOutscaleOAPIServerCertificate() *schema.Resource { +func dataSourceServerCertificate() *schema.Resource { return &schema.Resource{ - Read: datasourceOutscaleOAPIServerCertificateRead, + Read: dataSourceServerCertificateRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "expiration_date": { @@ -45,8 +45,8 @@ func datasourceOutscaleOAPIServerCertificate() *schema.Resource { } } -func datasourceOutscaleOAPIServerCertificateRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceServerCertificateRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") @@ -58,7 +58,7 @@ func datasourceOutscaleOAPIServerCertificateRead(d *schema.ResourceData, meta in params := oscgo.ReadServerCertificatesRequest{} if filtersOk { - params.Filters = buildOutscaleOSCAPIDataSourceServerCertificateFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceServerCertificateFilters(filters.(*schema.Set)) } var resp oscgo.ReadServerCertificatesResponse @@ -99,7 +99,7 @@ func datasourceOutscaleOAPIServerCertificateRead(d *schema.ResourceData, meta in return nil } -func buildOutscaleOSCAPIDataSourceServerCertificateFilters(set *schema.Set) *oscgo.FiltersServerCertificate { +func buildDataSourceServerCertificateFilters(set *schema.Set) *oscgo.FiltersServerCertificate { var filters oscgo.FiltersServerCertificate for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_server_certificate_test.go b/outscale/data_source_outscale_server_certificate_test.go index bf68db7a0..3f3ce106a 100644 --- a/outscale/data_source_outscale_server_certificate_test.go +++ b/outscale/data_source_outscale_server_certificate_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform/helper/acctest" ) -func TestAccOutscaleOAPIServerCertificateDatasource_basic(t *testing.T) { +func TestAccServerCertificateDatasource_basic(t *testing.T) { t.Parallel() rName := acctest.RandomWithPrefix("acc-test") body := `-----BEGIN CERTIFICATE----- @@ -100,13 +100,13 @@ kbcI5Y2wveEgMqPSRya2OapYGiPeqYhg6JAGPRXtOfOq9IUDcPuc2emnihNpSa8y Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIServerCertificateDatasourceConfig(rName, body, private), + Config: testAccServerCertificateDatasourceConfig(rName, body, private), }, }, }) } -func testAccOutscaleOAPIServerCertificateDatasourceConfig(name, body, privateKey string) string { +func testAccServerCertificateDatasourceConfig(name, body, privateKey string) string { return fmt.Sprintf(` resource "outscale_server_certificate" "test" { name = %[1]q diff --git a/outscale/data_source_outscale_server_certificates.go b/outscale/data_source_outscale_server_certificates.go index 236e838db..a74c9bd3e 100644 --- a/outscale/data_source_outscale_server_certificates.go +++ b/outscale/data_source_outscale_server_certificates.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func datasourceOutscaleOAPIServerCertificates() *schema.Resource { +func dataSourceServerCertificates() *schema.Resource { return &schema.Resource{ - Read: datasourceOutscaleOAPIServerCertificatesRead, + Read: dataSourceServerCertificatesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "server_certificates": { @@ -57,8 +57,8 @@ func datasourceOutscaleOAPIServerCertificates() *schema.Resource { } } -func datasourceOutscaleOAPIServerCertificatesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceServerCertificatesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") @@ -66,7 +66,7 @@ func datasourceOutscaleOAPIServerCertificatesRead(d *schema.ResourceData, meta i params := oscgo.ReadServerCertificatesRequest{} if filtersOk { - params.Filters = buildOutscaleOSCAPIDataSourceServerCertificateFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceServerCertificateFilters(filters.(*schema.Set)) } var resp oscgo.ReadServerCertificatesResponse diff --git a/outscale/data_source_outscale_server_certificates_test.go b/outscale/data_source_outscale_server_certificates_test.go index 87d4afc47..076a6bad7 100644 --- a/outscale/data_source_outscale_server_certificates_test.go +++ b/outscale/data_source_outscale_server_certificates_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIServerCertificatesDatasource_basic(t *testing.T) { +func TestAccServerCertificatesDatasource_basic(t *testing.T) { t.Parallel() rName := acctest.RandomWithPrefix("acc-test") body := `-----BEGIN CERTIFICATE----- @@ -100,13 +100,13 @@ kbcI5Y2wveEgMqPSRya2OapYGiPeqYhg6JAGPRXtOfOq9IUDcPuc2emnihNpSa8y Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIServerCertificatesDatasourceConfig(rName, body, private), + Config: testAccServerCertificatesDatasourceConfig(rName, body, private), }, }, }) } -func testAccOutscaleOAPIServerCertificatesDatasourceConfig(name, body, privateKey string) string { +func testAccServerCertificatesDatasourceConfig(name, body, privateKey string) string { return fmt.Sprintf(` resource "outscale_server_certificate" "test" { name = %[1]q diff --git a/outscale/data_source_outscale_snapshot.go b/outscale/data_source_outscale_snapshot.go index 8202d5ce7..d2f9c2019 100644 --- a/outscale/data_source_outscale_snapshot.go +++ b/outscale/data_source_outscale_snapshot.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPISnapshot() *schema.Resource { +func dataSourceSnapshot() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPISnapshotRead, + Read: dataSourceSnapshotRead, Schema: map[string]*schema.Schema{ //selection criteria @@ -86,8 +86,8 @@ func dataSourceOutscaleOAPISnapshot() *schema.Resource { } } -func dataSourceOutscaleOAPISnapshotRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSnapshotRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI restorableUsers, restorableUsersOk := d.GetOk("permission_to_create_volume") filters, filtersOk := d.GetOk("filter") @@ -104,11 +104,11 @@ func dataSourceOutscaleOAPISnapshotRead(d *schema.ResourceData, meta interface{} filter := oscgo.FiltersSnapshot{} if restorableUsersOk { - filter.SetPermissionsToCreateVolumeAccountIds(oapiExpandStringList(restorableUsers.([]interface{}))) + filter.SetPermissionsToCreateVolumeAccountIds(ExpandStringList(restorableUsers.([]interface{}))) params.SetFilters(filter) } if filtersOk { - buildOutscaleOapiSnapshootDataSourceFilters(filters.(*schema.Set), params.Filters) + buildSnapshotDataSourceFilters(filters.(*schema.Set), params.Filters) } if ownersOk { filter.SetAccountIds([]string{owners.(string)}) @@ -143,10 +143,10 @@ func dataSourceOutscaleOAPISnapshotRead(d *schema.ResourceData, meta interface{} snapshot := resp.GetSnapshots()[0] //Single Snapshot found so set to state - return snapshotOAPIDescriptionAttributes(d, &snapshot) + return snapshotDescriptionAttributes(d, &snapshot) } -func snapshotOAPIDescriptionAttributes(d *schema.ResourceData, snapshot *oscgo.Snapshot) error { +func snapshotDescriptionAttributes(d *schema.ResourceData, snapshot *oscgo.Snapshot) error { d.SetId(snapshot.GetSnapshotId()) if err := d.Set("description", snapshot.GetDescription()); err != nil { return err @@ -185,10 +185,10 @@ func snapshotOAPIDescriptionAttributes(d *schema.ResourceData, snapshot *oscgo.S return err } - return d.Set("tags", tagsOSCAPIToMap(snapshot.GetTags())) + return d.Set("tags", tagsToMap(snapshot.GetTags())) } -func buildOutscaleOapiSnapshootDataSourceFilters(set *schema.Set, filter *oscgo.FiltersSnapshot) *oscgo.FiltersSnapshot { +func buildSnapshotDataSourceFilters(set *schema.Set, filter *oscgo.FiltersSnapshot) *oscgo.FiltersSnapshot { for _, v := range set.List() { m := v.(map[string]interface{}) @@ -246,7 +246,8 @@ func buildOutscaleOapiSnapshootDataSourceFilters(set *schema.Set, filter *oscgo. return filter } -func oapiExpandStringList(configured []interface{}) []string { +// TODO MOVE To utils +func ExpandStringList(configured []interface{}) []string { vs := make([]string, 0, len(configured)) for _, v := range configured { val, ok := v.(string) diff --git a/outscale/data_source_outscale_snapshot_export_task.go b/outscale/data_source_outscale_snapshot_export_task.go index 1d4573b7c..86c57b32c 100644 --- a/outscale/data_source_outscale_snapshot_export_task.go +++ b/outscale/data_source_outscale_snapshot_export_task.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPISnapshotExportTask() *schema.Resource { +func dataSourceSnapshotExportTask() *schema.Resource { return &schema.Resource{ - Read: dataSourceOAPISnapshotExportTaskRead, + Read: dataSourceSnapshotExportTaskRead, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -80,14 +80,14 @@ func dataSourceOutscaleOAPISnapshotExportTask() *schema.Resource { } } -func dataSourceOAPISnapshotExportTaskRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSnapshotExportTaskRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") filtersReq := &oscgo.FiltersExportTask{} if filtersOk { - filtersReq = buildOutscaleOSCAPIDataSourceSnapshotExportTaskFilters(filters.(*schema.Set)) + filtersReq = buildDataSourceSnapshotExportTaskFilters(filters.(*schema.Set)) } var resp oscgo.ReadSnapshotExportTasksResponse @@ -140,7 +140,7 @@ func dataSourceOAPISnapshotExportTaskRead(d *schema.ResourceData, meta interface if err = d.Set("osu_export", exp); err != nil { return err } - if err = d.Set("tags", tagsOSCAPIToMap(v.GetTags())); err != nil { + if err = d.Set("tags", tagsToMap(v.GetTags())); err != nil { return err } @@ -149,7 +149,7 @@ func dataSourceOAPISnapshotExportTaskRead(d *schema.ResourceData, meta interface return nil } -func buildOutscaleOSCAPIDataSourceSnapshotExportTaskFilters(set *schema.Set) *oscgo.FiltersExportTask { +func buildDataSourceSnapshotExportTaskFilters(set *schema.Set) *oscgo.FiltersExportTask { var filters oscgo.FiltersExportTask for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_snapshot_export_task_test.go b/outscale/data_source_outscale_snapshot_export_task_test.go index d1bfcd7ff..84384cf9a 100644 --- a/outscale/data_source_outscale_snapshot_export_task_test.go +++ b/outscale/data_source_outscale_snapshot_export_task_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPISnapshotExportTaskDataSource_basic(t *testing.T) { +func TestAccSnapshotExportTaskDataSource_basic(t *testing.T) { t.Parallel() imageName := acctest.RandomWithPrefix("terraform-export-") resource.Test(t, resource.TestCase{ @@ -20,16 +20,16 @@ func TestAccOutscaleOAPISnapshotExportTaskDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotExportTaskDataSourceConfig(imageName), + Config: testAccSnapshotExportTaskDataSourceConfig(imageName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleSnapshotExportTaskDataSourceID("data.outscale_snapshot_export_task.export_task"), + testAccCheckSnapshotExportTaskDataSourceID("data.outscale_snapshot_export_task.export_task"), ), }, }, }) } -func testAccCheckOutscaleSnapshotExportTaskDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckSnapshotExportTaskDataSourceID(n string) resource.TestCheckFunc { // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -44,7 +44,7 @@ func testAccCheckOutscaleSnapshotExportTaskDataSourceID(n string) resource.TestC } } -func testAccOutscaleOAPISnapshotExportTaskDataSourceConfig(testName string) string { +func testAccSnapshotExportTaskDataSourceConfig(testName string) string { var stringTemplate = ` resource "outscale_volume" "outscale_volume_snap" { subregion_name = "eu-west-2a" diff --git a/outscale/data_source_outscale_snapshot_export_tasks.go b/outscale/data_source_outscale_snapshot_export_tasks.go index 71b4c13d1..7777b0584 100644 --- a/outscale/data_source_outscale_snapshot_export_tasks.go +++ b/outscale/data_source_outscale_snapshot_export_tasks.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPISnapshotExportTasks() *schema.Resource { +func dataSourceSnapshotExportTasks() *schema.Resource { return &schema.Resource{ - Read: dataSourceOAPISnapshotExportTasksRead, + Read: dataSourceSnapshotExportTasksRead, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -88,14 +88,14 @@ func dataSourceOutscaleOAPISnapshotExportTasks() *schema.Resource { } } -func dataSourceOAPISnapshotExportTasksRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSnapshotExportTasksRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") filtersReq := &oscgo.FiltersExportTask{} if filtersOk { - filtersReq = buildOutscaleOSCAPIDataSourceSnapshotExportTaskFilters(filters.(*schema.Set)) + filtersReq = buildDataSourceSnapshotExportTaskFilters(filters.(*schema.Set)) } var resp oscgo.ReadSnapshotExportTasksResponse @@ -140,7 +140,7 @@ func dataSourceOAPISnapshotExportTasksRead(d *schema.ResourceData, meta interfac snapshot["snapshot_id"] = v.GetSnapshotId() snapshot["osu_export"] = exp - snapshot["tags"] = tagsOSCAPIToMap(v.GetTags()) + snapshot["tags"] = tagsToMap(v.GetTags()) snapshots[k] = snapshot } diff --git a/outscale/data_source_outscale_snapshot_export_tasks_test.go b/outscale/data_source_outscale_snapshot_export_tasks_test.go index 10e2553b5..b3451aeee 100644 --- a/outscale/data_source_outscale_snapshot_export_tasks_test.go +++ b/outscale/data_source_outscale_snapshot_export_tasks_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPISnapshotExportTasksDataSource_basic(t *testing.T) { +func TestAccSnapshotExportTasksDataSource_basic(t *testing.T) { imageName := acctest.RandomWithPrefix("terraform-export") resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -17,16 +17,16 @@ func TestAccOutscaleOAPISnapshotExportTasksDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotExportTasksDataSourceConfig(imageName), + Config: testAccSnapshotExportTasksDataSourceConfig(imageName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleSnapshotExportTaskDataSourceID("data.outscale_snapshot_export_tasks.export_tasks"), + testAccCheckSnapshotExportTaskDataSourceID("data.outscale_snapshot_export_tasks.export_tasks"), ), }, }, }) } -func testAccOutscaleOAPISnapshotExportTasksDataSourceConfig(testName string) string { +func testAccSnapshotExportTasksDataSourceConfig(testName string) string { var stringTemplate = ` resource "outscale_volume" "outscale_volume_snap" { subregion_name = "eu-west-2a" diff --git a/outscale/data_source_outscale_snapshot_test.go b/outscale/data_source_outscale_snapshot_test.go index e00e1f673..3827f6000 100644 --- a/outscale/data_source_outscale_snapshot_test.go +++ b/outscale/data_source_outscale_snapshot_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPISnapshotDataSource_basic(t *testing.T) { +func TestAccSnapshotDataSource_basic(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -18,9 +18,9 @@ func TestAccOutscaleOAPISnapshotDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPISnapshotDataSourceConfig(region), + Config: testAccCheckSnapshotDataSourceConfig(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPISnapshotDataSourceID("data.outscale_snapshot.snapshot"), + testAccCheckSnapshotDataSourceID("data.outscale_snapshot.snapshot"), resource.TestCheckResourceAttr("data.outscale_snapshot.snapshot", "volume_size", "1"), ), }, @@ -28,7 +28,7 @@ func TestAccOutscaleOAPISnapshotDataSource_basic(t *testing.T) { }) } -func TestAccOutscaleOAPISnapshotDataSource_multipleFilters(t *testing.T) { +func TestAccSnapshotDataSource_multipleFilters(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -37,9 +37,9 @@ func TestAccOutscaleOAPISnapshotDataSource_multipleFilters(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPISnapshotDataSourceConfigWithMultipleFilters(region), + Config: testAccCheckSnapshotDataSourceConfigWithMultipleFilters(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPISnapshotDataSourceID("data.outscale_snapshot.snapshot"), + testAccCheckSnapshotDataSourceID("data.outscale_snapshot.snapshot"), resource.TestCheckResourceAttr("data.outscale_snapshot.snapshot", "volume_size", "10"), ), }, @@ -47,7 +47,7 @@ func TestAccOutscaleOAPISnapshotDataSource_multipleFilters(t *testing.T) { }) } -func testAccCheckOutscaleOAPISnapshotDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckSnapshotDataSourceID(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -61,7 +61,7 @@ func testAccCheckOutscaleOAPISnapshotDataSourceID(n string) resource.TestCheckFu } } -func testAccCheckOutscaleOAPISnapshotDataSourceConfig(region string) string { +func testAccCheckSnapshotDataSourceConfig(region string) string { return fmt.Sprintf(` resource "outscale_volume" "example" { subregion_name = "%sa" @@ -78,7 +78,7 @@ func testAccCheckOutscaleOAPISnapshotDataSourceConfig(region string) string { `, region) } -func testAccCheckOutscaleOAPISnapshotDataSourceConfigWithMultipleFilters(region string) string { +func testAccCheckSnapshotDataSourceConfigWithMultipleFilters(region string) string { return fmt.Sprintf(` resource "outscale_volume" "external1" { subregion_name = "%sa" diff --git a/outscale/data_source_outscale_snapshots.go b/outscale/data_source_outscale_snapshots.go index 42367a892..279414c3b 100644 --- a/outscale/data_source_outscale_snapshots.go +++ b/outscale/data_source_outscale_snapshots.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPISnapshots() *schema.Resource { +func dataSourceSnapshots() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPISnapshotsRead, + Read: dataSourceSnapshotsRead, Schema: map[string]*schema.Schema{ //selection criteria @@ -105,8 +105,8 @@ func dataSourceOutscaleOAPISnapshots() *schema.Resource { } } -func dataSourceOutscaleOAPISnapshotsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSnapshotsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI restorableUsers, restorableUsersOk := d.GetOk("permission_to_create_volume") filters, filtersOk := d.GetOk("filter") @@ -122,18 +122,18 @@ func dataSourceOutscaleOAPISnapshotsRead(d *schema.ResourceData, meta interface{ } filter := oscgo.FiltersSnapshot{} if restorableUsersOk { - filter.SetPermissionsToCreateVolumeAccountIds(oapiExpandStringList(restorableUsers.([]interface{}))) + filter.SetPermissionsToCreateVolumeAccountIds(ExpandStringList(restorableUsers.([]interface{}))) params.SetFilters(filter) } if filtersOk { - buildOutscaleOapiSnapshootDataSourceFilters(filters.(*schema.Set), params.Filters) + buildSnapshotDataSourceFilters(filters.(*schema.Set), params.Filters) } if ownersOk { - filter.SetAccountIds(oapiExpandStringList(owners.([]interface{}))) + filter.SetAccountIds(ExpandStringList(owners.([]interface{}))) params.SetFilters(filter) } if snapshotIdsOk { - filter.SetSnapshotIds(oapiExpandStringList(snapshotIds.([]interface{}))) + filter.SetSnapshotIds(ExpandStringList(snapshotIds.([]interface{}))) params.SetFilters(filter) } @@ -168,7 +168,7 @@ func dataSourceOutscaleOAPISnapshotsRead(d *schema.ResourceData, meta interface{ snapshot["state"] = v.GetState() snapshot["volume_id"] = v.GetVolumeId() snapshot["volume_size"] = v.GetVolumeSize() - snapshot["tags"] = tagsOSCAPIToMap(v.GetTags()) + snapshot["tags"] = tagsToMap(v.GetTags()) lp := make([]map[string]interface{}, 1) lp[0] = make(map[string]interface{}) diff --git a/outscale/data_source_outscale_snapshots_test.go b/outscale/data_source_outscale_snapshots_test.go index 43c968107..6785fe2e7 100644 --- a/outscale/data_source_outscale_snapshots_test.go +++ b/outscale/data_source_outscale_snapshots_test.go @@ -6,13 +6,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPISnapshotsDataSource_basic(t *testing.T) { +func TestAccSnapshotsDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPISnapshotsDataSourceConfig, + Config: testAccCheckSnapshotsDataSourceConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_snapshots.outscale_snapshots", "snapshots.#", "1"), ), @@ -21,7 +21,7 @@ func TestAccOutscaleOAPISnapshotsDataSource_basic(t *testing.T) { }) } -const testAccCheckOutscaleOAPISnapshotsDataSourceConfig = ` +const testAccCheckSnapshotsDataSourceConfig = ` resource "outscale_volume" "example" { subregion_name = "eu-west-2a" size = 1 diff --git a/outscale/data_source_outscale_subnet.go b/outscale/data_source_outscale_subnet.go index d960d1ecd..00616b1b7 100644 --- a/outscale/data_source_outscale_subnet.go +++ b/outscale/data_source_outscale_subnet.go @@ -15,9 +15,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPISubnet() *schema.Resource { +func dataSourceSubnet() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPISubnetRead, + Read: dataSourceSubnetRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -59,8 +59,8 @@ func dataSourceOutscaleOAPISubnet() *schema.Resource { } } -func dataSourceOutscaleOAPISubnetRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSubnetRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadSubnetsRequest{} @@ -71,7 +71,7 @@ func dataSourceOutscaleOAPISubnetRead(d *schema.ResourceData, meta interface{}) filters, filtersOk := d.GetOk("filter") if filtersOk { - req.Filters = buildOutscaleOAPISubnetDataSourceFilters(filters.(*schema.Set)) + req.Filters = buildSubnetDataSourceFilters(filters.(*schema.Set)) } var resp oscgo.ReadSubnetsResponse @@ -120,7 +120,7 @@ func dataSourceOutscaleOAPISubnetRead(d *schema.ResourceData, meta interface{}) if err := d.Set("map_public_ip_on_launch", subnet.GetMapPublicIpOnLaunch()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(subnet.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(subnet.GetTags())); err != nil { return err } if err := d.Set("available_ips_count", subnet.GetAvailableIpsCount()); err != nil { @@ -130,7 +130,7 @@ func dataSourceOutscaleOAPISubnetRead(d *schema.ResourceData, meta interface{}) return nil } -func buildOutscaleOAPISubnetDataSourceFilters(set *schema.Set) *oscgo.FiltersSubnet { +func buildSubnetDataSourceFilters(set *schema.Set) *oscgo.FiltersSubnet { var filters oscgo.FiltersSubnet for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_subnet_test.go b/outscale/data_source_outscale_subnet_test.go index 374235201..7ebd676f2 100644 --- a/outscale/data_source_outscale_subnet_test.go +++ b/outscale/data_source_outscale_subnet_test.go @@ -8,40 +8,40 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccDataSourceOutscaleOAPISubnet(t *testing.T) { +func TestAccDataSourceSubnet(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISubnetConfig, + Config: testAccDataSourceSubnetConfig, Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPISubnetCheck("data.outscale_subnet.by_id"), - testAccDataSourceOutscaleOAPISubnetCheck("data.outscale_subnet.by_filter"), + testAccDataSourceSubnetCheck("data.outscale_subnet.by_id"), + testAccDataSourceSubnetCheck("data.outscale_subnet.by_filter"), ), }, }, }) } -func TestAccDataSourceOutscaleOAPISubnet_withAvailableIpsCountsFilter(t *testing.T) { +func TestAccDataSourceSubnet_withAvailableIpsCountsFilter(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter(), + Config: testAccDataSourceSubnetWithAvailableIpsCountsFilter(), Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPISubnetCheck("data.outscale_subnet.by_filter"), + testAccDataSourceSubnetCheck("data.outscale_subnet.by_filter"), ), }, }, }) } -func testAccDataSourceOutscaleOAPISubnetCheck(name string) resource.TestCheckFunc { +func testAccDataSourceSubnetCheck(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -74,7 +74,7 @@ func testAccDataSourceOutscaleOAPISubnetCheck(name string) resource.TestCheckFun } } -const testAccDataSourceOutscaleOAPISubnetConfig = ` +const testAccDataSourceSubnetConfig = ` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" tags { @@ -101,7 +101,7 @@ const testAccDataSourceOutscaleOAPISubnetConfig = ` } ` -func testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter() string { +func testAccDataSourceSubnetWithAvailableIpsCountsFilter() string { return ` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_subnets.go b/outscale/data_source_outscale_subnets.go index 5e52536a3..2e9e6bc83 100644 --- a/outscale/data_source_outscale_subnets.go +++ b/outscale/data_source_outscale_subnets.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPISubnets() *schema.Resource { +func dataSourceSubnets() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPISubnetsRead, + Read: dataSourceSubnetsRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -72,8 +72,8 @@ func dataSourceOutscaleOAPISubnets() *schema.Resource { } } -func dataSourceOutscaleOAPISubnetsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSubnetsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadSubnetsRequest{} @@ -88,7 +88,7 @@ func dataSourceOutscaleOAPISubnetsRead(d *schema.ResourceData, meta interface{}) filters, filtersOk := d.GetOk("filter") if filtersOk { - req.Filters = buildOutscaleOAPISubnetDataSourceFilters(filters.(*schema.Set)) + req.Filters = buildSubnetDataSourceFilters(filters.(*schema.Set)) } var resp oscgo.ReadSubnetsResponse @@ -135,7 +135,7 @@ func dataSourceOutscaleOAPISubnetsRead(d *schema.ResourceData, meta interface{}) subnet["subnet_id"] = v.GetSubnetId() } if v.GetTags() != nil { - subnet["tags"] = tagsOSCAPIToMap(v.GetTags()) + subnet["tags"] = tagsToMap(v.GetTags()) } if v.GetNetId() != "" { subnet["net_id"] = v.GetNetId() diff --git a/outscale/data_source_outscale_subnets_test.go b/outscale/data_source_outscale_subnets_test.go index 7a467d9a8..b54fd5dd3 100644 --- a/outscale/data_source_outscale_subnets_test.go +++ b/outscale/data_source_outscale_subnets_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPISubnets(t *testing.T) { +func TestAccDataSourceSubnets(t *testing.T) { t.Parallel() rInt := acctest.RandIntRange(0, 256) @@ -17,7 +17,7 @@ func TestAccDataSourceOutscaleOAPISubnets(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISubnetsConfig(rInt), + Config: testAccDataSourceSubnetsConfig(rInt), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_subnets.by_filter", "subnets.#", "1"), ), @@ -26,20 +26,20 @@ func TestAccDataSourceOutscaleOAPISubnets(t *testing.T) { }) } -func TestAccDataSourceOutscaleOAPISubnets_withAvailableIpsCountsFilter(t *testing.T) { +func TestAccDataSourceSubnets_withAvailableIpsCountsFilter(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISubnetsWithAvailableIpsCountsFilter(), + Config: testAccDataSourceSubnetsWithAvailableIpsCountsFilter(), }, }, }) } -func testAccDataSourceOutscaleOAPISubnetsConfig(rInt int) string { +func testAccDataSourceSubnetsConfig(rInt int) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "172.%[1]d.123.0/24" @@ -70,7 +70,7 @@ func testAccDataSourceOutscaleOAPISubnetsConfig(rInt int) string { `, rInt) } -func testAccDataSourceOutscaleOAPISubnetsWithAvailableIpsCountsFilter() string { +func testAccDataSourceSubnetsWithAvailableIpsCountsFilter() string { return ` resource "outscale_net" "outscale_net1" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_subregions.go b/outscale/data_source_outscale_subregions.go index 79ec71ed3..3a7e93db7 100644 --- a/outscale/data_source_outscale_subregions.go +++ b/outscale/data_source_outscale_subregions.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPISubregions() *schema.Resource { +func dataSourceSubregions() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPISubregionsRead, + Read: dataSourceSubregionsRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -52,14 +52,14 @@ func dataSourceOutscaleOAPISubregions() *schema.Resource { } } -func dataSourceOutscaleOAPISubregionsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceSubregionsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") filtersReq := &oscgo.FiltersSubregion{} if filtersOk { - filtersReq = buildOutscaleOAPIDataSourceSubregionsFilters(filters.(*schema.Set)) + filtersReq = buildDataSourceSubregionsFilters(filters.(*schema.Set)) } req := oscgo.ReadSubregionsRequest{Filters: filtersReq} @@ -98,7 +98,7 @@ func dataSourceOutscaleOAPISubregionsRead(d *schema.ResourceData, meta interface }) } -func buildOutscaleOAPIDataSourceSubregionsFilters(set *schema.Set) *oscgo.FiltersSubregion { +func buildDataSourceSubregionsFilters(set *schema.Set) *oscgo.FiltersSubregion { filters := &oscgo.FiltersSubregion{} for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_subregions_test.go b/outscale/data_source_outscale_subregions_test.go index 53f22e455..3cb201769 100644 --- a/outscale/data_source_outscale_subregions_test.go +++ b/outscale/data_source_outscale_subregions_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPISubregionsDataSource_Basic(t *testing.T) { +func TestAccSubregionsDataSource_Basic(t *testing.T) { t.Parallel() subregionName := "eu-west-2b" @@ -19,16 +19,16 @@ func TestAccOutscaleOAPISubregionsDataSource_Basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPISubregionsDataSourceConfig(subregionName), + Config: testAccCheckSubregionsDataSourceConfig(subregionName), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPISubregionsDataSourceID("data.outscale_subregions.test"), + testAccCheckSubregionsDataSourceID("data.outscale_subregions.test"), ), }, }, }) } -func TestAccOutscaleOAPISubregionsDataSource_All(t *testing.T) { +func TestAccSubregionsDataSource_All(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -37,16 +37,16 @@ func TestAccOutscaleOAPISubregionsDataSource_All(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPISubregionsDataSourceConfigAll, + Config: testAccCheckSubregionsDataSourceConfigAll, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPISubregionsDataSourceID("data.outscale_subregions.test"), + testAccCheckSubregionsDataSourceID("data.outscale_subregions.test"), ), }, }, }) } -func testAccCheckOutscaleOAPISubregionsDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckSubregionsDataSourceID(n string) resource.TestCheckFunc { // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -61,7 +61,7 @@ func testAccCheckOutscaleOAPISubregionsDataSourceID(n string) resource.TestCheck } } -func testAccCheckOutscaleOAPISubregionsDataSourceConfig(subregionName string) string { +func testAccCheckSubregionsDataSourceConfig(subregionName string) string { return fmt.Sprintf(` data "outscale_subregions" "test" { filter { @@ -72,7 +72,7 @@ func testAccCheckOutscaleOAPISubregionsDataSourceConfig(subregionName string) st `, subregionName) } -var testAccCheckOutscaleOAPISubregionsDataSourceConfigAll = ` +var testAccCheckSubregionsDataSourceConfigAll = ` data "outscale_subregions" "test" { } ` diff --git a/outscale/data_source_outscale_tag.go b/outscale/data_source_outscale_tag.go index ae637eaf6..b731c1f96 100644 --- a/outscale/data_source_outscale_tag.go +++ b/outscale/data_source_outscale_tag.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPITag() *schema.Resource { +func dataSourceTag() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPITagRead, + Read: dataSourceTagRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "key": { @@ -38,8 +38,8 @@ func dataSourceOutscaleOAPITag() *schema.Resource { } } -func dataSourceOutscaleOAPITagRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceTagRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI // Build up search parameters params := oscgo.ReadTagsRequest{} @@ -47,7 +47,7 @@ func dataSourceOutscaleOAPITagRead(d *schema.ResourceData, meta interface{}) err filters, filtersOk := d.GetOk("filter") if filtersOk { - params.SetFilters(oapiBuildOutscaleDataSourceFilters(filters.(*schema.Set))) + params.SetFilters(buildDataSourceFilters(filters.(*schema.Set))) } var resp oscgo.ReadTagsResponse @@ -96,7 +96,7 @@ func dataSourceOutscaleOAPITagRead(d *schema.ResourceData, meta interface{}) err return err } -func oapiBuildOutscaleDataSourceFilters(set *schema.Set) oscgo.FiltersTag { +func buildDataSourceFilters(set *schema.Set) oscgo.FiltersTag { filters := oscgo.FiltersTag{} for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_tag_test.go b/outscale/data_source_outscale_tag_test.go index 875f13e46..e0d38739b 100644 --- a/outscale/data_source_outscale_tag_test.go +++ b/outscale/data_source_outscale_tag_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPITagDataSource(t *testing.T) { +func TestAccTagDataSource(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") resource.Test(t, resource.TestCase{ @@ -16,7 +16,7 @@ func TestAccOutscaleOAPITagDataSource(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOAPITagDataSourceConfig(omi, "tinav4.c2r2p2"), + Config: testAccTagDataSourceConfig(omi, "tinav4.c2r2p2"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "data.outscale_tag.web", "key", "Name"), @@ -31,7 +31,7 @@ func TestAccOutscaleOAPITagDataSource(t *testing.T) { } // Lookup based on InstanceID -func testAccOAPITagDataSourceConfig(omi, vmType string) string { +func testAccTagDataSourceConfig(omi, vmType string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%s" diff --git a/outscale/data_source_outscale_tags.go b/outscale/data_source_outscale_tags.go index 5c325c37b..ff75f5dfc 100644 --- a/outscale/data_source_outscale_tags.go +++ b/outscale/data_source_outscale_tags.go @@ -11,9 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPITags() *schema.Resource { +func dataSourceTags() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPITagsRead, + Read: dataSourceTagsRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "tags": { @@ -44,15 +44,15 @@ func dataSourceOutscaleOAPITags() *schema.Resource { } } -func dataSourceOutscaleOAPITagsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceTagsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI // Build up search parameters params := oscgo.ReadTagsRequest{} filters, filtersOk := d.GetOk("filter") if filtersOk { - params.SetFilters(oapiBuildOutscaleDataSourceFilters(filters.(*schema.Set))) + params.SetFilters(buildDataSourceFilters(filters.(*schema.Set))) } var resp oscgo.ReadTagsResponse @@ -71,7 +71,7 @@ func dataSourceOutscaleOAPITagsRead(d *schema.ResourceData, meta interface{}) er return err } - if err := d.Set("tags", oapiTagsDescToList(resp.GetTags())); err != nil { + if err := d.Set("tags", tagsDescToList(resp.GetTags())); err != nil { return err } d.SetId(resource.UniqueId()) diff --git a/outscale/data_source_outscale_tags_test.go b/outscale/data_source_outscale_tags_test.go index 559d63855..423249252 100644 --- a/outscale/data_source_outscale_tags_test.go +++ b/outscale/data_source_outscale_tags_test.go @@ -6,20 +6,20 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPITagsDataSource_basic(t *testing.T) { +func TestAccTagsDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOAPITagsDataSourceConfig(), + Config: testAccTagsDataSourceConfig(), }, }, }) } // Lookup based on InstanceID -func testAccOAPITagsDataSourceConfig() string { +func testAccTagsDataSourceConfig() string { return ` data "outscale_tags" "web" { filter { diff --git a/outscale/data_source_outscale_virtual_gateway.go b/outscale/data_source_outscale_virtual_gateway.go index d26bf34ab..1d8d3a67e 100644 --- a/outscale/data_source_outscale_virtual_gateway.go +++ b/outscale/data_source_outscale_virtual_gateway.go @@ -14,9 +14,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func dataSourceOutscaleOAPIVirtualGateway() *schema.Resource { +func dataSourceVirtualGateway() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIVirtualGatewayRead, + Read: dataSourceVirtualGatewayRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -60,8 +60,8 @@ func dataSourceOutscaleOAPIVirtualGateway() *schema.Resource { } } -func dataSourceOutscaleOAPIVirtualGatewayRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVirtualGatewayRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") virtualId, vpnOk := d.GetOk("virtual_gateway_id") @@ -77,7 +77,7 @@ func dataSourceOutscaleOAPIVirtualGatewayRead(d *schema.ResourceData, meta inter } if filtersOk { - params.SetFilters(buildOutscaleAPIVirtualGatewayFilters(filters.(*schema.Set))) + params.SetFilters(buildVirtualGatewayFilters(filters.(*schema.Set))) } var resp oscgo.ReadVirtualGatewaysResponse @@ -119,12 +119,12 @@ func dataSourceOutscaleOAPIVirtualGatewayRead(d *schema.ResourceData, meta inter d.Set("net_to_virtual_gateway_links", vs) d.Set("state", aws.StringValue(vgw.State)) d.Set("connection_type", vgw.ConnectionType) - d.Set("tags", tagsOSCAPIToMap(vgw.GetTags())) + d.Set("tags", tagsToMap(vgw.GetTags())) return nil } -func buildOutscaleAPIVirtualGatewayFilters(set *schema.Set) oscgo.FiltersVirtualGateway { +func buildVirtualGatewayFilters(set *schema.Set) oscgo.FiltersVirtualGateway { var filters oscgo.FiltersVirtualGateway for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_virtual_gateway_test.go b/outscale/data_source_outscale_virtual_gateway_test.go index b075ed0eb..6491c84a3 100644 --- a/outscale/data_source_outscale_virtual_gateway_test.go +++ b/outscale/data_source_outscale_virtual_gateway_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIVirtualGateway_unattached(t *testing.T) { +func TestAccDataSourceVirtualGateway_unattached(t *testing.T) { //t.Skip() t.Parallel() rInt := acctest.RandInt() @@ -20,7 +20,7 @@ func TestAccDataSourceOutscaleOAPIVirtualGateway_unattached(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIVirtualGatewayUnattachedConfig(rInt), + Config: testAccDataSourceVirtualGatewayUnattachedConfig(rInt), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair( "data.outscale_virtual_gateway.test_by_id", "id", @@ -33,7 +33,7 @@ func TestAccDataSourceOutscaleOAPIVirtualGateway_unattached(t *testing.T) { }) } -func testAccDataSourceOutscaleOAPIVirtualGatewayUnattachedConfig(rInt int) string { +func testAccDataSourceVirtualGatewayUnattachedConfig(rInt int) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "unattached" { connection_type = "ipsec.1" diff --git a/outscale/data_source_outscale_virtual_gateways.go b/outscale/data_source_outscale_virtual_gateways.go index b20dd74cc..932826110 100644 --- a/outscale/data_source_outscale_virtual_gateways.go +++ b/outscale/data_source_outscale_virtual_gateways.go @@ -12,9 +12,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func dataSourceOutscaleOAPIVirtualGateways() *schema.Resource { +func dataSourceVirtualGateways() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIVirtualGatewaysRead, + Read: dataSourceVirtualGatewaysRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -69,8 +69,8 @@ func dataSourceOutscaleOAPIVirtualGateways() *schema.Resource { } } -func dataSourceOutscaleOAPIVirtualGatewaysRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVirtualGatewaysRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filter, filtersOk := d.GetOk("filter") _, vpnOk := d.GetOk("virtual_gateway_id") @@ -82,7 +82,7 @@ func dataSourceOutscaleOAPIVirtualGatewaysRead(d *schema.ResourceData, meta inte params := oscgo.ReadVirtualGatewaysRequest{} if filtersOk { - params.SetFilters(buildOutscaleAPIVirtualGatewayFilters(filter.(*schema.Set))) + params.SetFilters(buildVirtualGatewayFilters(filter.(*schema.Set))) } var resp oscgo.ReadVirtualGatewaysResponse @@ -121,7 +121,7 @@ func dataSourceOutscaleOAPIVirtualGatewaysRead(d *schema.ResourceData, meta inte vpn["state"] = v.GetState() vpn["connection_type"] = v.GetConnectionType() vpn["virtual_gateway_id"] = v.GetVirtualGatewayId() - vpn["tags"] = tagsOSCAPIToMap(v.GetTags()) + vpn["tags"] = tagsToMap(v.GetTags()) vpns[k] = vpn } diff --git a/outscale/data_source_outscale_virtual_gateways_test.go b/outscale/data_source_outscale_virtual_gateways_test.go index f86d1bfdb..f298beaea 100644 --- a/outscale/data_source_outscale_virtual_gateways_test.go +++ b/outscale/data_source_outscale_virtual_gateways_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIVpnGateways_unattached(t *testing.T) { +func TestAccDataSourceVpnGateways_unattached(t *testing.T) { //t.Skip() t.Parallel() rInt := acctest.RandInt() @@ -20,13 +20,13 @@ func TestAccDataSourceOutscaleOAPIVpnGateways_unattached(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIVpnGatewaysUnattachedConfig(rInt), + Config: testAccDataSourceVpnGatewaysUnattachedConfig(rInt), }, }, }) } -func testAccDataSourceOutscaleOAPIVpnGatewaysUnattachedConfig(rInt int) string { +func testAccDataSourceVpnGatewaysUnattachedConfig(rInt int) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "unattached" { connection_type = "ipsec.1" diff --git a/outscale/data_source_outscale_vm.go b/outscale/data_source_outscale_vm.go index 31bda10ca..4b0395106 100644 --- a/outscale/data_source_outscale_vm.go +++ b/outscale/data_source_outscale_vm.go @@ -14,14 +14,14 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIVM() *schema.Resource { +func dataSourceVM() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIVMRead, - Schema: getDataSourceOAPIVMSchemas(), + Read: dataSourceVMRead, + Schema: getDataSourceVMSchemas(), } } -func dataSourceOutscaleOAPIVMRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*OutscaleClient).OSCAPI +func dataSourceVMRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") instanceID, instanceIDOk := d.GetOk("vm_id") @@ -32,7 +32,7 @@ func dataSourceOutscaleOAPIVMRead(d *schema.ResourceData, meta interface{}) erro // Build up search parameters params := oscgo.ReadVmsRequest{} if filtersOk { - params.Filters = buildOutscaleOAPIDataSourceVMFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceVMFilters(filters.(*schema.Set)) } if instanceIDOk { params.Filters.VmIds = &[]string{instanceID.(string)} @@ -82,18 +82,18 @@ func dataSourceOutscaleOAPIVMRead(d *schema.ResourceData, meta interface{}) erro // Populate vm attribute fields with the returned vm return resourceDataAttrSetter(d, func(set AttributeSetter) error { d.SetId(vm.GetVmId()) - return oapiVMDescriptionAttributes(set, &vm) + return setVMAttributes(set, &vm) }) } // Populate instance attribute fields with the returned instance -func oapiVMDescriptionAttributes(set AttributeSetter, vm *oscgo.Vm) error { +func setVMAttributes(set AttributeSetter, vm *oscgo.Vm) error { if err := set("architecture", vm.GetArchitecture()); err != nil { return err } - if err := set("block_device_mappings_created", getOscAPIVMBlockDeviceMapping(vm.GetBlockDeviceMappings())); err != nil { + if err := set("block_device_mappings_created", getVMBlockDeviceMapping(vm.GetBlockDeviceMappings())); err != nil { log.Printf("[DEBUG] BLOCKING DEVICE MAPPING ERR %+v", err) return err } @@ -130,7 +130,7 @@ func oapiVMDescriptionAttributes(set AttributeSetter, vm *oscgo.Vm) error { if err := set("nested_virtualization", vm.GetNestedVirtualization()); err != nil { return err } - if err := set("nics", getOAPIVMNetworkInterfaceLightSet(vm.GetNics())); err != nil { + if err := set("nics", getVMNetworkInterfaceLightSet(vm.GetNics())); err != nil { return err } @@ -170,7 +170,7 @@ func oapiVMDescriptionAttributes(set AttributeSetter, vm *oscgo.Vm) error { if err := set("root_device_type", vm.GetRootDeviceType()); err != nil { return err } - if err := set("security_groups", getOAPIVMSecurityGroups(vm.GetSecurityGroups())); err != nil { + if err := set("security_groups", getVMSecurityGroups(vm.GetSecurityGroups())); err != nil { log.Printf("[DEBUG] SECURITY GROUPS ERR %+v", err) return err } @@ -192,14 +192,14 @@ func oapiVMDescriptionAttributes(set AttributeSetter, vm *oscgo.Vm) error { if err := set("vm_initiated_shutdown_behavior", vm.GetVmInitiatedShutdownBehavior()); err != nil { return err } - if err := set("tags", getOscAPITagSet(vm.GetTags())); err != nil { + if err := set("tags", getTagSet(vm.GetTags())); err != nil { return err } return set("vm_type", vm.GetVmType()) } -func getOscAPIVMBlockDeviceMapping(blockDeviceMappings []oscgo.BlockDeviceMappingCreated) []map[string]interface{} { +func getVMBlockDeviceMapping(blockDeviceMappings []oscgo.BlockDeviceMappingCreated) []map[string]interface{} { blockDeviceMapping := make([]map[string]interface{}, len(blockDeviceMappings)) for k, v := range blockDeviceMappings { @@ -216,7 +216,7 @@ func getOscAPIVMBlockDeviceMapping(blockDeviceMappings []oscgo.BlockDeviceMappin return blockDeviceMapping } -func getOAPIVMSecurityGroups(groupSet []oscgo.SecurityGroupLight) []map[string]interface{} { +func getVMSecurityGroups(groupSet []oscgo.SecurityGroupLight) []map[string]interface{} { res := []map[string]interface{}{} for _, g := range groupSet { r := map[string]interface{}{ @@ -229,12 +229,12 @@ func getOAPIVMSecurityGroups(groupSet []oscgo.SecurityGroupLight) []map[string]i return res } -func getDataSourceOAPIVMSchemas() map[string]*schema.Schema { +func getDataSourceVMSchemas() map[string]*schema.Schema { wholeSchema := map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), } - attrsSchema := getOApiVMAttributesSchema() + attrsSchema := getVMAttributesSchema() for k, v := range attrsSchema { wholeSchema[k] = v @@ -248,7 +248,7 @@ func getDataSourceOAPIVMSchemas() map[string]*schema.Schema { return wholeSchema } -func buildOutscaleOAPIDataSourceVMFilters(set *schema.Set) *oscgo.FiltersVm { +func buildDataSourceVMFilters(set *schema.Set) *oscgo.FiltersVm { filters := new(oscgo.FiltersVm) for _, v := range set.List() { @@ -274,7 +274,7 @@ func buildOutscaleOAPIDataSourceVMFilters(set *schema.Set) *oscgo.FiltersVm { return filters } -func getOApiVMAttributesSchema() map[string]*schema.Schema { +func getVMAttributesSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ // Attributes "architecture": { diff --git a/outscale/data_source_outscale_vm_state.go b/outscale/data_source_outscale_vm_state.go index b485cbefd..0f14c7924 100644 --- a/outscale/data_source_outscale_vm_state.go +++ b/outscale/data_source_outscale_vm_state.go @@ -14,14 +14,14 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIVMState() *schema.Resource { +func dataSourceVMState() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIVMStateRead, - Schema: getOAPIVMStateDataSourceSchema(), + Read: dataSourceVMStateRead, + Schema: getVMStateDataSourceSchema(), } } -func getOAPIVMStateDataSourceSchema() map[string]*schema.Schema { +func getVMStateDataSourceSchema() map[string]*schema.Schema { wholeSchema := map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), } @@ -79,8 +79,8 @@ func getVMStateAttrsSchema() map[string]*schema.Schema { } } -func dataSourceOutscaleOAPIVMStateRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVMStateRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") instanceID, instanceIDOk := d.GetOk("vm_id") @@ -91,7 +91,7 @@ func dataSourceOutscaleOAPIVMStateRead(d *schema.ResourceData, meta interface{}) params := oscgo.ReadVmsStateRequest{} if filtersOk { - params.SetFilters(buildOutscaleOAPIDataSourceVMStateFilters(filters.(*schema.Set))) + params.SetFilters(buildDataSourceVMStateFilters(filters.(*schema.Set))) } if instanceIDOk { filter := oscgo.FiltersVmsState{} @@ -130,7 +130,7 @@ func dataSourceOutscaleOAPIVMStateRead(d *schema.ResourceData, meta interface{}) state = filteredStates[0] - log.Printf("[DEBUG] outscale_oapi_vm_state - Single State found: %s", state.GetVmId()) + log.Printf("[DEBUG] outscale_vm.state - Single State found: %s", state.GetVmId()) return vmStateDataAttrSetter(d, &state) } @@ -139,15 +139,15 @@ func vmStateDataAttrSetter(d *schema.ResourceData, status *oscgo.VmStates) error return d.Set(key, value) } d.SetId(status.GetVmId()) - return statusDescriptionOAPIVMStateAttributes(setterFunc, status) + return statusDescriptionVMStateAttributes(setterFunc, status) } -func statusDescriptionOAPIVMStateAttributes(set AttributeSetter, status *oscgo.VmStates) error { +func statusDescriptionVMStateAttributes(set AttributeSetter, status *oscgo.VmStates) error { if err := set("subregion_name", status.GetSubregionName()); err != nil { return err } - if err := set("maintenance_events", statusSetOAPIVMState(status.GetMaintenanceEvents())); err != nil { + if err := set("maintenance_events", statusSetVMState(status.GetMaintenanceEvents())); err != nil { return err } if err := set("vm_state", status.GetVmState()); err != nil { @@ -160,7 +160,7 @@ func statusDescriptionOAPIVMStateAttributes(set AttributeSetter, status *oscgo.V return nil } -func statusSetOAPIVMState(status []oscgo.MaintenanceEvent) []map[string]interface{} { +func statusSetVMState(status []oscgo.MaintenanceEvent) []map[string]interface{} { s := make([]map[string]interface{}, len(status)) for k, v := range status { s[k] = map[string]interface{}{ @@ -174,7 +174,7 @@ func statusSetOAPIVMState(status []oscgo.MaintenanceEvent) []map[string]interfac return s } -func buildOutscaleOAPIDataSourceVMStateFilters(set *schema.Set) oscgo.FiltersVmsState { +func buildDataSourceVMStateFilters(set *schema.Set) oscgo.FiltersVmsState { var filters oscgo.FiltersVmsState for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_vm_state_test.go b/outscale/data_source_outscale_vm_state_test.go index 68b93e5b4..488e83c9e 100644 --- a/outscale/data_source_outscale_vm_state_test.go +++ b/outscale/data_source_outscale_vm_state_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccDataSourceOutscaleOAPIVmState(t *testing.T) { +func TestAccDataSourceVmState(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") @@ -18,16 +18,16 @@ func TestAccDataSourceOutscaleOAPIVmState(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIVmStateConfig(omi, "tinav4.c2r2p2"), + Config: testAccDataSourceVmStateConfig(omi, "tinav4.c2r2p2"), Check: resource.ComposeTestCheckFunc( - testAccDataSourceOutscaleOAPIVMStateCheck("data.outscale_vm_state.state"), + testAccDataSourceVMStateCheck("data.outscale_vm_state.state"), ), }, }, }) } -func testAccDataSourceOutscaleOAPIVMStateCheck(name string) resource.TestCheckFunc { +func testAccDataSourceVMStateCheck(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -53,7 +53,7 @@ func testAccDataSourceOutscaleOAPIVMStateCheck(name string) resource.TestCheckFu } } -func testAccDataSourceOutscaleOAPIVmStateConfig(omi, vmType string) string { +func testAccDataSourceVmStateConfig(omi, vmType string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%s" diff --git a/outscale/data_source_outscale_vm_states.go b/outscale/data_source_outscale_vm_states.go index 65e40e9d6..9e62faa5b 100644 --- a/outscale/data_source_outscale_vm_states.go +++ b/outscale/data_source_outscale_vm_states.go @@ -13,14 +13,14 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIVMStates() *schema.Resource { +func dataSourceVMStates() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIVMStatesRead, - Schema: getOAPIVMStatesDataSourceSchema(), + Read: dataSourceVMStatesRead, + Schema: getVMStatesDataSourceSchema(), } } -func getOAPIVMStatesDataSourceSchema() map[string]*schema.Schema { +func getVMStatesDataSourceSchema() map[string]*schema.Schema { wholeSchema := map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "vm_ids": { @@ -44,8 +44,8 @@ func getOAPIVMStatesDataSourceSchema() map[string]*schema.Schema { return wholeSchema } -func dataSourceOutscaleOAPIVMStatesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVMStatesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") instanceIds, instanceIdsOk := d.GetOk("vm_ids") @@ -56,11 +56,11 @@ func dataSourceOutscaleOAPIVMStatesRead(d *schema.ResourceData, meta interface{} params := oscgo.ReadVmsStateRequest{} if filtersOk { - params.SetFilters(buildOutscaleOAPIDataSourceVMStateFilters(filters.(*schema.Set))) + params.SetFilters(buildDataSourceVMStateFilters(filters.(*schema.Set))) } if instanceIdsOk { filter := oscgo.FiltersVmsState{} - filter.SetVmIds(oapiExpandStringList(instanceIds.([]interface{}))) + filter.SetVmIds(ExpandStringList(instanceIds.([]interface{}))) params.SetFilters(filter) } @@ -86,10 +86,10 @@ func dataSourceOutscaleOAPIVMStatesRead(d *schema.ResourceData, meta interface{} return fmt.Errorf("your query returned no results, please change your search criteria and try again") } - return statusDescriptionOAPIVMStatesAttributes(d, filteredStates) + return statusDescriptionVMStatesAttributes(d, filteredStates) } -func statusDescriptionOAPIVMStatesAttributes(d *schema.ResourceData, status []oscgo.VmStates) error { +func statusDescriptionVMStatesAttributes(d *schema.ResourceData, status []oscgo.VmStates) error { d.SetId(resource.UniqueId()) states := make([]map[string]interface{}, len(status)) @@ -102,7 +102,7 @@ func statusDescriptionOAPIVMStatesAttributes(d *schema.ResourceData, status []os return nil } - if err := statusDescriptionOAPIVMStateAttributes(setterFunc, &v); err != nil { + if err := statusDescriptionVMStateAttributes(setterFunc, &v); err != nil { return err } diff --git a/outscale/data_source_outscale_vm_states_test.go b/outscale/data_source_outscale_vm_states_test.go index dd81749cd..7685bf439 100644 --- a/outscale/data_source_outscale_vm_states_test.go +++ b/outscale/data_source_outscale_vm_states_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIVMStates(t *testing.T) { +func TestAccDataSourceVMStates(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") @@ -17,13 +17,13 @@ func TestAccDataSourceOutscaleOAPIVMStates(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIVMStatesConfig(omi, "tinav4.c2r2p2"), + Config: testAccDataSourceVMStatesConfig(omi, "tinav4.c2r2p2"), }, }, }) } -func testAccDataSourceOutscaleOAPIVMStatesConfig(omi, vmType string) string { +func testAccDataSourceVMStatesConfig(omi, vmType string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%s" diff --git a/outscale/data_source_outscale_vm_test.go b/outscale/data_source_outscale_vm_test.go index 1486409bf..1c1d40b6e 100644 --- a/outscale/data_source_outscale_vm_test.go +++ b/outscale/data_source_outscale_vm_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIVMDataSource_basic(t *testing.T) { +func TestAccVMDataSource_basic(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") datasourcceName := "data.outscale_vm.basic_web" @@ -18,7 +18,7 @@ func TestAccOutscaleOAPIVMDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOAPIVMDataSourceConfig(omi, "tinav4.c2r2p2"), + Config: testAccVMDataSourceConfig(omi, "tinav4.c2r2p2"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(datasourcceName, "image_id", omi), resource.TestCheckResourceAttr(datasourcceName, "vm_type", "tinav4.c2r2p2"), @@ -29,7 +29,7 @@ func TestAccOutscaleOAPIVMDataSource_basic(t *testing.T) { }) } -func testAccOAPIVMDataSourceConfig(omi, vmType string) string { +func testAccVMDataSourceConfig(omi, vmType string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/data_source_outscale_vm_types.go b/outscale/data_source_outscale_vm_types.go index 39a9909cd..4d3cc54d9 100644 --- a/outscale/data_source_outscale_vm_types.go +++ b/outscale/data_source_outscale_vm_types.go @@ -13,9 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleOAPIVMTypes() *schema.Resource { +func dataSourceVMTypes() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOAPIVMTypesRead, + Read: dataSourceVMTypesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -63,14 +63,14 @@ func dataSourceOutscaleOAPIVMTypes() *schema.Resource { } } -func dataSourceOutscaleOAPIVMTypesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVMTypesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filter, filterOk := d.GetOk("filter") filtersReq := oscgo.FiltersVmType{} if filterOk { - filtersReq = buildOutscaleOAPIDataSourceVMTypesFilters(filter.(*schema.Set)) + filtersReq = buildDataSourceVMTypesFilters(filter.(*schema.Set)) } req := oscgo.ReadVmTypesRequest{Filters: &filtersReq} @@ -96,11 +96,11 @@ func dataSourceOutscaleOAPIVMTypesRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Your query returned no results. Please change your search criteria and try again") } - return statusDescriptionOAPIVMTypesAttributes(d, filteredTypes) + return statusDescriptionVMTypesAttributes(d, filteredTypes) } -func setOAPIVMTypeAttributes(set AttributeSetter, vType *oscgo.VmType) error { +func setVMTypeAttributes(set AttributeSetter, vType *oscgo.VmType) error { if err := set("bsu_optimized", vType.GetBsuOptimized()); err != nil { return err @@ -127,7 +127,7 @@ func setOAPIVMTypeAttributes(set AttributeSetter, vType *oscgo.VmType) error { return nil } -func statusDescriptionOAPIVMTypesAttributes(d *schema.ResourceData, fTypes []oscgo.VmType) error { +func statusDescriptionVMTypesAttributes(d *schema.ResourceData, fTypes []oscgo.VmType) error { d.SetId(resource.UniqueId()) vTypes := make([]map[string]interface{}, len(fTypes)) @@ -140,7 +140,7 @@ func statusDescriptionOAPIVMTypesAttributes(d *schema.ResourceData, fTypes []osc return nil } - if err := setOAPIVMTypeAttributes(setterFunc, &v); err != nil { + if err := setVMTypeAttributes(setterFunc, &v); err != nil { return err } @@ -151,7 +151,7 @@ func statusDescriptionOAPIVMTypesAttributes(d *schema.ResourceData, fTypes []osc } -func buildOutscaleOAPIDataSourceVMTypesFilters(set *schema.Set) oscgo.FiltersVmType { +func buildDataSourceVMTypesFilters(set *schema.Set) oscgo.FiltersVmType { var filters oscgo.FiltersVmType for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_vm_types_test.go b/outscale/data_source_outscale_vm_types_test.go index a48784442..5d5fde41f 100644 --- a/outscale/data_source_outscale_vm_types_test.go +++ b/outscale/data_source_outscale_vm_types_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccDataSourceOutscaleOAPIVMTypes_basic(t *testing.T) { +func TestAccDataSourceVMTypes_basic(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") @@ -19,13 +19,13 @@ func TestAccDataSourceOutscaleOAPIVMTypes_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIVMTypesConfig(omi, "tinav4.c1r1p1"), + Config: testAccDataSourceVMTypesConfig(omi, "tinav4.c1r1p1"), }, }, }) } -func testAccDataSourceOutscaleOAPIVMTypesConfig(omi, vmType string) string { +func testAccDataSourceVMTypesConfig(omi, vmType string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%s" diff --git a/outscale/data_source_outscale_vms.go b/outscale/data_source_outscale_vms.go index 970078030..7bab6dc87 100644 --- a/outscale/data_source_outscale_vms.go +++ b/outscale/data_source_outscale_vms.go @@ -13,11 +13,11 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func datasourceOutscaleOApiVMS() *schema.Resource { +func dataSourceVMS() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleOApiVMSRead, + Read: dataSourceVMSRead, - Schema: datasourceOutscaleOApiVMSSchema(), + Schema: dataSourceVMSSchema(), } } @@ -43,14 +43,14 @@ func dataSourceFiltersSchema() *schema.Schema { } } -func datasourceOutscaleOApiVMSSchema() map[string]*schema.Schema { +func dataSourceVMSSchema() map[string]*schema.Schema { wholeSchema := map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "vms": { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ - Schema: getOApiVMAttributesSchema(), + Schema: getVMAttributesSchema(), }, }, "request_id": { @@ -62,8 +62,8 @@ func datasourceOutscaleOApiVMSSchema() map[string]*schema.Schema { return wholeSchema } -func dataSourceOutscaleOApiVMSRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*OutscaleClient).OSCAPI +func dataSourceVMSRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") vmID, vmIDOk := d.GetOk("vm_id") @@ -75,7 +75,7 @@ func dataSourceOutscaleOApiVMSRead(d *schema.ResourceData, meta interface{}) err // Build up search parameters params := oscgo.ReadVmsRequest{} if filtersOk { - params.Filters = buildOutscaleOAPIDataSourceVMFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceVMFilters(filters.(*schema.Set)) } if vmIDOk { params.Filters.VmIds = &[]string{vmID.(string)} @@ -114,10 +114,10 @@ func dataSourceOutscaleOApiVMSRead(d *schema.ResourceData, meta interface{}) err } d.SetId(resource.UniqueId()) - return d.Set("vms", dataSourceOAPIVMS(filteredVms)) + return d.Set("vms", flattenVMS(filteredVms)) } -func dataSourceOAPIVMS(i []oscgo.Vm) []map[string]interface{} { +func flattenVMS(i []oscgo.Vm) []map[string]interface{} { vms := make([]map[string]interface{}, len(i)) for index, v := range i { vm := make(map[string]interface{}) @@ -127,11 +127,11 @@ func dataSourceOAPIVMS(i []oscgo.Vm) []map[string]interface{} { return nil } - if err := oapiVMDescriptionAttributes(setterFunc, &v); err != nil { - log.Fatalf("[DEBUG] oapiVMDescriptionAttributes ERROR %+v", err) + if err := setVMAttributes(setterFunc, &v); err != nil { + log.Fatalf("[DEBUG] setVMAttributes ERROR %+v", err) } - vm["tags"] = getOscAPITagSet(v.GetTags()) + vm["tags"] = getTagSet(v.GetTags()) vms[index] = vm } return vms diff --git a/outscale/data_source_outscale_vms_test.go b/outscale/data_source_outscale_vms_test.go index 821808c34..8697ed683 100644 --- a/outscale/data_source_outscale_vms_test.go +++ b/outscale/data_source_outscale_vms_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIVMSDataSource_basic(t *testing.T) { +func TestAccVMSDataSource_basic(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") @@ -17,7 +17,7 @@ func TestAccOutscaleOAPIVMSDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOAPIVMSDataSourceConfig(omi, "tinav4.c2r2p2"), + Config: testAccVMSDataSourceConfig(omi, "tinav4.c2r2p2"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "data.outscale_vms.basic_web", "vms.0.image_id", omi), @@ -29,7 +29,7 @@ func TestAccOutscaleOAPIVMSDataSource_basic(t *testing.T) { }) } -func testAccOAPIVMSDataSourceConfig(omi, vmType string) string { +func testAccVMSDataSourceConfig(omi, vmType string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%s" diff --git a/outscale/data_source_outscale_volume.go b/outscale/data_source_outscale_volume.go index d77c06bf4..ae10fa9dc 100644 --- a/outscale/data_source_outscale_volume.go +++ b/outscale/data_source_outscale_volume.go @@ -15,9 +15,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func datasourceOutscaleOAPIVolume() *schema.Resource { +func dataSourceVolume() *schema.Resource { return &schema.Resource{ - Read: datasourceOAPIVolumeRead, + Read: datasourceVolumeRead, Schema: map[string]*schema.Schema{ // Arguments @@ -92,8 +92,8 @@ func datasourceOutscaleOAPIVolume() *schema.Resource { } } -func datasourceOAPIVolumeRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func datasourceVolumeRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") volumeIds, VolumeIdsOk := d.GetOk("volume_id") @@ -106,7 +106,7 @@ func datasourceOAPIVolumeRead(d *schema.ResourceData, meta interface{}) error { } if filtersOk { - params.SetFilters(buildOutscaleOSCAPIDataSourceVolumesFilters(filters.(*schema.Set))) + params.SetFilters(buildDataSourceVolumesFilters(filters.(*schema.Set))) } var resp oscgo.ReadVolumesResponse @@ -142,11 +142,11 @@ func datasourceOAPIVolumeRead(d *schema.ResourceData, meta interface{}) error { // Query returned single result. volume = filteredVolumes[0] log.Printf("[DEBUG] outscale_volume - Single Volume found: %s", volume.GetVolumeId()) - return volumeOAPIDescriptionAttributes(d, &volume) + return volumeDescriptionAttributes(d, &volume) } -func volumeOAPIDescriptionAttributes(d *schema.ResourceData, volume *oscgo.Volume) error { +func volumeDescriptionAttributes(d *schema.ResourceData, volume *oscgo.Volume) error { if err := d.Set("volume_id", volume.GetVolumeId()); err != nil { return err } @@ -194,7 +194,7 @@ func volumeOAPIDescriptionAttributes(d *schema.ResourceData, volume *oscgo.Volum } if volume.GetTags() != nil { - if err := d.Set("tags", tagsOSCAPIToMap(volume.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(volume.GetTags())); err != nil { return err } } else { @@ -212,7 +212,7 @@ func volumeOAPIDescriptionAttributes(d *schema.ResourceData, volume *oscgo.Volum return nil } -func buildOutscaleOSCAPIDataSourceVolumesFilters(set *schema.Set) oscgo.FiltersVolume { +func buildDataSourceVolumesFilters(set *schema.Set) oscgo.FiltersVolume { var filters oscgo.FiltersVolume for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_volume_test.go b/outscale/data_source_outscale_volume_test.go index 316d2e1a1..c95222c78 100644 --- a/outscale/data_source_outscale_volume_test.go +++ b/outscale/data_source_outscale_volume_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIVolumeDataSource_basic(t *testing.T) { +func TestAccVolumeDataSource_basic(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -18,9 +18,9 @@ func TestAccOutscaleOAPIVolumeDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumeDataSourceConfig(region), + Config: testAccCheckVolumeDataSourceConfig(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volume.ebs_volume"), + testAccCheckVolumeDataSourceID("data.outscale_volume.ebs_volume"), resource.TestCheckResourceAttr("data.outscale_volume.ebs_volume", "size", "10"), resource.TestCheckResourceAttr("data.outscale_volume.ebs_volume", "volume_type", "standard"), ), @@ -29,7 +29,7 @@ func TestAccOutscaleOAPIVolumeDataSource_basic(t *testing.T) { }) } -func TestAccOutscaleOAPIVolumeDataSource_filterByTags(t *testing.T) { +func TestAccVolumeDataSource_filterByTags(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -38,9 +38,9 @@ func TestAccOutscaleOAPIVolumeDataSource_filterByTags(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumeDataSourceConfigFilterByTags(region), + Config: testAccCheckVolumeDataSourceConfigFilterByTags(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volume.ebs_volume"), + testAccCheckVolumeDataSourceID("data.outscale_volume.ebs_volume"), resource.TestCheckResourceAttr("data.outscale_volume.ebs_volume", "size", "10"), resource.TestCheckResourceAttr("data.outscale_volume.ebs_volume", "volume_type", "standard"), ), @@ -49,7 +49,7 @@ func TestAccOutscaleOAPIVolumeDataSource_filterByTags(t *testing.T) { }) } -func testAccCheckOutscaleOAPIVolumeDataSourceID(n string) resource.TestCheckFunc { +func testAccCheckVolumeDataSourceID(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -63,7 +63,7 @@ func testAccCheckOutscaleOAPIVolumeDataSourceID(n string) resource.TestCheckFunc } } -func testAccCheckOutscaleOAPIVolumeDataSourceConfig(region string) string { +func testAccCheckVolumeDataSourceConfig(region string) string { return fmt.Sprintf(` resource "outscale_volume" "example" { subregion_name = "%sa" @@ -85,7 +85,7 @@ func testAccCheckOutscaleOAPIVolumeDataSourceConfig(region string) string { `, region) } -func testAccCheckOutscaleOAPIVolumeDataSourceConfigFilterByTags(region string) string { +func testAccCheckVolumeDataSourceConfigFilterByTags(region string) string { return fmt.Sprintf(` resource "outscale_volume" "example" { subregion_name = "%sa" diff --git a/outscale/data_source_outscale_volumes.go b/outscale/data_source_outscale_volumes.go index 81a4a7604..4c129ce2e 100644 --- a/outscale/data_source_outscale_volumes.go +++ b/outscale/data_source_outscale_volumes.go @@ -14,9 +14,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func datasourceOutscaleOAPIVolumes() *schema.Resource { +func dataSourceVolumes() *schema.Resource { return &schema.Resource{ - Read: datasourceOAPIVolumesRead, + Read: datasourceVolumesRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -101,8 +101,8 @@ func datasourceOutscaleOAPIVolumes() *schema.Resource { } } -func datasourceOAPIVolumesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func datasourceVolumesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") volumeIds, volumeIdsOk := d.GetOk("volume_id") @@ -118,7 +118,7 @@ func datasourceOAPIVolumesRead(d *schema.ResourceData, meta interface{}) error { } if filtersOk { - params.SetFilters(buildOutscaleOSCAPIDataSourceVolumesFilters(filters.(*schema.Set))) + params.SetFilters(buildDataSourceVolumesFilters(filters.(*schema.Set))) } log.Printf("LOG____ params: %#+v\n", params.GetFilters()) @@ -146,7 +146,7 @@ func datasourceOAPIVolumesRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("your query returned no results, please change your search criteria and try again") } - if err := d.Set("volumes", getOAPIVolumes(volumes)); err != nil { + if err := d.Set("volumes", flattenVolumes(volumes)); err != nil { return err } @@ -155,7 +155,7 @@ func datasourceOAPIVolumesRead(d *schema.ResourceData, meta interface{}) error { return nil } -func getOAPIVolumes(volumes []oscgo.Volume) (res []map[string]interface{}) { +func flattenVolumes(volumes []oscgo.Volume) (res []map[string]interface{}) { for _, v := range volumes { res = append(res, map[string]interface{}{ "creation_date": v.CreationDate, @@ -165,7 +165,7 @@ func getOAPIVolumes(volumes []oscgo.Volume) (res []map[string]interface{}) { "snapshot_id": v.SnapshotId, "state": v.State, "subregion_name": v.SubregionName, - "tags": tagsOSCAPIToMap(v.GetTags()), + "tags": tagsToMap(v.GetTags()), "volume_id": v.VolumeId, "volume_type": v.VolumeType, }) diff --git a/outscale/data_source_outscale_volumes_test.go b/outscale/data_source_outscale_volumes_test.go index e0dd64975..cd9e0c154 100644 --- a/outscale/data_source_outscale_volumes_test.go +++ b/outscale/data_source_outscale_volumes_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIVolumesDataSource_multipleFilters(t *testing.T) { +func TestAccVolumesDataSource_multipleFilters(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -17,9 +17,9 @@ func TestAccOutscaleOAPIVolumesDataSource_multipleFilters(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumeDataSourceConfigWithMultipleFilters(region), + Config: testAccCheckVolumeDataSourceConfigWithMultipleFilters(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volumes.ebs_volume"), + testAccCheckVolumeDataSourceID("data.outscale_volumes.ebs_volume"), resource.TestCheckResourceAttr("data.outscale_volumes.ebs_volume", "volumes.0.size", "1"), resource.TestCheckResourceAttr("data.outscale_volumes.ebs_volume", "volumes.0.volume_type", "standard"), ), @@ -28,7 +28,7 @@ func TestAccOutscaleOAPIVolumesDataSource_multipleFilters(t *testing.T) { }) } -func TestAccOutscaleOAPIVolumeDataSource_multipleVIdsFilters(t *testing.T) { +func TestAccVolumeDataSource_multipleVIdsFilters(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -37,9 +37,9 @@ func TestAccOutscaleOAPIVolumeDataSource_multipleVIdsFilters(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumesDataSourceConfigWithMultipleVolumeIDsFilter(region), + Config: testAccCheckVolumesDataSourceConfigWithMultipleVolumeIDsFilter(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volumes.outscale_volumes"), + testAccCheckVolumeDataSourceID("data.outscale_volumes.outscale_volumes"), resource.TestCheckResourceAttr("data.outscale_volumes.outscale_volumes", "volumes.0.size", "40"), ), }, @@ -47,7 +47,7 @@ func TestAccOutscaleOAPIVolumeDataSource_multipleVIdsFilters(t *testing.T) { }) } -func TestAccOutscaleOAPIVolumesDataSource_withVM(t *testing.T) { +func TestAccVolumesDataSource_withVM(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") omi := os.Getenv("OUTSCALE_IMAGEID") @@ -59,9 +59,9 @@ func TestAccOutscaleOAPIVolumesDataSource_withVM(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumesDataSourceConfigWithVM(region, omi, keypair, sgId), + Config: testAccCheckVolumesDataSourceConfigWithVM(region, omi, keypair, sgId), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volumes.outscale_volumes"), + testAccCheckVolumeDataSourceID("data.outscale_volumes.outscale_volumes"), // resource.TestCheckResourceAttr("data.outscale_volumes.outscale_volumes", "volumes.0.size", "1"), // resource.TestCheckResourceAttr("data.outscale_volumes.outscale_volumes", "volumes.0.volume_type", "standard"), ), @@ -70,7 +70,7 @@ func TestAccOutscaleOAPIVolumesDataSource_withVM(t *testing.T) { }) } -func testAccCheckOutscaleOAPIVolumeDataSourceConfigWithMultipleFilters(region string) string { +func testAccCheckVolumeDataSourceConfigWithMultipleFilters(region string) string { return fmt.Sprintf(` resource "outscale_volume" "external" { subregion_name = "%sa" @@ -97,7 +97,7 @@ func testAccCheckOutscaleOAPIVolumeDataSourceConfigWithMultipleFilters(region st `, region) } -func testAccCheckOutscaleOAPIVolumesDataSourceConfigWithMultipleVolumeIDsFilter(region string) string { +func testAccCheckVolumesDataSourceConfigWithMultipleVolumeIDsFilter(region string) string { return fmt.Sprintf(` resource "outscale_volume" "outscale_volume" { subregion_name = "%[1]sa" @@ -118,7 +118,7 @@ func testAccCheckOutscaleOAPIVolumesDataSourceConfigWithMultipleVolumeIDsFilter( `, region) } -func testAccCheckOutscaleOAPIVolumesDataSourceConfigWithVM(region, imageID, keypair, sgId string) string { +func testAccCheckVolumesDataSourceConfigWithVM(region, imageID, keypair, sgId string) string { return fmt.Sprintf(` resource "outscale_volume" "outscale_volume" { subregion_name = "%[1]sa" diff --git a/outscale/data_source_outscale_vpn_connection.go b/outscale/data_source_outscale_vpn_connection.go index 2861be130..6f2d83ea4 100644 --- a/outscale/data_source_outscale_vpn_connection.go +++ b/outscale/data_source_outscale_vpn_connection.go @@ -14,9 +14,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func dataSourceOutscaleVPNConnection() *schema.Resource { +func dataSourceVPNConnection() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleVPNConnectionRead, + Read: dataSourceVPNConnectionRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), "vpn_connection_id": { @@ -104,8 +104,8 @@ func dataSourceOutscaleVPNConnection() *schema.Resource { } } -func dataSourceOutscaleVPNConnectionRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVPNConnectionRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") vpnConnectionID, vpnConnectionOk := d.GetOk("vpn_connection_id") @@ -123,7 +123,7 @@ func dataSourceOutscaleVPNConnectionRead(d *schema.ResourceData, meta interface{ } if filtersOk { - params.Filters = buildOutscaleDataSourceVPNConnectionFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceVPNConnectionFilters(filters.(*schema.Set)) } var resp oscgo.ReadVpnConnectionsResponse @@ -174,7 +174,7 @@ func dataSourceOutscaleVPNConnectionRead(d *schema.ResourceData, meta interface{ if err := d.Set("routes", flattenVPNConnection(vpnConnection.GetRoutes())); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(vpnConnection.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(vpnConnection.GetTags())); err != nil { return err } if err := d.Set("vgw_telemetries", flattenVgwTelemetries(vpnConnection.GetVgwTelemetries())); err != nil { @@ -185,7 +185,7 @@ func dataSourceOutscaleVPNConnectionRead(d *schema.ResourceData, meta interface{ return nil } -func buildOutscaleDataSourceVPNConnectionFilters(set *schema.Set) *oscgo.FiltersVpnConnection { +func buildDataSourceVPNConnectionFilters(set *schema.Set) *oscgo.FiltersVpnConnection { var filters oscgo.FiltersVpnConnection for _, v := range set.List() { m := v.(map[string]interface{}) diff --git a/outscale/data_source_outscale_vpn_connection_test.go b/outscale/data_source_outscale_vpn_connection_test.go index 52e5ef9e3..a964ec509 100644 --- a/outscale/data_source_outscale_vpn_connection_test.go +++ b/outscale/data_source_outscale_vpn_connection_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleVPNConnectionDataSource_basic(t *testing.T) { +func TestAccVPNConnectionDataSource_basic(t *testing.T) { t.Parallel() publicIP := fmt.Sprintf("172.0.0.%d", acctest.RandIntRange(1, 255)) @@ -17,13 +17,13 @@ func TestAccOutscaleVPNConnectionDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionDataSourceConfigBasic(publicIP), + Config: testAccVPNConnectionDataSourceConfigBasic(publicIP), }, }, }) } -func TestAccOutscaleVPNConnectionDataSource_withFilters(t *testing.T) { +func TestAccVPNConnectionDataSource_withFilters(t *testing.T) { t.Parallel() publicIP := fmt.Sprintf("172.0.0.%d", acctest.RandIntRange(1, 255)) @@ -32,13 +32,13 @@ func TestAccOutscaleVPNConnectionDataSource_withFilters(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionDataSourceConfigWithFilters(publicIP), + Config: testAccVPNConnectionDataSourceConfigWithFilters(publicIP), }, }, }) } -func testAccOutscaleVPNConnectionDataSourceConfigBasic(publicIP string) string { +func testAccVPNConnectionDataSourceConfigBasic(publicIP string) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "virtual_gateway" { connection_type = "ipsec.1" @@ -68,7 +68,7 @@ func testAccOutscaleVPNConnectionDataSourceConfigBasic(publicIP string) string { `, publicIP) } -func testAccOutscaleVPNConnectionDataSourceConfigWithFilters(publicIP string) string { +func testAccVPNConnectionDataSourceConfigWithFilters(publicIP string) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "virtual_gateway" { connection_type = "ipsec.1" diff --git a/outscale/data_source_outscale_vpn_connections.go b/outscale/data_source_outscale_vpn_connections.go index 414790fff..f6d889409 100644 --- a/outscale/data_source_outscale_vpn_connections.go +++ b/outscale/data_source_outscale_vpn_connections.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func dataSourceOutscaleVPNConnections() *schema.Resource { +func dataSourceVPNConnections() *schema.Resource { return &schema.Resource{ - Read: dataSourceOutscaleVPNConnectionsRead, + Read: dataSourceVPNConnectionsRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), @@ -116,8 +116,8 @@ func dataSourceOutscaleVPNConnections() *schema.Resource { } } -func dataSourceOutscaleVPNConnectionsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func dataSourceVPNConnectionsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filters, filtersOk := d.GetOk("filter") vpnConnectionIDs, vpnConnectionOk := d.GetOk("vpn_connection_ids") @@ -136,7 +136,7 @@ func dataSourceOutscaleVPNConnectionsRead(d *schema.ResourceData, meta interface } if filtersOk { - params.Filters = buildOutscaleDataSourceVPNConnectionFilters(filters.(*schema.Set)) + params.Filters = buildDataSourceVPNConnectionFilters(filters.(*schema.Set)) } var resp oscgo.ReadVpnConnectionsResponse @@ -177,7 +177,7 @@ func flattenVPNConnections(vpnConnections []oscgo.VpnConnection) []map[string]in "client_gateway_configuration": vpnConnection.GetClientGatewayConfiguration(), "state": vpnConnection.GetState(), "routes": flattenVPNConnection(vpnConnection.GetRoutes()), - "tags": tagsOSCAPIToMap(vpnConnection.GetTags()), + "tags": tagsToMap(vpnConnection.GetTags()), "vgw_telemetries": flattenVgwTelemetries(vpnConnection.GetVgwTelemetries()), } } diff --git a/outscale/data_source_outscale_vpn_connections_test.go b/outscale/data_source_outscale_vpn_connections_test.go index 5b69bea6c..6484f036b 100644 --- a/outscale/data_source_outscale_vpn_connections_test.go +++ b/outscale/data_source_outscale_vpn_connections_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleVPNConnectionsDataSource_basic(t *testing.T) { +func TestAccVPNConnectionsDataSource_basic(t *testing.T) { t.Parallel() publicIP := fmt.Sprintf("172.0.0.%d", acctest.RandIntRange(1, 255)) @@ -17,13 +17,13 @@ func TestAccOutscaleVPNConnectionsDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionsDataSourceConfigBasic(publicIP), + Config: testAccVPNConnectionsDataSourceConfigBasic(publicIP), }, }, }) } -func TestAccOutscaleVPNConnectionsDataSource_withFilters(t *testing.T) { +func TestAccVPNConnectionsDataSource_withFilters(t *testing.T) { t.Parallel() publicIP := fmt.Sprintf("172.0.0.%d", acctest.RandIntRange(1, 255)) @@ -32,13 +32,13 @@ func TestAccOutscaleVPNConnectionsDataSource_withFilters(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionsDataSourceConfigWithFilters(publicIP), + Config: testAccVPNConnectionsDataSourceConfigWithFilters(publicIP), }, }, }) } -func testAccOutscaleVPNConnectionsDataSourceConfigBasic(publicIP string) string { +func testAccVPNConnectionsDataSourceConfigBasic(publicIP string) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "virtual_gateway" { connection_type = "ipsec.1" @@ -68,7 +68,7 @@ func testAccOutscaleVPNConnectionsDataSourceConfigBasic(publicIP string) string `, publicIP) } -func testAccOutscaleVPNConnectionsDataSourceConfigWithFilters(publicIP string) string { +func testAccVPNConnectionsDataSourceConfigWithFilters(publicIP string) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "virtual_gateway" { connection_type = "ipsec.1" diff --git a/outscale/dictionary.go b/outscale/dictionary.go index ed26294ac..16f690ab6 100644 --- a/outscale/dictionary.go +++ b/outscale/dictionary.go @@ -17,94 +17,94 @@ var datasources Dictionary func init() { resources = Dictionary{ "oapi": ResourceMap{ - "outscale_vm": resourceOutscaleOApiVM, - "outscale_firewall_rules_set": resourceOutscaleOAPISecurityGroup, - "outscale_security_group": resourceOutscaleOAPISecurityGroup, - "outscale_image": resourceOutscaleOAPIImage, - "outscale_keypair": resourceOutscaleOAPIKeyPair, - "outscale_public_ip": resourceOutscaleOAPIPublicIP, - "outscale_public_ip_link": resourceOutscaleOAPIPublicIPLink, - "outscale_volume": resourceOutscaleOAPIVolume, - "outscale_volumes_link": resourceOutscaleOAPIVolumeLink, - "outscale_outbound_rule": resourceOutscaleOAPIOutboundRule, - "outscale_security_group_rule": resourceOutscaleOAPIOutboundRule, - "outscale_tag": resourceOutscaleOAPITags, - "outscale_net_attributes": resourceOutscaleOAPILinAttributes, - "outscale_net": resourceOutscaleOAPINet, - "outscale_internet_service": resourceOutscaleOAPIInternetService, - "outscale_internet_service_link": resourceOutscaleOAPIInternetServiceLink, - "outscale_nat_service": resourceOutscaleOAPINatService, - "outscale_subnet": resourceOutscaleOAPISubNet, - "outscale_route": resourceOutscaleOAPIRoute, - "outscale_route_table": resourceOutscaleOAPIRouteTable, - "outscale_route_table_link": resourceOutscaleOAPILinkRouteTable, - "outscale_snapshot": resourceOutscaleOAPISnapshot, - "outscale_image_launch_permission": resourceOutscaleOAPIImageLaunchPermission, - "outscale_net_peering": resourceOutscaleOAPILinPeeringConnection, - "outscale_nic_private_ip": resourceOutscaleOAPINetworkInterfacePrivateIP, - "outscale_nic_link": resourceOutscaleOAPINetworkInterfaceAttachment, - "outscale_nic": resourceOutscaleOAPINic, - "outscale_snapshot_attributes": resourcedOutscaleOAPISnapshotAttributes, - "outscale_image_export_task": resourceOutscaleOAPIIMageExportTask, - "outscale_net_peering_acceptation": resourceOutscaleOAPILinPeeringConnectionAccepter, - "outscale_server_certificate": resourceOutscaleOAPIServerCertificate, - "outscale_snapshot_export_task": resourceOutscaleOAPISnapshotExportTask, - "outscale_ca": resourceOutscaleOAPICa, - "outscale_api_access_rule": resourceOutscaleOAPIApiAccessRule, - "outscale_api_access_policy": resourceOutscaleOAPIApiAccessPolicy, + "outscale_vm": resourceVM, + "outscale_firewall_rules_set": resourceSecurityGroup, + "outscale_security_group": resourceSecurityGroup, + "outscale_image": resourceImage, + "outscale_keypair": resourceKeyPair, + "outscale_public_ip": resourcePublicIP, + "outscale_public_ip_link": resourcePublicIPLink, + "outscale_volume": resourceVolume, + "outscale_volumes_link": resourceVolumeLink, + "outscale_outbound_rule": resourceOutboundRule, + "outscale_security_group_rule": resourceOutboundRule, + "outscale_tag": resourceTags, + "outscale_net_attributes": resourceLinAttributes, + "outscale_net": resourceNet, + "outscale_internet_service": resourceInternetService, + "outscale_internet_service_link": resourceInternetServiceLink, + "outscale_nat_service": resourceNatService, + "outscale_subnet": resourceSubNet, + "outscale_route": resourceRoute, + "outscale_route_table": resourceRouteTable, + "outscale_route_table_link": resourceLinkRouteTable, + "outscale_snapshot": resourceSnapshot, + "outscale_image_launch_permission": resourceImageLaunchPermission, + "outscale_net_peering": resourceLinPeeringConnection, + "outscale_nic_private_ip": resourceNetworkInterfacePrivateIP, + "outscale_nic_link": resourceNetworkInterfaceAttachment, + "outscale_nic": resourceNic, + "outscale_snapshot_attributes": resourcedSnapshotAttributes, + "outscale_image_export_task": resourceIMageExportTask, + "outscale_net_peering_acceptation": resourceLinPeeringConnectionAccepter, + "outscale_server_certificate": resourceServerCertificate, + "outscale_snapshot_export_task": resourceSnapshotExportTask, + "outscale_ca": resourceCa, + "outscale_api_access_rule": resourceApiAccessRule, + "outscale_api_access_policy": resourceApiAccessPolicy, }, } datasources = Dictionary{ "oapi": ResourceMap{ - "outscale_vm": dataSourceOutscaleOAPIVM, - "outscale_vms": datasourceOutscaleOApiVMS, - "outscale_firewall_rules_sets": dataSourceOutscaleOAPISecurityGroups, - "outscale_security_groups": dataSourceOutscaleOAPISecurityGroups, - "outscale_images": dataSourceOutscaleOAPIImages, - "outscale_firewall_rules_set": dataSourceOutscaleOAPISecurityGroup, - "outscale_security_group": dataSourceOutscaleOAPISecurityGroup, - "outscale_tag": dataSourceOutscaleOAPITag, - "outscale_tags": dataSourceOutscaleOAPITags, - "outscale_volume": datasourceOutscaleOAPIVolume, - "outscale_volumes": datasourceOutscaleOAPIVolumes, - "outscale_keypair": datasourceOutscaleOAPIKeyPair, - "outscale_keypairs": datasourceOutscaleOAPIKeyPairs, - "outscale_internet_service": datasourceOutscaleOAPIInternetService, - "outscale_internet_services": datasourceOutscaleOAPIInternetServices, - "outscale_subnet": dataSourceOutscaleOAPISubnet, - "outscale_subnets": dataSourceOutscaleOAPISubnets, - "outscale_vm_state": dataSourceOutscaleOAPIVMState, - "outscale_vm_states": dataSourceOutscaleOAPIVMStates, - "outscale_net": dataSourceOutscaleOAPIVpc, - "outscale_nets": dataSourceOutscaleOAPIVpcs, - "outscale_net_attributes": dataSourceOutscaleOAPIVpcAttr, - "outscale_route_table": dataSourceOutscaleOAPIRouteTable, - "outscale_route_tables": dataSourceOutscaleOAPIRouteTables, - "outscale_snapshot": dataSourceOutscaleOAPISnapshot, - "outscale_snapshots": dataSourceOutscaleOAPISnapshots, - "outscale_net_peering": dataSourceOutscaleOAPILinPeeringConnection, - "outscale_net_peerings": dataSourceOutscaleOAPILinPeeringsConnection, - "outscale_nic": dataSourceOutscaleOAPINic, - "outscale_nics": dataSourceOutscaleOAPINics, - "outscale_image": dataSourceOutscaleOAPIImage, - "outscale_public_ip": dataSourceOutscaleOAPIPublicIP, - "outscale_public_ips": dataSourceOutscaleOAPIPublicIPS, - "outscale_nat_service": dataSourceOutscaleOAPINatService, - "outscale_nat_services": dataSourceOutscaleOAPINatServices, - "outscale_subregions": dataSourceOutscaleOAPISubregions, - "outscale_regions": dataSourceOutscaleOAPIRegions, - "outscale_image_export_task": dataSourceOutscaleOAPIImageExportTask, - "outscale_image_export_tasks": dataSourceOutscaleOAPIImageExportTasks, - "outscale_server_certificate": datasourceOutscaleOAPIServerCertificate, - "outscale_server_certificates": datasourceOutscaleOAPIServerCertificates, - "outscale_snapshot_export_task": dataSourceOutscaleOAPISnapshotExportTask, - "outscale_snapshot_export_tasks": dataSourceOutscaleOAPISnapshotExportTasks, - "outscale_ca": dataSourceOutscaleOAPICa, - "outscale_cas": dataSourceOutscaleOAPICas, - "outscale_api_access_rule": dataSourceOutscaleOAPIApiAccessRule, - "outscale_api_access_rules": dataSourceOutscaleOAPIApiAccessRules, - "outscale_api_access_policy": dataSourceOutscaleOAPIApiAccessPolicy, + "outscale_vm": dataSourceVM, + "outscale_vms": dataSourceVMS, + "outscale_firewall_rules_sets": dataSourceSecurityGroups, + "outscale_security_groups": dataSourceSecurityGroups, + "outscale_images": dataSourceImages, + "outscale_firewall_rules_set": dataSourceSecurityGroup, + "outscale_security_group": dataSourceSecurityGroup, + "outscale_tag": dataSourceTag, + "outscale_tags": dataSourceTags, + "outscale_volume": dataSourceVolume, + "outscale_volumes": dataSourceVolumes, + "outscale_keypair": dataSourceKeyPair, + "outscale_keypairs": dataSourceKeyPairs, + "outscale_internet_service": dataSourceInternetService, + "outscale_internet_services": dataSourceInternetServices, + "outscale_subnet": dataSourceSubnet, + "outscale_subnets": dataSourceSubnets, + "outscale_vm_state": dataSourceVMState, + "outscale_vm_states": dataSourceVMStates, + "outscale_net": dataSourceVpc, + "outscale_nets": dataSourceVpcs, + "outscale_net_attributes": dataSourceVpcAttr, + "outscale_route_table": dataSourceRouteTable, + "outscale_route_tables": dataSourceRouteTables, + "outscale_snapshot": dataSourceSnapshot, + "outscale_snapshots": dataSourceSnapshots, + "outscale_net_peering": dataSourceLinPeeringConnection, + "outscale_net_peerings": dataSourceLinPeeringsConnection, + "outscale_nic": dataSourceNic, + "outscale_nics": dataSourceNics, + "outscale_image": dataSourceImage, + "outscale_public_ip": dataSourcePublicIP, + "outscale_public_ips": dataSourcePublicIPS, + "outscale_nat_service": dataSourceNatService, + "outscale_nat_services": dataSourceNatServices, + "outscale_subregions": dataSourceSubregions, + "outscale_regions": dataSourceRegions, + "outscale_image_export_task": dataSourceImageExportTask, + "outscale_image_export_tasks": dataSourceImageExportTasks, + "outscale_server_certificate": dataSourceServerCertificate, + "outscale_server_certificates": dataSourceServerCertificates, + "outscale_snapshot_export_task": dataSourceSnapshotExportTask, + "outscale_snapshot_export_tasks": dataSourceSnapshotExportTasks, + "outscale_ca": dataSourceCa, + "outscale_cas": dataSourceCas, + "outscale_api_access_rule": dataSourceApiAccessRule, + "outscale_api_access_rules": dataSourceApiAccessRules, + "outscale_api_access_policy": dataSourceApiAccessPolicy, }, } } diff --git a/outscale/import_outscale_net_attributes_test.go b/outscale/import_outscale_net_attributes_test.go index f6aca696f..c274e13b7 100644 --- a/outscale/import_outscale_net_attributes_test.go +++ b/outscale/import_outscale_net_attributes_test.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleNetAttr_import(t *testing.T) { +func TestAccNetAttr_import(t *testing.T) { t.Parallel() resourceName := "outscale_net_attributes.outscale_net_attributes" @@ -15,7 +15,7 @@ func TestAccOutscaleNetAttr_import(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILinAttrConfig, + Config: testAccLinAttrConfig, }, { ResourceName: resourceName, diff --git a/outscale/instance_set_set.go b/outscale/instance_set_set.go index 514c168e6..732aedfac 100644 --- a/outscale/instance_set_set.go +++ b/outscale/instance_set_set.go @@ -10,7 +10,7 @@ import ( oscgo "github.com/outscale/osc-sdk-go/v2" ) -func getOAPISecurityGroups(groups []oscgo.SecurityGroupLight) (SecurityGroup []map[string]interface{}, SecurityGroupIds []string) { +func getSecurityGroups(groups []oscgo.SecurityGroupLight) (SecurityGroup []map[string]interface{}, SecurityGroupIds []string) { for _, g := range groups { SecurityGroup = append(SecurityGroup, map[string]interface{}{ "security_group_id": g.GetSecurityGroupId(), @@ -21,7 +21,7 @@ func getOAPISecurityGroups(groups []oscgo.SecurityGroupLight) (SecurityGroup []m return } -func getOAPILinkNicLight(l oscgo.LinkNicLight) []map[string]interface{} { +func getLinkNicLight(l oscgo.LinkNicLight) []map[string]interface{} { return []map[string]interface{}{{ "delete_on_vm_deletion": l.GetDeleteOnVmDeletion(), "device_number": fmt.Sprintf("%d", l.GetDeviceNumber()), @@ -30,7 +30,7 @@ func getOAPILinkNicLight(l oscgo.LinkNicLight) []map[string]interface{} { }} } -func getOAPILinkNic(l oscgo.LinkNic) map[string]interface{} { +func getLinkNic(l oscgo.LinkNic) map[string]interface{} { return map[string]interface{}{ "delete_on_vm_deletion": strconv.FormatBool(l.GetDeleteOnVmDeletion()), "device_number": fmt.Sprintf("%d", l.GetDeviceNumber()), @@ -41,7 +41,7 @@ func getOAPILinkNic(l oscgo.LinkNic) map[string]interface{} { } } -func getOAPILinkPublicIPLight(l oscgo.LinkPublicIpLightForVm) *schema.Set { +func getLinkPublicIPLight(l oscgo.LinkPublicIpLightForVm) *schema.Set { res := &schema.Set{ F: func(v interface{}) int { var buf bytes.Buffer @@ -60,7 +60,7 @@ func getOAPILinkPublicIPLight(l oscgo.LinkPublicIpLightForVm) *schema.Set { return res } -func getOAPILinkPublicIP(l oscgo.LinkPublicIp) map[string]interface{} { +func getLinkPublicIP(l oscgo.LinkPublicIp) map[string]interface{} { return map[string]interface{}{ "link_public_ip_id": l.GetLinkPublicIpId(), "public_dns_name": l.GetPublicDnsName(), @@ -70,7 +70,7 @@ func getOAPILinkPublicIP(l oscgo.LinkPublicIp) map[string]interface{} { } } -func getOAPIPrivateIPsLight(privateIPs []oscgo.PrivateIpLightForVm) *schema.Set { +func getPrivateIPsLight(privateIPs []oscgo.PrivateIpLightForVm) *schema.Set { res := &schema.Set{ F: func(v interface{}) int { var buf bytes.Buffer @@ -89,7 +89,7 @@ func getOAPIPrivateIPsLight(privateIPs []oscgo.PrivateIpLightForVm) *schema.Set } if p.HasLinkPublicIp() { - r["link_public_ip"] = getOAPILinkPublicIPLight(p.GetLinkPublicIp()) + r["link_public_ip"] = getLinkPublicIPLight(p.GetLinkPublicIp()) } res.Add(r) @@ -97,11 +97,11 @@ func getOAPIPrivateIPsLight(privateIPs []oscgo.PrivateIpLightForVm) *schema.Set return res } -func getOAPIPrivateIPs(privateIPs []oscgo.PrivateIp) (res []map[string]interface{}) { +func getPrivateIPs(privateIPs []oscgo.PrivateIp) (res []map[string]interface{}) { for _, p := range privateIPs { res = append(res, map[string]interface{}{ "is_primary": p.GetIsPrimary(), - "link_public_ip": getOAPILinkPublicIP(p.GetLinkPublicIp()), + "link_public_ip": getLinkPublicIP(p.GetLinkPublicIp()), "private_dns_name": p.GetPrivateDnsName(), "private_ip": p.GetPrivateIp(), }) @@ -109,9 +109,9 @@ func getOAPIPrivateIPs(privateIPs []oscgo.PrivateIp) (res []map[string]interface return } -func getOAPIVMNetworkInterfaceLightSet(nics []oscgo.NicLight) (res []map[string]interface{}) { +func getVMNetworkInterfaceLightSet(nics []oscgo.NicLight) (res []map[string]interface{}) { for _, nic := range nics { - securityGroups, securityGroupIds := getOAPISecurityGroups(nic.GetSecurityGroups()) + securityGroups, securityGroupIds := getSecurityGroups(nic.GetSecurityGroups()) nicMap := map[string]interface{}{ "delete_on_vm_deletion": nic.LinkNic.GetDeleteOnVmDeletion(), // Workaround. @@ -133,15 +133,15 @@ func getOAPIVMNetworkInterfaceLightSet(nics []oscgo.NicLight) (res []map[string] } if nic.HasLinkPublicIp() { - nicMap["link_public_ip"] = getOAPILinkPublicIPLight(nic.GetLinkPublicIp()) + nicMap["link_public_ip"] = getLinkPublicIPLight(nic.GetLinkPublicIp()) } if nic.HasPrivateIps() { - nicMap["private_ips"] = getOAPIPrivateIPsLight(nic.GetPrivateIps()) + nicMap["private_ips"] = getPrivateIPsLight(nic.GetPrivateIps()) } if nic.HasLinkNic() { - nicMap["link_nic"] = getOAPILinkNicLight(nic.GetLinkNic()) + nicMap["link_nic"] = getLinkNicLight(nic.GetLinkNic()) } res = append(res, nicMap) @@ -149,25 +149,25 @@ func getOAPIVMNetworkInterfaceLightSet(nics []oscgo.NicLight) (res []map[string] return } -func getOAPIVMNetworkInterfaceSet(nics []oscgo.Nic) (res []map[string]interface{}) { +func getVMNetworkInterfaceSet(nics []oscgo.Nic) (res []map[string]interface{}) { for _, nic := range nics { - securityGroups, _ := getOAPISecurityGroups(*nic.SecurityGroups) + securityGroups, _ := getSecurityGroups(*nic.SecurityGroups) res = append(res, map[string]interface{}{ "account_id": nic.GetAccountId(), "description": nic.GetDescription(), "is_source_dest_checked": nic.GetIsSourceDestChecked(), - "link_nic": getOAPILinkNic(nic.GetLinkNic()), - "link_public_ip": getOAPILinkPublicIP(nic.GetLinkPublicIp()), + "link_nic": getLinkNic(nic.GetLinkNic()), + "link_public_ip": getLinkPublicIP(nic.GetLinkPublicIp()), "mac_address": nic.GetMacAddress(), "net_id": nic.GetNetId(), "nic_id": nic.GetNicId(), "private_dns_name": nic.GetPrivateDnsName(), - "private_ips": getOAPIPrivateIPs(nic.GetPrivateIps()), + "private_ips": getPrivateIPs(nic.GetPrivateIps()), "security_groups": securityGroups, "state": nic.GetState(), "subnet_id": nic.GetSubnetId(), "subregion_name": nic.GetSubregionName(), - "tags": getOapiTagSet(nic.Tags), + "tags": getTagSet(nic.GetTags()), }) } return diff --git a/outscale/oapi_tags.go b/outscale/oapi_tags.go index 753ac892c..4c5038e85 100644 --- a/outscale/oapi_tags.go +++ b/outscale/oapi_tags.go @@ -14,13 +14,13 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func setOSCAPITags(conn *oscgo.APIClient, d *schema.ResourceData) error { +func setTags(conn *oscgo.APIClient, d *schema.ResourceData) error { if d.HasChange("tags") { oraw, nraw := d.GetChange("tags") o := oraw.(*schema.Set) n := nraw.(*schema.Set) - create, remove := diffOSCAPITags(tagsFromSliceMap(o), tagsFromSliceMap(n)) + create, remove := diffTags(tagsFromSliceMap(o), tagsFromSliceMap(n)) // Set tag if len(remove) > 0 { @@ -64,7 +64,7 @@ func setOSCAPITags(conn *oscgo.APIClient, d *schema.ResourceData) error { return nil } -func tagsOAPIListSchemaComputed() *schema.Schema { +func tagsListSchemaComputed() *schema.Schema { return &schema.Schema{ Type: schema.TypeSet, Computed: true, @@ -83,7 +83,7 @@ func tagsOAPIListSchemaComputed() *schema.Schema { } } -func tagsListOAPISchema2(computed bool) *schema.Schema { +func tagsListSchema2(computed bool) *schema.Schema { stype := schema.TypeSet if computed { @@ -105,7 +105,7 @@ func tagsListOAPISchema2(computed bool) *schema.Schema { } } -func tagsListOAPISchema() *schema.Schema { +func tagsListSchema() *schema.Schema { return &schema.Schema{ Type: schema.TypeSet, Elem: &schema.Resource{ @@ -126,8 +126,8 @@ func tagsListOAPISchema() *schema.Schema { } } -// tagsOSCsAPI ToMap turns the list of tag into a map. -func tagsOSCAPIToMap(ts []oscgo.ResourceTag) []map[string]string { +// tagsToMap turns the list of tag into a map. +func tagsToMap(ts []oscgo.ResourceTag) []map[string]string { result := make([]map[string]string, len(ts)) if len(ts) > 0 { for k, t := range ts { @@ -143,7 +143,7 @@ func tagsOSCAPIToMap(ts []oscgo.ResourceTag) []map[string]string { return result } -func tagsOSCAPIFromMap(m map[string]interface{}) []oscgo.ResourceTag { +func tagsFromMap(m map[string]interface{}) []oscgo.ResourceTag { result := make([]oscgo.ResourceTag, 0, len(m)) for k, v := range m { t := oscgo.ResourceTag{ @@ -156,10 +156,10 @@ func tagsOSCAPIFromMap(m map[string]interface{}) []oscgo.ResourceTag { return result } -// diffOSCAPITags takes our tag locally and the ones remotely and returns +// diffTags takes our tag locally and the ones remotely and returns // the set of tag that must be created, and the set of tag that must // be destroyed. -func diffOSCAPITags(oldTags, newTags []oscgo.ResourceTag) ([]oscgo.ResourceTag, []oscgo.ResourceTag) { +func diffTags(oldTags, newTags []oscgo.ResourceTag) ([]oscgo.ResourceTag, []oscgo.ResourceTag) { // First, we're creating everything we have create := make(map[string]interface{}) for _, t := range newTags { @@ -188,7 +188,7 @@ func diffOSCAPITags(oldTags, newTags []oscgo.ResourceTag) ([]oscgo.ResourceTag, } } - return tagsOSCAPIFromMap(tagsToCreate), remove + return tagsFromMap(tagsToCreate), remove } func tagsFromMapLBU(m map[string]interface{}) *[]oscgo.ResourceTag { @@ -218,11 +218,11 @@ func tagsFromSliceMap(m *schema.Set) []oscgo.ResourceTag { return result } -func oapiTagsDescToList(ts []oscgo.Tag) []map[string]interface{} { +func tagsDescToList(ts []oscgo.Tag) []map[string]interface{} { res := make([]map[string]interface{}, len(ts)) for i, t := range ts { - if !oapiTagDescIgnored(&t) { + if !tagDescIgnored(&t) { res[i] = map[string]interface{}{ "key": t.Key, "value": t.Value, @@ -234,7 +234,7 @@ func oapiTagsDescToList(ts []oscgo.Tag) []map[string]interface{} { return res } -func oapiTagDescIgnored(t *oscgo.Tag) bool { +func tagDescIgnored(t *oscgo.Tag) bool { filter := []string{"^outscale:"} for _, v := range filter { if r, _ := regexp.MatchString(v, t.GetKey()); r { @@ -292,24 +292,7 @@ func tagsSchema() *schema.Schema { } } -func getOapiTagSet(tags *[]oscgo.ResourceTag) []map[string]interface{} { - res := []map[string]interface{}{} - - if tags != nil { - for _, t := range *tags { - tag := map[string]interface{}{} - - tag["key"] = t.Key - tag["value"] = t.Value - - res = append(res, tag) - } - } - - return res -} - -func getOscAPITagSet(tags []oscgo.ResourceTag) []map[string]interface{} { +func getTagSet(tags []oscgo.ResourceTag) []map[string]interface{} { res := []map[string]interface{}{} for _, t := range tags { diff --git a/outscale/provider.go b/outscale/provider.go index c558f8ab4..e45c79487 100644 --- a/outscale/provider.go +++ b/outscale/provider.go @@ -51,132 +51,132 @@ func Provider() terraform.ResourceProvider { }, ResourcesMap: map[string]*schema.Resource{ - "outscale_vm": resourceOutscaleOApiVM(), - "outscale_keypair": resourceOutscaleOAPIKeyPair(), - "outscale_image": resourceOutscaleOAPIImage(), - "outscale_internet_service_link": resourceOutscaleOAPIInternetServiceLink(), - "outscale_internet_service": resourceOutscaleOAPIInternetService(), - "outscale_net": resourceOutscaleOAPINet(), - "outscale_security_group": resourceOutscaleOAPISecurityGroup(), - "outscale_outbound_rule": resourceOutscaleOAPIOutboundRule(), - "outscale_security_group_rule": resourceOutscaleOAPIOutboundRule(), - "outscale_tag": resourceOutscaleOAPITags(), - "outscale_public_ip": resourceOutscaleOAPIPublicIP(), - "outscale_public_ip_link": resourceOutscaleOAPIPublicIPLink(), - "outscale_volume": resourceOutscaleOAPIVolume(), - "outscale_volumes_link": resourceOutscaleOAPIVolumeLink(), - "outscale_net_attributes": resourceOutscaleOAPILinAttributes(), - "outscale_nat_service": resourceOutscaleOAPINatService(), - "outscale_subnet": resourceOutscaleOAPISubNet(), - "outscale_route": resourceOutscaleOAPIRoute(), - "outscale_route_table": resourceOutscaleOAPIRouteTable(), - "outscale_route_table_link": resourceOutscaleOAPILinkRouteTable(), - "outscale_nic": resourceOutscaleOAPINic(), - "outscale_snapshot": resourceOutscaleOAPISnapshot(), - "outscale_image_launch_permission": resourceOutscaleOAPIImageLaunchPermission(), - "outscale_net_peering": resourceOutscaleOAPILinPeeringConnection(), - "outscale_net_peering_acceptation": resourceOutscaleOAPILinPeeringConnectionAccepter(), - "outscale_net_access_point": resourceOutscaleNetAccessPoint(), - "outscale_nic_link": resourceOutscaleOAPINetworkInterfaceAttachment(), - "outscale_nic_private_ip": resourceOutscaleOAPINetworkInterfacePrivateIP(), - "outscale_snapshot_attributes": resourcedOutscaleOAPISnapshotAttributes(), - "outscale_dhcp_option": resourceOutscaleDHCPOption(), - "outscale_client_gateway": resourceOutscaleClientGateway(), - "outscale_virtual_gateway": resourceOutscaleOAPIVirtualGateway(), - "outscale_virtual_gateway_link": resourceOutscaleOAPIVirtualGatewayLink(), - "outscale_virtual_gateway_route_propagation": resourceOutscaleOAPIVirtualGatewayRoutePropagation(), - "outscale_vpn_connection": resourceOutscaleVPNConnection(), - "outscale_vpn_connection_route": resourceOutscaleVPNConnectionRoute(), - "outscale_access_key": resourceOutscaleAccessKey(), - "outscale_load_balancer": resourceOutscaleOAPILoadBalancer(), - "outscale_load_balancer_policy": resourceOutscaleAppCookieStickinessPolicy(), - "outscale_load_balancer_vms": resourceOutscaleOAPILBUAttachment(), - "outscale_load_balancer_attributes": resourceOutscaleOAPILoadBalancerAttributes(), - "outscale_load_balancer_listener_rule": resourceOutscaleLoadBalancerListenerRule(), - "outscale_flexible_gpu": resourceOutscaleOAPIFlexibleGpu(), - "outscale_flexible_gpu_link": resourceOutscaleOAPIFlexibleGpuLink(), - "outscale_image_export_task": resourceOutscaleOAPIIMageExportTask(), - "outscale_server_certificate": resourceOutscaleOAPIServerCertificate(), - "outscale_snapshot_export_task": resourceOutscaleOAPISnapshotExportTask(), - "outscale_ca": resourceOutscaleOAPICa(), - "outscale_api_access_rule": resourceOutscaleOAPIApiAccessRule(), - "outscale_api_access_policy": resourceOutscaleOAPIApiAccessPolicy(), + "outscale_vm": resourceVM(), + "outscale_keypair": resourceKeyPair(), + "outscale_image": resourceImage(), + "outscale_internet_service_link": resourceInternetServiceLink(), + "outscale_internet_service": resourceInternetService(), + "outscale_net": resourceNet(), + "outscale_security_group": resourceSecurityGroup(), + "outscale_outbound_rule": resourceOutboundRule(), + "outscale_security_group_rule": resourceOutboundRule(), + "outscale_tag": resourceTags(), + "outscale_public_ip": resourcePublicIP(), + "outscale_public_ip_link": resourcePublicIPLink(), + "outscale_volume": resourceVolume(), + "outscale_volumes_link": resourceVolumeLink(), + "outscale_net_attributes": resourceLinAttributes(), + "outscale_nat_service": resourceNatService(), + "outscale_subnet": resourceSubNet(), + "outscale_route": resourceRoute(), + "outscale_route_table": resourceRouteTable(), + "outscale_route_table_link": resourceLinkRouteTable(), + "outscale_nic": resourceNic(), + "outscale_snapshot": resourceSnapshot(), + "outscale_image_launch_permission": resourceImageLaunchPermission(), + "outscale_net_peering": resourceLinPeeringConnection(), + "outscale_net_peering_acceptation": resourceLinPeeringConnectionAccepter(), + "outscale_net_access_point": resourceNetAccessPoint(), + "outscale_nic_link": resourceNetworkInterfaceAttachment(), + "outscale_nic_private_ip": resourceNetworkInterfacePrivateIP(), + "outscale_snapshot_attributes": resourcedSnapshotAttributes(), + "outscale_dhcp_option": resourceDHCPOption(), + "outscale_client_gateway": resourceClientGateway(), + "outscale_virtual_gateway": resourceVirtualGateway(), + "outscale_virtual_gateway_link": resourceVirtualGatewayLink(), + "outscale_virtual_gateway_route_propagation": resourceVirtualGatewayRoutePropagation(), + "outscale_vpn_connection": resourceVPNConnection(), + "outscale_vpn_connection_route": resourceVPNConnectionRoute(), + "outscale_access_key": resourceAccessKey(), + "outscale_load_balancer": resourceLoadBalancer(), + "outscale_load_balancer_policy": resourceAppCookieStickinessPolicy(), + "outscale_load_balancer_vms": resourceLBUAttachment(), + "outscale_load_balancer_attributes": resourceLoadBalancerAttributes(), + "outscale_load_balancer_listener_rule": resourceLoadBalancerListenerRule(), + "outscale_flexible_gpu": resourceFlexibleGpu(), + "outscale_flexible_gpu_link": resourceFlexibleGpuLink(), + "outscale_image_export_task": resourceIMageExportTask(), + "outscale_server_certificate": resourceServerCertificate(), + "outscale_snapshot_export_task": resourceSnapshotExportTask(), + "outscale_ca": resourceCa(), + "outscale_api_access_rule": resourceApiAccessRule(), + "outscale_api_access_policy": resourceApiAccessPolicy(), }, DataSourcesMap: map[string]*schema.Resource{ - "outscale_vm": dataSourceOutscaleOAPIVM(), - "outscale_vms": datasourceOutscaleOApiVMS(), - "outscale_security_group": dataSourceOutscaleOAPISecurityGroup(), - "outscale_security_groups": dataSourceOutscaleOAPISecurityGroups(), - "outscale_image": dataSourceOutscaleOAPIImage(), - "outscale_images": dataSourceOutscaleOAPIImages(), - "outscale_tag": dataSourceOutscaleOAPITag(), - "outscale_tags": dataSourceOutscaleOAPITags(), - "outscale_public_ip": dataSourceOutscaleOAPIPublicIP(), - "outscale_public_ips": dataSourceOutscaleOAPIPublicIPS(), - "outscale_volume": datasourceOutscaleOAPIVolume(), - "outscale_volumes": datasourceOutscaleOAPIVolumes(), - "outscale_nat_service": dataSourceOutscaleOAPINatService(), - "outscale_nat_services": dataSourceOutscaleOAPINatServices(), - "outscale_keypair": datasourceOutscaleOAPIKeyPair(), - "outscale_keypairs": datasourceOutscaleOAPIKeyPairs(), - "outscale_vm_state": dataSourceOutscaleOAPIVMState(), - "outscale_vm_states": dataSourceOutscaleOAPIVMStates(), - "outscale_internet_service": datasourceOutscaleOAPIInternetService(), - "outscale_internet_services": datasourceOutscaleOAPIInternetServices(), - "outscale_subnet": dataSourceOutscaleOAPISubnet(), - "outscale_subnets": dataSourceOutscaleOAPISubnets(), - "outscale_net": dataSourceOutscaleOAPIVpc(), - "outscale_nets": dataSourceOutscaleOAPIVpcs(), - "outscale_net_attributes": dataSourceOutscaleOAPIVpcAttr(), - "outscale_route_table": dataSourceOutscaleOAPIRouteTable(), - "outscale_route_tables": dataSourceOutscaleOAPIRouteTables(), - "outscale_snapshot": dataSourceOutscaleOAPISnapshot(), - "outscale_snapshots": dataSourceOutscaleOAPISnapshots(), - "outscale_net_peering": dataSourceOutscaleOAPILinPeeringConnection(), - "outscale_net_peerings": dataSourceOutscaleOAPILinPeeringsConnection(), - "outscale_nics": dataSourceOutscaleOAPINics(), - "outscale_nic": dataSourceOutscaleOAPINic(), - "outscale_client_gateway": dataSourceOutscaleClientGateway(), - "outscale_client_gateways": dataSourceOutscaleClientGateways(), - "outscale_virtual_gateway": dataSourceOutscaleOAPIVirtualGateway(), - "outscale_virtual_gateways": dataSourceOutscaleOAPIVirtualGateways(), - "outscale_vpn_connection": dataSourceOutscaleVPNConnection(), - "outscale_vpn_connections": dataSourceOutscaleVPNConnections(), - "outscale_access_key": dataSourceOutscaleAccessKey(), - "outscale_access_keys": dataSourceOutscaleAccessKeys(), - "outscale_dhcp_option": dataSourceOutscaleDHCPOption(), - "outscale_dhcp_options": dataSourceOutscaleDHCPOptions(), - "outscale_load_balancer": dataSourceOutscaleOAPILoadBalancer(), - "outscale_load_balancer_listener_rule": dataSourceOutscaleOAPILoadBalancerLDRule(), - "outscale_load_balancer_listener_rules": dataSourceOutscaleOAPILoadBalancerLDRules(), - "outscale_load_balancer_tags": dataSourceOutscaleOAPILBUTags(), - "outscale_load_balancer_vm_health": dataSourceOutscaleLoadBalancerVmsHeals(), - "outscale_load_balancers": dataSourceOutscaleOAPILoadBalancers(), - "outscale_vm_types": dataSourceOutscaleOAPIVMTypes(), - "outscale_net_access_point": dataSourceOutscaleNetAccessPoint(), - "outscale_net_access_points": dataSourceOutscaleNetAccessPoints(), - "outscale_flexible_gpu": dataSourceOutscaleOAPIFlexibleGpu(), - "outscale_flexible_gpus": dataSourceOutscaleOAPIFlexibleGpus(), - "outscale_subregions": dataSourceOutscaleOAPISubregions(), - "outscale_regions": dataSourceOutscaleOAPIRegions(), - "outscale_net_access_point_services": dataSourceOutscaleOAPINetAccessPointServices(), - "outscale_flexible_gpu_catalog": dataSourceOutscaleOAPIFlexibleGpuCatalog(), - "outscale_product_type": dataSourceOutscaleOAPIProductType(), - "outscale_product_types": dataSourceOutscaleOAPIProductTypes(), - "outscale_quota": dataSourceOutscaleOAPIQuota(), - "outscale_quotas": dataSourceOutscaleOAPIQuotas(), - "outscale_image_export_task": dataSourceOutscaleOAPIImageExportTask(), - "outscale_image_export_tasks": dataSourceOutscaleOAPIImageExportTasks(), - "outscale_server_certificate": datasourceOutscaleOAPIServerCertificate(), - "outscale_server_certificates": datasourceOutscaleOAPIServerCertificates(), - "outscale_snapshot_export_task": dataSourceOutscaleOAPISnapshotExportTask(), - "outscale_snapshot_export_tasks": dataSourceOutscaleOAPISnapshotExportTasks(), - "outscale_ca": dataSourceOutscaleOAPICa(), - "outscale_cas": dataSourceOutscaleOAPICas(), - "outscale_api_access_rule": dataSourceOutscaleOAPIApiAccessRule(), - "outscale_api_access_rules": dataSourceOutscaleOAPIApiAccessRules(), - "outscale_api_access_policy": dataSourceOutscaleOAPIApiAccessPolicy(), - "outscale_public_catalog": dataSourceOutscaleOAPIPublicCatalog(), + "outscale_vm": dataSourceVM(), + "outscale_vms": dataSourceVMS(), + "outscale_security_group": dataSourceSecurityGroup(), + "outscale_security_groups": dataSourceSecurityGroups(), + "outscale_image": dataSourceImage(), + "outscale_images": dataSourceImages(), + "outscale_tag": dataSourceTag(), + "outscale_tags": dataSourceTags(), + "outscale_public_ip": dataSourcePublicIP(), + "outscale_public_ips": dataSourcePublicIPS(), + "outscale_volume": dataSourceVolume(), + "outscale_volumes": dataSourceVolumes(), + "outscale_nat_service": dataSourceNatService(), + "outscale_nat_services": dataSourceNatServices(), + "outscale_keypair": dataSourceKeyPair(), + "outscale_keypairs": dataSourceKeyPairs(), + "outscale_vm_state": dataSourceVMState(), + "outscale_vm_states": dataSourceVMStates(), + "outscale_internet_service": dataSourceInternetService(), + "outscale_internet_services": dataSourceInternetServices(), + "outscale_subnet": dataSourceSubnet(), + "outscale_subnets": dataSourceSubnets(), + "outscale_net": dataSourceVpc(), + "outscale_nets": dataSourceVpcs(), + "outscale_net_attributes": dataSourceVpcAttr(), + "outscale_route_table": dataSourceRouteTable(), + "outscale_route_tables": dataSourceRouteTables(), + "outscale_snapshot": dataSourceSnapshot(), + "outscale_snapshots": dataSourceSnapshots(), + "outscale_net_peering": dataSourceLinPeeringConnection(), + "outscale_net_peerings": dataSourceLinPeeringsConnection(), + "outscale_nics": dataSourceNics(), + "outscale_nic": dataSourceNic(), + "outscale_client_gateway": dataSourceClientGateway(), + "outscale_client_gateways": dataSourceClientGateways(), + "outscale_virtual_gateway": dataSourceVirtualGateway(), + "outscale_virtual_gateways": dataSourceVirtualGateways(), + "outscale_vpn_connection": dataSourceVPNConnection(), + "outscale_vpn_connections": dataSourceVPNConnections(), + "outscale_access_key": dataSourceAccessKey(), + "outscale_access_keys": dataSourceAccessKeys(), + "outscale_dhcp_option": dataSourceDHCPOption(), + "outscale_dhcp_options": dataSourceDHCPOptions(), + "outscale_load_balancer": dataSourceLoadBalancer(), + "outscale_load_balancer_listener_rule": dataSourceLoadBalancerLDRule(), + "outscale_load_balancer_listener_rules": dataSourceLoadBalancerLDRules(), + "outscale_load_balancer_tags": dataSourceLBUTags(), + "outscale_load_balancer_vm_health": dataSourceLoadBalancerVmsHeals(), + "outscale_load_balancers": dataSourceLoadBalancers(), + "outscale_vm_types": dataSourceVMTypes(), + "outscale_net_access_point": dataSourceNetAccessPoint(), + "outscale_net_access_points": dataSourceNetAccessPoints(), + "outscale_flexible_gpu": dataSourceFlexibleGpu(), + "outscale_flexible_gpus": dataSourceFlexibleGpus(), + "outscale_subregions": dataSourceSubregions(), + "outscale_regions": dataSourceRegions(), + "outscale_net_access_point_services": dataSourceNetAccessPointServices(), + "outscale_flexible_gpu_catalog": dataSourceFlexibleGpuCatalog(), + "outscale_product_type": dataSourceProductType(), + "outscale_product_types": dataSourceProductTypes(), + "outscale_quota": dataSourceQuota(), + "outscale_quotas": dataSourceQuotas(), + "outscale_image_export_task": dataSourceImageExportTask(), + "outscale_image_export_tasks": dataSourceImageExportTasks(), + "outscale_server_certificate": dataSourceServerCertificate(), + "outscale_server_certificates": dataSourceServerCertificates(), + "outscale_snapshot_export_task": dataSourceSnapshotExportTask(), + "outscale_snapshot_export_tasks": dataSourceSnapshotExportTasks(), + "outscale_ca": dataSourceCa(), + "outscale_cas": dataSourceCas(), + "outscale_api_access_rule": dataSourceApiAccessRule(), + "outscale_api_access_rules": dataSourceApiAccessRules(), + "outscale_api_access_policy": dataSourceApiAccessPolicy(), + "outscale_public_catalog": dataSourcePublicCatalog(), "outscale_accounts": dataSourceAccounts(), }, diff --git a/outscale/resource_outscale_access_key.go b/outscale/resource_outscale_access_key.go index 9a3e199d7..2ef75c254 100644 --- a/outscale/resource_outscale_access_key.go +++ b/outscale/resource_outscale_access_key.go @@ -13,12 +13,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleAccessKey() *schema.Resource { +func resourceAccessKey() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleAccessKeyCreate, - Read: resourceOutscaleAccessKeyRead, - Update: resourceOutscaleAccessKeyUpdate, - Delete: resourceOutscaleAccessKeyDelete, + Create: resourceAccessKeyCreate, + Read: resourceAccessKeyRead, + Update: resourceAccessKeyUpdate, + Delete: resourceAccessKeyDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -63,8 +63,8 @@ func resourceOutscaleAccessKey() *schema.Resource { } } -func resourceOutscaleAccessKeyCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceAccessKeyCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var err error req := oscgo.CreateAccessKeyRequest{} @@ -97,11 +97,11 @@ func resourceOutscaleAccessKeyCreate(d *schema.ResourceData, meta interface{}) e } } - return resourceOutscaleAccessKeyRead(d, meta) + return resourceAccessKeyRead(d, meta) } -func resourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceAccessKeyRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filter := oscgo.ReadSecretAccessKeyRequest{ AccessKeyId: d.Id(), @@ -148,8 +148,8 @@ func resourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) err return nil } -func resourceOutscaleAccessKeyUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceAccessKeyUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.UpdateAccessKeyRequest{AccessKeyId: d.Id()} if d.HasChange("state") { @@ -177,11 +177,11 @@ func resourceOutscaleAccessKeyUpdate(d *schema.ResourceData, meta interface{}) e if err != nil { return err } - return resourceOutscaleAccessKeyRead(d, meta) + return resourceAccessKeyRead(d, meta) } -func resourceOutscaleAccessKeyDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceAccessKeyDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.DeleteAccessKeyRequest{ AccessKeyId: d.Id(), diff --git a/outscale/resource_outscale_access_key_test.go b/outscale/resource_outscale_access_key_test.go index 868eb4e4b..de3d64721 100644 --- a/outscale/resource_outscale_access_key_test.go +++ b/outscale/resource_outscale_access_key_test.go @@ -12,19 +12,19 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func TestAccOutscaleAccessKey_basic(t *testing.T) { +func TestAccAccessKey_basic(t *testing.T) { t.Parallel() resourceName := "outscale_access_key.outscale_access_key" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleAccessKeyDestroy, + CheckDestroy: testAccCheckAccessKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleAccessKeyBasicConfig, + Config: testAccAccessKeyBasicConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleAccessKeyExists(resourceName), + testAccCheckAccessKeyExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "access_key_id"), resource.TestCheckResourceAttrSet(resourceName, "creation_date"), resource.TestCheckResourceAttrSet(resourceName, "last_modification_date"), @@ -38,7 +38,7 @@ func TestAccOutscaleAccessKey_basic(t *testing.T) { }) } -func TestAccOutscaleAccessKey_updatedToInactivedKey(t *testing.T) { +func TestAccAccessKey_updatedToInactivedKey(t *testing.T) { t.Parallel() resourceName := "outscale_access_key.outscale_access_key" @@ -48,12 +48,12 @@ func TestAccOutscaleAccessKey_updatedToInactivedKey(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleAccessKeyDestroy, + CheckDestroy: testAccCheckAccessKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleAccessKeyUpdatedConfig(state), + Config: testAccAccessKeyUpdatedConfig(state), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleAccessKeyExists(resourceName), + testAccCheckAccessKeyExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "access_key_id"), resource.TestCheckResourceAttrSet(resourceName, "creation_date"), resource.TestCheckResourceAttrSet(resourceName, "last_modification_date"), @@ -64,9 +64,9 @@ func TestAccOutscaleAccessKey_updatedToInactivedKey(t *testing.T) { ), }, { - Config: testAccOutscaleAccessKeyUpdatedConfig(stateUpdated), + Config: testAccAccessKeyUpdatedConfig(stateUpdated), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleAccessKeyExists(resourceName), + testAccCheckAccessKeyExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "access_key_id"), resource.TestCheckResourceAttrSet(resourceName, "creation_date"), resource.TestCheckResourceAttrSet(resourceName, "last_modification_date"), @@ -80,7 +80,7 @@ func TestAccOutscaleAccessKey_updatedToInactivedKey(t *testing.T) { }) } -func TestAccOutscaleAccessKey_updatedToActivedKey(t *testing.T) { +func TestAccAccessKey_updatedToActivedKey(t *testing.T) { resourceName := "outscale_access_key.outscale_access_key" state := "INACTIVE" @@ -89,12 +89,12 @@ func TestAccOutscaleAccessKey_updatedToActivedKey(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleAccessKeyDestroy, + CheckDestroy: testAccCheckAccessKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleAccessKeyUpdatedConfig(state), + Config: testAccAccessKeyUpdatedConfig(state), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleAccessKeyExists(resourceName), + testAccCheckAccessKeyExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "access_key_id"), resource.TestCheckResourceAttrSet(resourceName, "creation_date"), resource.TestCheckResourceAttrSet(resourceName, "last_modification_date"), @@ -105,9 +105,9 @@ func TestAccOutscaleAccessKey_updatedToActivedKey(t *testing.T) { ), }, { - Config: testAccOutscaleAccessKeyUpdatedConfig(stateUpdated), + Config: testAccAccessKeyUpdatedConfig(stateUpdated), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleAccessKeyExists(resourceName), + testAccCheckAccessKeyExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "access_key_id"), resource.TestCheckResourceAttrSet(resourceName, "creation_date"), resource.TestCheckResourceAttrSet(resourceName, "last_modification_date"), @@ -121,7 +121,7 @@ func TestAccOutscaleAccessKey_updatedToActivedKey(t *testing.T) { }) } -func TestAccOutscaleAccessKey_updatedExpirationDate(t *testing.T) { +func TestAccAccessKey_updatedExpirationDate(t *testing.T) { resourceName := "outscale_access_key.outscale_access_key" expirDate := time.Now().AddDate(1, 1, 0).Format("2006-01-02") expirDateUpdated := time.Now().AddDate(1, 4, 0).Format("2006-01-02") @@ -129,12 +129,12 @@ func TestAccOutscaleAccessKey_updatedExpirationDate(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleAccessKeyDestroy, + CheckDestroy: testAccCheckAccessKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleAccessKeyExpirationDateConfig(string(expirDate)), + Config: testAccAccessKeyExpirationDateConfig(string(expirDate)), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleAccessKeyExists(resourceName), + testAccCheckAccessKeyExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "access_key_id"), resource.TestCheckResourceAttrSet(resourceName, "creation_date"), resource.TestCheckResourceAttrSet(resourceName, "expiration_date"), @@ -144,9 +144,9 @@ func TestAccOutscaleAccessKey_updatedExpirationDate(t *testing.T) { ), }, { - Config: testAccOutscaleAccessKeyExpirationDateConfig(string(expirDateUpdated)), + Config: testAccAccessKeyExpirationDateConfig(string(expirDateUpdated)), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleAccessKeyExists(resourceName), + testAccCheckAccessKeyExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "access_key_id"), resource.TestCheckResourceAttrSet(resourceName, "creation_date"), resource.TestCheckResourceAttrSet(resourceName, "expiration_date"), @@ -159,7 +159,7 @@ func TestAccOutscaleAccessKey_updatedExpirationDate(t *testing.T) { }) } -func testAccCheckOutscaleAccessKeyExists(resourceName string) resource.TestCheckFunc { +func testAccCheckAccessKeyExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -169,7 +169,7 @@ func testAccCheckOutscaleAccessKeyExists(resourceName string) resource.TestCheck if rs.Primary.ID == "" { return fmt.Errorf("No Access ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI filter := oscgo.ReadSecretAccessKeyRequest{ AccessKeyId: rs.Primary.ID, @@ -188,8 +188,8 @@ func testAccCheckOutscaleAccessKeyExists(resourceName string) resource.TestCheck } } -func testAccCheckOutscaleAccessKeyDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckAccessKeyDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_access_key" { @@ -213,10 +213,10 @@ func testAccCheckOutscaleAccessKeyDestroy(s *terraform.State) error { return nil } -const testAccOutscaleAccessKeyBasicConfig = ` +const testAccAccessKeyBasicConfig = ` resource "outscale_access_key" "outscale_access_key" {}` -func testAccOutscaleAccessKeyUpdatedConfig(state string) string { +func testAccAccessKeyUpdatedConfig(state string) string { return fmt.Sprintf(` resource "outscale_access_key" "outscale_access_key" { state = "%s" @@ -224,7 +224,7 @@ func testAccOutscaleAccessKeyUpdatedConfig(state string) string { `, state) } -func testAccOutscaleAccessKeyExpirationDateConfig(expirDate string) string { +func testAccAccessKeyExpirationDateConfig(expirDate string) string { return fmt.Sprintf(` resource "outscale_access_key" "outscale_access_key" { expiration_date = "%s" diff --git a/outscale/resource_outscale_api_access_policy.go b/outscale/resource_outscale_api_access_policy.go index 2bcc85394..d186a8a27 100644 --- a/outscale/resource_outscale_api_access_policy.go +++ b/outscale/resource_outscale_api_access_policy.go @@ -11,12 +11,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPIApiAccessPolicy() *schema.Resource { +func resourceApiAccessPolicy() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIApiAccessPolicyCreate, - Read: resourceOutscaleOAPIApiAccessPolicyRead, - Update: resourceOutscaleOAPIApiAccessPolicyUpdate, - Delete: resourceOutscaleOAPIApiAccessPolicyDelete, + Create: resourceApiAccessPolicyCreate, + Read: resourceApiAccessPolicyRead, + Update: resourceApiAccessPolicyUpdate, + Delete: resourceApiAccessPolicyDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -37,8 +37,8 @@ func resourceOutscaleOAPIApiAccessPolicy() *schema.Resource { } } -func resourceOutscaleOAPIApiAccessPolicyCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceApiAccessPolicyCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI maxAcc := d.Get("max_access_key_expiration_seconds") trustEnv := d.Get("require_trusted_env") @@ -63,11 +63,11 @@ func resourceOutscaleOAPIApiAccessPolicyCreate(d *schema.ResourceData, meta inte if err != nil { return err } - return resourceOutscaleOAPIApiAccessPolicyRead(d, meta) + return resourceApiAccessPolicyRead(d, meta) } -func resourceOutscaleOAPIApiAccessPolicyRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceApiAccessPolicyRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadApiAccessPolicyRequest{} @@ -102,8 +102,8 @@ func resourceOutscaleOAPIApiAccessPolicyRead(d *schema.ResourceData, meta interf return nil } -func resourceOutscaleOAPIApiAccessPolicyUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceApiAccessPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI _, maxAcc := d.GetChange("max_access_key_expiration_seconds") _, trustEnv := d.GetChange("require_trusted_env") @@ -128,10 +128,10 @@ func resourceOutscaleOAPIApiAccessPolicyUpdate(d *schema.ResourceData, meta inte if err != nil { return err } - return resourceOutscaleOAPIApiAccessPolicyRead(d, meta) + return resourceApiAccessPolicyRead(d, meta) } -func resourceOutscaleOAPIApiAccessPolicyDelete(d *schema.ResourceData, _ interface{}) error { +func resourceApiAccessPolicyDelete(d *schema.ResourceData, _ interface{}) error { d.SetId("") return nil } diff --git a/outscale/resource_outscale_api_access_rule.go b/outscale/resource_outscale_api_access_rule.go index cf67aa460..48d95446f 100644 --- a/outscale/resource_outscale_api_access_rule.go +++ b/outscale/resource_outscale_api_access_rule.go @@ -12,12 +12,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPIApiAccessRule() *schema.Resource { +func resourceApiAccessRule() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIApiAccessRuleCreate, - Read: resourceOutscaleOAPIApiAccessRuleRead, - Update: resourceOutscaleOAPIApiAccessRuleUpdate, - Delete: resourceOutscaleOAPIApiAccessRuleDelete, + Create: resourceApiAccessRuleCreate, + Read: resourceApiAccessRuleRead, + Update: resourceApiAccessRuleUpdate, + Delete: resourceApiAccessRuleDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -53,8 +53,8 @@ func resourceOutscaleOAPIApiAccessRule() *schema.Resource { } } -func resourceOutscaleOAPIApiAccessRuleCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceApiAccessRuleCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var checkParam = false req := oscgo.CreateApiAccessRuleRequest{} @@ -92,11 +92,11 @@ func resourceOutscaleOAPIApiAccessRuleCreate(d *schema.ResourceData, meta interf } d.SetId(cast.ToString(resp.ApiAccessRule.GetApiAccessRuleId())) - return resourceOutscaleOAPIApiAccessRuleRead(d, meta) + return resourceApiAccessRuleRead(d, meta) } -func resourceOutscaleOAPIApiAccessRuleRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceApiAccessRuleRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadApiAccessRulesRequest{ Filters: &oscgo.FiltersApiAccessRule{ApiAccessRuleIds: &[]string{d.Id()}}, @@ -154,8 +154,8 @@ func resourceOutscaleOAPIApiAccessRuleRead(d *schema.ResourceData, meta interfac return nil } -func resourceOutscaleOAPIApiAccessRuleUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceApiAccessRuleUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI accRid, isIdOk := d.GetOk("api_access_rule_id") if !isIdOk { @@ -198,11 +198,11 @@ func resourceOutscaleOAPIApiAccessRuleUpdate(d *schema.ResourceData, meta interf if err != nil { return err } - return resourceOutscaleOAPIApiAccessRuleRead(d, meta) + return resourceApiAccessRuleRead(d, meta) } -func resourceOutscaleOAPIApiAccessRuleDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceApiAccessRuleDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.DeleteApiAccessRuleRequest{ ApiAccessRuleId: d.Id(), diff --git a/outscale/resource_outscale_api_access_rule_test.go b/outscale/resource_outscale_api_access_rule_test.go index d9e70deef..fb76b5138 100644 --- a/outscale/resource_outscale_api_access_rule_test.go +++ b/outscale/resource_outscale_api_access_rule_test.go @@ -13,33 +13,33 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIApiAccessRule_basic(t *testing.T) { +func TestAccApiAccessRule_basic(t *testing.T) { t.Parallel() resourceName := "outscale_api_access_rule.rule_test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleApiAccessRuleDestroy, + CheckDestroy: testAccCheckApiAccessRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIApiAccessRuleConfig(utils.TestCaPem), + Config: testAccApiAccessRuleConfig(utils.TestCaPem), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleApiAccessRuleExists(resourceName), + testAccCheckApiAccessRuleExists(resourceName), ), }, }, }) } -func testAccCheckOutscaleApiAccessRuleExists(n string) resource.TestCheckFunc { +func testAccCheckApiAccessRuleExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI if rs.Primary.ID == "" { return fmt.Errorf("No id is set") @@ -77,8 +77,8 @@ func testAccCheckOutscaleApiAccessRuleExists(n string) resource.TestCheckFunc { } } -func testAccCheckOutscaleApiAccessRuleDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckApiAccessRuleDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_api_access_rule" { @@ -116,7 +116,7 @@ func testAccCheckOutscaleApiAccessRuleDestroy(s *terraform.State) error { return nil } -func testAccOutscaleOAPIApiAccessRuleConfig(ca_pem string) string { +func testAccApiAccessRuleConfig(ca_pem string) string { return fmt.Sprintf(` resource "outscale_ca" "ca_rule" { ca_pem = %[1]q diff --git a/outscale/resource_outscale_ca.go b/outscale/resource_outscale_ca.go index b4ec04e5f..8fad5e8f0 100644 --- a/outscale/resource_outscale_ca.go +++ b/outscale/resource_outscale_ca.go @@ -13,12 +13,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPICa() *schema.Resource { +func resourceCa() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPICaCreate, - Read: resourceOutscaleOAPICaRead, - Update: resourceOutscaleOAPICaUpdate, - Delete: resourceOutscaleOAPICaDelete, + Create: resourceCaCreate, + Read: resourceCaRead, + Update: resourceCaUpdate, + Delete: resourceCaDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -48,8 +48,8 @@ func resourceOutscaleOAPICa() *schema.Resource { } } -func resourceOutscaleOAPICaCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceCaCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI if _, ok := d.GetOk("ca_pem"); ok == false { return fmt.Errorf("[DEBUG] Error 'ca_pem' field is require for certificate authority creation") @@ -77,11 +77,11 @@ func resourceOutscaleOAPICaCreate(d *schema.ResourceData, meta interface{}) erro } d.SetId(cast.ToString(resp.Ca.GetCaId())) - return resourceOutscaleOAPICaRead(d, meta) + return resourceCaRead(d, meta) } -func resourceOutscaleOAPICaRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceCaRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadCasRequest{ Filters: &oscgo.FiltersCa{CaIds: &[]string{d.Id()}}, @@ -123,8 +123,8 @@ func resourceOutscaleOAPICaRead(d *schema.ResourceData, meta interface{}) error return nil } -func resourceOutscaleOAPICaUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceCaUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.UpdateCaRequest{ CaId: d.Get("ca_id").(string), @@ -146,11 +146,11 @@ func resourceOutscaleOAPICaUpdate(d *schema.ResourceData, meta interface{}) erro if err != nil { return err } - return resourceOutscaleOAPICaRead(d, meta) + return resourceCaRead(d, meta) } -func resourceOutscaleOAPICaDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceCaDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.DeleteCaRequest{ CaId: d.Get("ca_id").(string), diff --git a/outscale/resource_outscale_ca_test.go b/outscale/resource_outscale_ca_test.go index 18e1bbf6f..fc31212a0 100644 --- a/outscale/resource_outscale_ca_test.go +++ b/outscale/resource_outscale_ca_test.go @@ -13,39 +13,39 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPICa_basic(t *testing.T) { +func TestAccCa_basic(t *testing.T) { t.Parallel() resourceName := "outscale_ca.ca_test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleCaDestroy, + CheckDestroy: testAccCheckCaDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPICaConfig(utils.TestCaPem), + Config: testAccCaConfig(utils.TestCaPem), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleCaExists(resourceName), + testAccCheckCaExists(resourceName), ), }, { - Config: testAccOutscaleOAPICaConfigUpdateDescription(utils.TestCaPem), + Config: testAccCaConfigUpdateDescription(utils.TestCaPem), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleCaExists(resourceName), + testAccCheckCaExists(resourceName), ), }, }, }) } -func testAccCheckOutscaleCaExists(n string) resource.TestCheckFunc { +func testAccCheckCaExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI if rs.Primary.ID == "" { return fmt.Errorf("No id is set") @@ -81,8 +81,8 @@ func testAccCheckOutscaleCaExists(n string) resource.TestCheckFunc { } } -func testAccCheckOutscaleCaDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckCaDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_ca" { @@ -121,7 +121,7 @@ func testAccCheckOutscaleCaDestroy(s *terraform.State) error { return nil } -func testAccOutscaleOAPICaConfig(ca_pem string) string { +func testAccCaConfig(ca_pem string) string { return fmt.Sprintf(` resource "outscale_ca" "ca_test" { ca_pem = %[1]q @@ -130,7 +130,7 @@ resource "outscale_ca" "ca_test" { `, ca_pem) } -func testAccOutscaleOAPICaConfigUpdateDescription(ca_pem string) string { +func testAccCaConfigUpdateDescription(ca_pem string) string { return fmt.Sprintf(` resource "outscale_ca" "ca_test" { ca_pem = %[1]q diff --git a/outscale/resource_outscale_client_gateway.go b/outscale/resource_outscale_client_gateway.go index 84b91a930..f6a3bdc71 100644 --- a/outscale/resource_outscale_client_gateway.go +++ b/outscale/resource_outscale_client_gateway.go @@ -14,12 +14,12 @@ import ( oscgo "github.com/outscale/osc-sdk-go/v2" ) -func resourceOutscaleClientGateway() *schema.Resource { +func resourceClientGateway() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleClientGatewayCreate, - Read: resourceOutscaleClientGatewayRead, - Update: resourceOutscaleClientGatewayUpdate, - Delete: resourceOutscaleClientGatewayDelete, + Create: resourceClientGatewayCreate, + Read: resourceClientGatewayRead, + Update: resourceClientGatewayUpdate, + Delete: resourceClientGatewayDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -48,7 +48,7 @@ func resourceOutscaleClientGateway() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "request_id": { Type: schema.TypeString, Computed: true, @@ -57,8 +57,8 @@ func resourceOutscaleClientGateway() *schema.Resource { } } -func resourceOutscaleClientGatewayCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceClientGatewayCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.CreateClientGatewayRequest{ BgpAsn: cast.ToInt32(d.Get("bgp_asn")), @@ -89,11 +89,11 @@ func resourceOutscaleClientGatewayCreate(d *schema.ResourceData, meta interface{ d.SetId(*resp.GetClientGateway().ClientGatewayId) - return resourceOutscaleClientGatewayRead(d, meta) + return resourceClientGatewayRead(d, meta) } -func resourceOutscaleClientGatewayRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceClientGatewayRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI clientGatewayID := d.Id() @@ -129,30 +129,30 @@ func resourceOutscaleClientGatewayRead(d *schema.ResourceData, meta interface{}) if err := d.Set("state", clientGateway.GetState()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(clientGateway.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(clientGateway.GetTags())); err != nil { return err } return nil } -func resourceOutscaleClientGatewayUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceClientGatewayUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOutscaleClientGatewayRead(d, meta) + return resourceClientGatewayRead(d, meta) } -func resourceOutscaleClientGatewayDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceClientGatewayDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI gatewayID := d.Id() req := oscgo.DeleteClientGatewayRequest{ diff --git a/outscale/resource_outscale_client_gateway_test.go b/outscale/resource_outscale_client_gateway_test.go index c1b7db2a6..db2e641e9 100644 --- a/outscale/resource_outscale_client_gateway_test.go +++ b/outscale/resource_outscale_client_gateway_test.go @@ -14,7 +14,7 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func TestAccOutscaleClientGateway_basic(t *testing.T) { +func TestAccClientGateway_basic(t *testing.T) { t.Parallel() resourceName := "outscale_client_gateway.foo" rBgpAsn := acctest.RandIntRange(64512, 65534) @@ -52,7 +52,7 @@ func TestAccOutscaleClientGateway_basic(t *testing.T) { }) } -func TestAccOutscaleClientGateway_withTags(t *testing.T) { +func TestAccClientGateway_withTags(t *testing.T) { resourceName := "outscale_client_gateway.foo" value := fmt.Sprintf("testacc-%s", acctest.RandString(5)) valueUpdated := fmt.Sprintf("testacc-%s", acctest.RandString(5)) @@ -92,7 +92,7 @@ func testAccCheckClientGatewayExists(resourceName string) resource.TestCheckFunc return fmt.Errorf("Not found: %s", resourceName) } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI if rs.Primary.ID == "" { return fmt.Errorf("No Client Gateway ID is set") @@ -121,7 +121,7 @@ func testAccCheckClientGatewayExists(resourceName string) resource.TestCheckFunc } func testAccCheckClientGatewayDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_client_gateway" { diff --git a/outscale/resource_outscale_dhcp_option.go b/outscale/resource_outscale_dhcp_option.go index bb600acbf..70fc6789e 100644 --- a/outscale/resource_outscale_dhcp_option.go +++ b/outscale/resource_outscale_dhcp_option.go @@ -12,12 +12,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleDHCPOption() *schema.Resource { +func resourceDHCPOption() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleDHCPOptionCreate, - Read: resourceOutscaleDHCPOptionRead, - Update: resourceOutscaleDHCPOptionUpdate, - Delete: resourceOutscaleDHCPOptionDelete, + Create: resourceDHCPOptionCreate, + Read: resourceDHCPOptionRead, + Update: resourceDHCPOptionUpdate, + Delete: resourceDHCPOptionDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -63,7 +63,7 @@ func resourceOutscaleDHCPOption() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "request_id": { Type: schema.TypeString, Computed: true, @@ -72,8 +72,8 @@ func resourceOutscaleDHCPOption() *schema.Resource { } } -func resourceOutscaleDHCPOptionCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceDHCPOptionCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI createOpts := oscgo.CreateDhcpOptionsRequest{} @@ -112,11 +112,11 @@ func resourceOutscaleDHCPOptionCreate(d *schema.ResourceData, meta interface{}) d.SetId(dhcp.GetDhcpOptionsSetId()) - return resourceOutscaleDHCPOptionRead(d, meta) + return resourceDHCPOptionRead(d, meta) } -func resourceOutscaleDHCPOptionRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceDHCPOptionRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI dhcpID := d.Id() _, resp, err := readDhcpOption(conn, dhcpID) @@ -149,19 +149,19 @@ func resourceOutscaleDHCPOptionRead(d *schema.ResourceData, meta interface{}) er if err := d.Set("dhcp_options_set_id", dhcp.GetDhcpOptionsSetId()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(dhcp.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(dhcp.GetTags())); err != nil { return err } return nil } -func resourceOutscaleDHCPOptionUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceDHCPOptionUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } @@ -169,11 +169,11 @@ func resourceOutscaleDHCPOptionUpdate(d *schema.ResourceData, meta interface{}) d.Partial(false) - return resourceOutscaleDHCPOptionRead(d, meta) + return resourceDHCPOptionRead(d, meta) } -func resourceOutscaleDHCPOptionDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceDHCPOptionDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI dhcpID := d.Id() diff --git a/outscale/resource_outscale_dhcp_option_test.go b/outscale/resource_outscale_dhcp_option_test.go index 3ecd38822..df5d987e8 100644 --- a/outscale/resource_outscale_dhcp_option_test.go +++ b/outscale/resource_outscale_dhcp_option_test.go @@ -16,7 +16,7 @@ import ( oscgo "github.com/outscale/osc-sdk-go/v2" ) -func TestAccOutscaleOAPIDhcpOptional_basic(t *testing.T) { +func TestAccDhcpOptional_basic(t *testing.T) { t.Parallel() resourceName := "outscale_dhcp_option.foo" value := fmt.Sprintf("test-acc-value-%s", acctest.RandString(5)) @@ -26,12 +26,12 @@ func TestAccOutscaleOAPIDhcpOptional_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: resourceName, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIDHCPOptionDestroy, + CheckDestroy: testAccCheckDHCPOptionDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIDHCPOptionalBasicConfig(value, false, false), + Config: testAccDHCPOptionalBasicConfig(value, false, false), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleDHCPOptionExists(resourceName), + testAccCheckDHCPOptionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "domain_name"), resource.TestCheckResourceAttrSet(resourceName, "domain_name_servers.#"), //resource.TestCheckResourceAttrSet(resourceName, "tags.#"), @@ -44,9 +44,9 @@ func TestAccOutscaleOAPIDhcpOptional_basic(t *testing.T) { ), }, { - Config: testAccOAPIDHCPOptionalBasicConfig(updateValue, true, true), + Config: testAccDHCPOptionalBasicConfig(updateValue, true, true), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleDHCPOptionExists(resourceName), + testAccCheckDHCPOptionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "domain_name"), resource.TestCheckResourceAttrSet(resourceName, "domain_name_servers.#"), resource.TestCheckResourceAttrSet(resourceName, "log_servers.#"), @@ -66,7 +66,7 @@ func TestAccOutscaleOAPIDhcpOptional_basic(t *testing.T) { }) } -func TestAccOutscaleOAPIDhcpOptional_withEmptyAttrs(t *testing.T) { +func TestAccDhcpOptional_withEmptyAttrs(t *testing.T) { resourceName := "outscale_dhcp_option.foo" value := fmt.Sprintf("test-acc-value-%s", acctest.RandString(5)) @@ -79,12 +79,12 @@ func TestAccOutscaleOAPIDhcpOptional_withEmptyAttrs(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: resourceName, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIDHCPOptionDestroy, + CheckDestroy: testAccCheckDHCPOptionDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIDHCPOptionalBasicConfigWithEmptyAttrs(ntpServers, value), + Config: testAccDHCPOptionalBasicConfigWithEmptyAttrs(ntpServers, value), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleDHCPOptionExists(resourceName), + testAccCheckDHCPOptionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "ntp_servers.#"), //resource.TestCheckResourceAttrSet(resourceName, "tags.#"), @@ -97,9 +97,9 @@ func TestAccOutscaleOAPIDhcpOptional_withEmptyAttrs(t *testing.T) { ), }, { - Config: testAccOAPIDHCPOptionalBasicConfigWithEmptyAttrs(ntpServersUpdated, updateValue), + Config: testAccDHCPOptionalBasicConfigWithEmptyAttrs(ntpServersUpdated, updateValue), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleDHCPOptionExists(resourceName), + testAccCheckDHCPOptionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "ntp_servers.#"), //resource.TestCheckResourceAttrSet(resourceName, "tags.#"), @@ -115,7 +115,7 @@ func TestAccOutscaleOAPIDhcpOptional_withEmptyAttrs(t *testing.T) { }) } -func TestAccOutscaleOAPIDhcpOptional_withNet(t *testing.T) { +func TestAccDhcpOptional_withNet(t *testing.T) { t.Parallel() resourceName := "outscale_dhcp_option.outscale_dhcp_option" @@ -132,12 +132,12 @@ func TestAccOutscaleOAPIDhcpOptional_withNet(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: resourceName, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIDHCPOptionDestroy, + CheckDestroy: testAccCheckDHCPOptionDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIDHCPOptionalWithNet(domainName, domainServers, tags), + Config: testAccDHCPOptionalWithNet(domainName, domainServers, tags), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleDHCPOptionExists(resourceName), + testAccCheckDHCPOptionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "domain_name"), resource.TestCheckResourceAttrSet(resourceName, "domain_name_servers.#"), resource.TestCheckResourceAttrSet(resourceName, "tags.#"), @@ -152,9 +152,9 @@ func TestAccOutscaleOAPIDhcpOptional_withNet(t *testing.T) { ), }, { - Config: testAccOAPIDHCPOptionalWithNet(domainNameUpdated, []string{}, nil), + Config: testAccDHCPOptionalWithNet(domainNameUpdated, []string{}, nil), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleDHCPOptionExists(resourceName), + testAccCheckDHCPOptionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "domain_name"), resource.TestCheckResourceAttr(resourceName, "domain_name", domainNameUpdated), ), @@ -163,21 +163,21 @@ func TestAccOutscaleOAPIDhcpOptional_withNet(t *testing.T) { }) } -func TestAccOutscaleDHCPOption_importBasic(t *testing.T) { +func TestAccDHCPOption_importBasic(t *testing.T) { resourceName := "outscale_dhcp_option.foo" value := fmt.Sprintf("test-acc-value-%s", acctest.RandString(5)) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIDHCPOptionDestroy, + CheckDestroy: testAccCheckDHCPOptionDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIDHCPOptionalBasicConfig(value, true, true), + Config: testAccDHCPOptionalBasicConfig(value, true, true), }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOutscaleInternetServiceLinkImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckInternetServiceLinkImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id"}, @@ -186,7 +186,7 @@ func TestAccOutscaleDHCPOption_importBasic(t *testing.T) { }) } -func testAccCheckOutscaleDHCPOptionImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckDHCPOptionImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -196,14 +196,14 @@ func testAccCheckOutscaleDHCPOptionImportStateIDFunc(resourceName string) resour } } -func testAccCheckOutscaleDHCPOptionExists(n string) resource.TestCheckFunc { +func testAccCheckDHCPOptionExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI if rs.Primary.ID == "" { return fmt.Errorf("No DHCP Option id is set") @@ -227,8 +227,8 @@ func testAccCheckOutscaleDHCPOptionExists(n string) resource.TestCheckFunc { } } -func testAccCheckOAPIDHCPOptionDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckDHCPOptionDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_dhcp_option" { @@ -264,7 +264,7 @@ func testAccCheckOAPIDHCPOptionDestroy(s *terraform.State) error { return nil } -func testAccOAPIDHCPOptionalBasicConfig(value string, ntpServers bool, logServers bool) string { +func testAccDHCPOptionalBasicConfig(value string, ntpServers bool, logServers bool) string { var ntp string var log string @@ -296,7 +296,7 @@ func testAccOAPIDHCPOptionalBasicConfig(value string, ntpServers bool, logServer return tf } -func testAccOAPIDHCPOptionalBasicConfigWithEmptyAttrs(ntpServers []string, value string) string { +func testAccDHCPOptionalBasicConfigWithEmptyAttrs(ntpServers []string, value string) string { return fmt.Sprintf(` resource "outscale_dhcp_option" "foo" { ntp_servers = %s @@ -309,7 +309,7 @@ func testAccOAPIDHCPOptionalBasicConfigWithEmptyAttrs(ntpServers []string, value `, strings.ReplaceAll(fmt.Sprintf("%+q", ntpServers), " ", ","), value) } -func testAccOAPIDHCPOptionalWithNet(domainName string, domainServers []string, tags *oscgo.Tag) string { +func testAccDHCPOptionalWithNet(domainName string, domainServers []string, tags *oscgo.Tag) string { var servers, dhcpTags string if len(domainServers) > 0 { diff --git a/outscale/resource_outscale_flexible_gpu.go b/outscale/resource_outscale_flexible_gpu.go index 0d2fcfdcb..332f6bbac 100644 --- a/outscale/resource_outscale_flexible_gpu.go +++ b/outscale/resource_outscale_flexible_gpu.go @@ -11,12 +11,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPIFlexibleGpu() *schema.Resource { +func resourceFlexibleGpu() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIFlexibleGpuCreate, - Read: resourceOutscaleOAPIFlexibleGpuRead, - Delete: resourceOutscaleOAPIFlexibleGpuDelete, - Update: resourceOutscaleOAPIFlexibleGpuUpdate, + Create: resourceFlexibleGpuCreate, + Read: resourceFlexibleGpuRead, + Delete: resourceFlexibleGpuDelete, + Update: resourceFlexibleGpuUpdate, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -64,8 +64,8 @@ func resourceOutscaleOAPIFlexibleGpu() *schema.Resource { } } -func resourceOutscaleOAPIFlexibleGpuCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceFlexibleGpuCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := &oscgo.CreateFlexibleGpuRequest{} @@ -102,11 +102,11 @@ func resourceOutscaleOAPIFlexibleGpuCreate(d *schema.ResourceData, meta interfac d.SetId(resp.FlexibleGpu.GetFlexibleGpuId()) - return resourceOutscaleOAPIFlexibleGpuRead(d, meta) + return resourceFlexibleGpuRead(d, meta) } -func resourceOutscaleOAPIFlexibleGpuRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceFlexibleGpuRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI napid := d.Id() @@ -167,8 +167,8 @@ func resourceOutscaleOAPIFlexibleGpuRead(d *schema.ResourceData, meta interface{ return nil } -func resourceOutscaleOAPIFlexibleGpuUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceFlexibleGpuUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI v := d.Get("delete_on_vm_deletion") req := &oscgo.UpdateFlexibleGpuRequest{ @@ -191,12 +191,12 @@ func resourceOutscaleOAPIFlexibleGpuUpdate(d *schema.ResourceData, meta interfac if err != nil { return err } - return resourceOutscaleOAPIFlexibleGpuRead(d, meta) + return resourceFlexibleGpuRead(d, meta) } -func resourceOutscaleOAPIFlexibleGpuDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceFlexibleGpuDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := &oscgo.DeleteFlexibleGpuRequest{ FlexibleGpuId: d.Id(), diff --git a/outscale/resource_outscale_flexible_gpu_link.go b/outscale/resource_outscale_flexible_gpu_link.go index 4a6a11342..151a764d7 100644 --- a/outscale/resource_outscale_flexible_gpu_link.go +++ b/outscale/resource_outscale_flexible_gpu_link.go @@ -12,11 +12,11 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPIFlexibleGpuLink() *schema.Resource { +func resourceFlexibleGpuLink() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIFlexibleGpuLinkCreate, - Read: resourceOutscaleOAPIFlexibleGpuLinkRead, - Delete: resourceOutscaleOAPIFlexibleGpuLinkDelete, + Create: resourceFlexibleGpuLinkCreate, + Read: resourceFlexibleGpuLinkRead, + Delete: resourceFlexibleGpuLinkDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -40,8 +40,8 @@ func resourceOutscaleOAPIFlexibleGpuLink() *schema.Resource { } } -func resourceOutscaleOAPIFlexibleGpuLinkCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceFlexibleGpuLinkCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI flexGpuID := d.Get("flexible_gpu_id").(string) vmId := d.Get("vm_id").(string) @@ -103,11 +103,11 @@ func resourceOutscaleOAPIFlexibleGpuLinkCreate(d *schema.ResourceData, meta inte return fmt.Errorf("Unable to change ShutdownBehavior: %s\n", err) } - return resourceOutscaleOAPIFlexibleGpuLinkRead(d, meta) + return resourceFlexibleGpuLinkRead(d, meta) } -func resourceOutscaleOAPIFlexibleGpuLinkRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceFlexibleGpuLinkRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI flexGpuID := d.Get("flexible_gpu_id").(string) if flexGpuID == "" { @@ -152,8 +152,8 @@ func resourceOutscaleOAPIFlexibleGpuLinkRead(d *schema.ResourceData, meta interf return nil } -func resourceOutscaleOAPIFlexibleGpuLinkDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceFlexibleGpuLinkDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI flexGpuID := d.Get("flexible_gpu_id").(string) vmId := d.Get("vm_id").(string) diff --git a/outscale/resource_outscale_flexible_gpu_link_test.go b/outscale/resource_outscale_flexible_gpu_link_test.go index f944a6f8a..0a1c42759 100644 --- a/outscale/resource_outscale_flexible_gpu_link_test.go +++ b/outscale/resource_outscale_flexible_gpu_link_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIFlexibleGpuLink_basic(t *testing.T) { +func TestAccFlexibleGpuLink_basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") region := fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) @@ -19,13 +19,13 @@ func TestAccOutscaleOAPIFlexibleGpuLink_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIFlexibleGpuLinkConfig(omi, "tinav3.c1r1p2", region), + Config: testAccFlexibleGpuLinkConfig(omi, "tinav3.c1r1p2", region), }, }, }) } -func testAccOutscaleOAPIFlexibleGpuLinkConfig(omi, vmType, region string) string { +func testAccFlexibleGpuLinkConfig(omi, vmType, region string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%s" diff --git a/outscale/resource_outscale_flexible_gpu_test.go b/outscale/resource_outscale_flexible_gpu_test.go index fab10fb7b..2c3577b24 100644 --- a/outscale/resource_outscale_flexible_gpu_test.go +++ b/outscale/resource_outscale_flexible_gpu_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPIFlexibleGpu_basic(t *testing.T) { +func TestAccFlexibleGpu_basic(t *testing.T) { t.Parallel() region := fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) @@ -19,13 +19,13 @@ func TestAccOutscaleOAPIFlexibleGpu_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIFlexibleGpuConfig(region), + Config: testAccFlexibleGpuConfig(region), }, }, }) } -func testAccOutscaleOAPIFlexibleGpuConfig(region string) string { +func testAccFlexibleGpuConfig(region string) string { return fmt.Sprintf(` resource "outscale_flexible_gpu" "fGPU-1" { model_name = "nvidia-k2" diff --git a/outscale/resource_outscale_image.go b/outscale/resource_outscale_image.go index 4d0c1b68a..21aad5abb 100644 --- a/outscale/resource_outscale_image.go +++ b/outscale/resource_outscale_image.go @@ -14,22 +14,22 @@ import ( ) const ( - // OutscaleImageRetryTimeout ... - OutscaleImageRetryTimeout = 40 * time.Minute - // OutscaleImageDeleteRetryTimeout ... - OutscaleImageDeleteRetryTimeout = 90 * time.Minute - // OutscaleImageRetryDelay ... - OutscaleImageRetryDelay = 20 * time.Second - // OutscaleImageRetryMinTimeout ... - OutscaleImageRetryMinTimeout = 3 * time.Second + // ImageRetryTimeout ... + ImageRetryTimeout = 40 * time.Minute + // ImageDeleteRetryTimeout ... + ImageDeleteRetryTimeout = 90 * time.Minute + // ImageRetryDelay ... + ImageRetryDelay = 20 * time.Second + // ImageRetryMinTimeout ... + ImageRetryMinTimeout = 3 * time.Second ) -func resourceOutscaleOAPIImage() *schema.Resource { +func resourceImage() *schema.Resource { return &schema.Resource{ - Create: resourceOAPIImageCreate, - Read: resourceOAPIImageRead, - Update: resourceOAPIImageUpdate, - Delete: resourceOAPIImageDelete, + Create: resourceImageCreate, + Read: resourceImageRead, + Update: resourceImageUpdate, + Delete: resourceImageDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -210,7 +210,7 @@ func resourceOutscaleOAPIImage() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "vm_id": { Type: schema.TypeString, Optional: true, @@ -220,8 +220,8 @@ func resourceOutscaleOAPIImage() *schema.Resource { } } -func resourceOAPIImageCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI imageRequest := oscgo.CreateImageRequest{} if v, ok := d.GetOk("image_name"); ok { @@ -236,7 +236,7 @@ func resourceOAPIImageCreate(d *schema.ResourceData, meta interface{}) error { imageRequest.SetDescription(v.(string)) } if blocks, ok := d.GetOk("block_device_mappings"); ok { - blockDevices := expandOmiBlockDeviceOApiMappings(blocks.([]interface{})) + blockDevices := expandOmiBlockDeviceMappings(blocks.([]interface{})) imageRequest.SetBlockDeviceMappings(blockDevices) } if v, ok := d.GetOk("no_reboot"); ok { @@ -290,7 +290,7 @@ func resourceOAPIImageCreate(d *schema.ResourceData, meta interface{}) error { stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: []string{"available"}, - Refresh: ImageOAPIStateRefreshFunc(conn, req, "failed"), + Refresh: ImageStateRefreshFunc(conn, req, "failed"), Timeout: 10 * time.Minute, MinTimeout: 30 * time.Second, Delay: 1 * time.Minute, @@ -310,11 +310,11 @@ func resourceOAPIImageCreate(d *schema.ResourceData, meta interface{}) error { d.SetId(*image.ImageId) - return resourceOAPIImageRead(d, meta) + return resourceImageRead(d, meta) } -func resourceOAPIImageRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() req := oscgo.ReadImagesRequest{ @@ -382,19 +382,19 @@ func resourceOAPIImageRead(d *schema.ResourceData, meta interface{}) error { if err := set("state", image.State); err != nil { return err } - if err := set("block_device_mappings", omiOAPIBlockDeviceMappings(image.GetBlockDeviceMappings())); err != nil { + if err := set("block_device_mappings", omiBlockDeviceMappings(image.GetBlockDeviceMappings())); err != nil { return err } if err := set("product_codes", image.ProductCodes); err != nil { return err } - if err := set("state_comment", omiOAPIStateReason(image.StateComment)); err != nil { + if err := set("state_comment", omiStateReason(image.StateComment)); err != nil { return err } if err := set("permissions_to_launch", setResourcePermissions(*image.PermissionsToLaunch)); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(image.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(image.GetTags())); err != nil { fmt.Printf("[WARN] ERROR TAGS PROBLEME (%s)", err) } @@ -411,22 +411,22 @@ func setResourcePermissions(por oscgo.PermissionsOnResource) []map[string]interf } } -func resourceOAPIImageUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOAPIImageRead(d, meta) + return resourceImageRead(d, meta) } -func resourceOAPIImageDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var err error err = resource.Retry(120*time.Second, func() *resource.RetryError { @@ -443,7 +443,7 @@ func resourceOAPIImageDelete(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error deleting the image %s", err) } - if err := resourceOutscaleOAPIImageWaitForDestroy(d.Id(), conn); err != nil { + if err := resourceImageWaitForDestroy(d.Id(), conn); err != nil { return err } @@ -451,7 +451,7 @@ func resourceOAPIImageDelete(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceOutscaleOAPIImageWaitForDestroy(id string, conn *oscgo.APIClient) error { +func resourceImageWaitForDestroy(id string, conn *oscgo.APIClient) error { log.Printf("[INFO] Waiting for OMI %s to be deleted...", id) filterReq := oscgo.ReadImagesRequest{ @@ -461,7 +461,7 @@ func resourceOutscaleOAPIImageWaitForDestroy(id string, conn *oscgo.APIClient) e stateConf := &resource.StateChangeConf{ Pending: []string{"available", "pending"}, Target: []string{"destroyed", "failed"}, - Refresh: ImageOAPIStateRefreshFunc(conn, filterReq, "failed"), + Refresh: ImageStateRefreshFunc(conn, filterReq, "failed"), Timeout: 10 * time.Minute, MinTimeout: 30 * time.Second, Delay: 1 * time.Minute, @@ -474,8 +474,8 @@ func resourceOutscaleOAPIImageWaitForDestroy(id string, conn *oscgo.APIClient) e return nil } -// ImageOAPIStateRefreshFunc ... -func ImageOAPIStateRefreshFunc(client *oscgo.APIClient, req oscgo.ReadImagesRequest, failState string) resource.StateRefreshFunc { +// ImageStateRefreshFunc ... +func ImageStateRefreshFunc(client *oscgo.APIClient, req oscgo.ReadImagesRequest, failState string) resource.StateRefreshFunc { return func() (interface{}, string, error) { var resp oscgo.ReadImagesResponse var err error @@ -511,7 +511,7 @@ func ImageOAPIStateRefreshFunc(client *oscgo.APIClient, req oscgo.ReadImagesRequ } // Returns a set of block device mappings. -func omiOAPIBlockDeviceMappings(m []oscgo.BlockDeviceMappingImage) []map[string]interface{} { +func omiBlockDeviceMappings(m []oscgo.BlockDeviceMappingImage) []map[string]interface{} { blockDeviceMapping := make([]map[string]interface{}, len(m)) for k, v := range m { @@ -519,14 +519,14 @@ func omiOAPIBlockDeviceMappings(m []oscgo.BlockDeviceMappingImage) []map[string] block["device_name"] = v.GetDeviceName() block["virtual_device_name"] = v.GetVirtualDeviceName() if val, ok := v.GetBsuOk(); ok { - block["bsu"] = getOAPIBsuToCreate(*val) + block["bsu"] = getBsuToCreate(*val) } blockDeviceMapping[k] = block } return blockDeviceMapping } -func getOAPIBsuToCreate(bsu oscgo.BsuToCreate) []map[string]interface{} { +func getBsuToCreate(bsu oscgo.BsuToCreate) []map[string]interface{} { return []map[string]interface{}{{ "delete_on_vm_deletion": bsu.GetDeleteOnVmDeletion(), "iops": bsu.GetIops(), @@ -536,7 +536,7 @@ func getOAPIBsuToCreate(bsu oscgo.BsuToCreate) []map[string]interface{} { }} } -func expandOmiBlockDeviceOApiMappings(blocks []interface{}) []oscgo.BlockDeviceMappingImage { +func expandOmiBlockDeviceMappings(blocks []interface{}) []oscgo.BlockDeviceMappingImage { var blockDevices []oscgo.BlockDeviceMappingImage for _, v := range blocks { @@ -584,7 +584,7 @@ func expandOmiBlockDeviceBSU(bsu []interface{}) oscgo.BsuToCreate { } // Returns the state reason. -func omiOAPIStateReason(m *oscgo.StateComment) []map[string]interface{} { +func omiStateReason(m *oscgo.StateComment) []map[string]interface{} { return []map[string]interface{}{{ "state_code": m.GetStateCode(), "state_message": m.GetStateMessage(), diff --git a/outscale/resource_outscale_image_export_task.go b/outscale/resource_outscale_image_export_task.go index 4add24d1c..ae541ff05 100644 --- a/outscale/resource_outscale_image_export_task.go +++ b/outscale/resource_outscale_image_export_task.go @@ -16,12 +16,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIIMageExportTask() *schema.Resource { +func resourceIMageExportTask() *schema.Resource { return &schema.Resource{ - Create: resourceOAPIImageExportTaskCreate, - Read: resourceOAPIImageExportTaskRead, - Update: resourceOAPIImageExportTaskUpdate, - Delete: resourceOAPIImageExportTaskDelete, + Create: resourceImageExportTaskCreate, + Read: resourceImageExportTaskRead, + Update: resourceImageExportTaskUpdate, + Delete: resourceImageExportTaskDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -104,13 +104,13 @@ func resourceOutscaleOAPIIMageExportTask() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), }, } } -func resourceOAPIImageExportTaskCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageExportTaskCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI eto, etoOk := d.GetOk("osu_export") v, ok := d.GetOk("image_id") @@ -177,21 +177,21 @@ func resourceOAPIImageExportTaskCreate(d *schema.ResourceData, meta interface{}) id := resp.ImageExportTask.GetTaskId() d.SetId(id) if d.IsNewResource() { - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") } - _, err = resourceOutscaleImageTaskWaitForAvailable(id, conn) + _, err = resourceImageTaskWaitForAvailable(id, conn) if err != nil { return err } - return resourceOAPIImageExportTaskRead(d, meta) + return resourceImageExportTaskRead(d, meta) } -func resourceOAPIImageExportTaskRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageExportTaskRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var resp oscgo.ReadImageExportTasksResponse var err error @@ -268,37 +268,37 @@ func resourceOAPIImageExportTaskRead(d *schema.ResourceData, meta interface{}) e if err = d.Set("osu_export", exp); err != nil { return err } - if err = d.Set("tags", tagsOSCAPIToMap(v.GetTags())); err != nil { + if err = d.Set("tags", tagsToMap(v.GetTags())); err != nil { return err } return nil } -func resourceOAPIImageExportTaskUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageExportTaskUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOAPIImageExportTaskRead(d, meta) + return resourceImageExportTaskRead(d, meta) } -func resourceOutscaleImageTaskWaitForAvailable(id string, client *oscgo.APIClient) (oscgo.ImageExportTask, error) { +func resourceImageTaskWaitForAvailable(id string, client *oscgo.APIClient) (oscgo.ImageExportTask, error) { log.Printf("Waiting for Image Task %s to become available...", id) var image oscgo.ImageExportTask stateConf := &resource.StateChangeConf{ Pending: []string{"pending", "pending/queued", "queued"}, Target: []string{"completed"}, Refresh: ImageTaskStateRefreshFunc(client, id), - Timeout: OutscaleImageRetryTimeout, - Delay: OutscaleImageRetryDelay, - MinTimeout: OutscaleImageRetryMinTimeout, + Timeout: ImageRetryTimeout, + Delay: ImageRetryDelay, + MinTimeout: ImageRetryMinTimeout, } info, err := stateConf.WaitForState() @@ -309,7 +309,7 @@ func resourceOutscaleImageTaskWaitForAvailable(id string, client *oscgo.APIClien return image, nil } -func resourceOAPIImageExportTaskDelete(d *schema.ResourceData, meta interface{}) error { +func resourceImageExportTaskDelete(d *schema.ResourceData, meta interface{}) error { d.SetId("") if err := d.Set("osu_export", nil); err != nil { diff --git a/outscale/resource_outscale_image_export_task_test.go b/outscale/resource_outscale_image_export_task_test.go index 3a6dd48cf..0bc817337 100644 --- a/outscale/resource_outscale_image_export_task_test.go +++ b/outscale/resource_outscale_image_export_task_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIImageExportTask_basic(t *testing.T) { +func TestAccImageExportTask_basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") imageName := acctest.RandomWithPrefix("test-image-name") @@ -31,15 +31,15 @@ func TestAccOutscaleOAPIImageExportTask_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOAPIImageExportTaskConfigBasic(omi, "tinav4.c2r2p2", region, imageName, ""), + Config: testAccImageExportTaskConfigBasic(omi, "tinav4.c2r2p2", region, imageName, ""), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPImageExportTaskExists("outscale_image_export_task.outscale_image_export_task"), + testAccCheckmageExportTaskExists("outscale_image_export_task.outscale_image_export_task"), ), }, { - Config: testAccOAPIImageExportTaskConfigBasic(omi, "tinav4.c2r2p2", region, imageName, tags), + Config: testAccImageExportTaskConfigBasic(omi, "tinav4.c2r2p2", region, imageName, tags), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPImageExportTaskExists("outscale_image_export_task.outscale_image_export_task"), + testAccCheckmageExportTaskExists("outscale_image_export_task.outscale_image_export_task"), ), }, }, @@ -49,7 +49,7 @@ func TestAccOutscaleOAPIImageExportTask_basic(t *testing.T) { } } -func testAccCheckOutscaleOAPImageExportTaskExists(n string) resource.TestCheckFunc { +func testAccCheckmageExportTaskExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -64,7 +64,7 @@ func testAccCheckOutscaleOAPImageExportTaskExists(n string) resource.TestCheckFu } } -func testAccOAPIImageExportTaskConfigBasic(omi, vmType, region, imageName, tags string) string { +func testAccImageExportTaskConfigBasic(omi, vmType, region, imageName, tags string) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%s" diff --git a/outscale/resource_outscale_image_launch_permission.go b/outscale/resource_outscale_image_launch_permission.go index facb25c97..6a273f09e 100644 --- a/outscale/resource_outscale_image_launch_permission.go +++ b/outscale/resource_outscale_image_launch_permission.go @@ -17,12 +17,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIImageLaunchPermission() *schema.Resource { +func resourceImageLaunchPermission() *schema.Resource { return &schema.Resource{ - Exists: resourceOutscaleOAPIImageLaunchPermissionExists, - Create: resourceOutscaleOAPIImageLaunchPermissionCreate, - Read: resourceOutscaleOAPIImageLaunchPermissionRead, - Delete: resourceOutscaleOAPIImageLaunchPermissionDelete, + Exists: resourceImageLaunchPermissionExists, + Create: resourceImageLaunchPermissionCreate, + Read: resourceImageLaunchPermissionRead, + Delete: resourceImageLaunchPermissionDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -107,14 +107,14 @@ func resourceOutscaleOAPIImageLaunchPermission() *schema.Resource { } } -func resourceOutscaleOAPIImageLaunchPermissionExists(d *schema.ResourceData, meta interface{}) (bool, error) { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageLaunchPermissionExists(d *schema.ResourceData, meta interface{}) (bool, error) { + conn := meta.(*Client).OSCAPI imageID := d.Get("image_id").(string) - return hasOAPILaunchPermission(conn, imageID) + return hasLaunchPermission(conn, imageID) } -func expandOAPIImagePermission(permissionType interface{}) (res oscgo.PermissionsOnResource) { +func expandImagePermission(permissionType interface{}) (res oscgo.PermissionsOnResource) { if len(permissionType.([]interface{})) > 0 { permission := permissionType.([]interface{})[0].(map[string]interface{}) @@ -131,8 +131,8 @@ func expandOAPIImagePermission(permissionType interface{}) (res oscgo.Permission return } -func resourceOutscaleOAPIImageLaunchPermissionCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageLaunchPermissionCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI imageID, ok := d.GetOk("image_id") @@ -143,10 +143,10 @@ func resourceOutscaleOAPIImageLaunchPermissionCreate(d *schema.ResourceData, met permissionLunch := oscgo.PermissionsOnResourceCreation{} if permissionAdditions, ok := d.GetOk("permission_additions"); ok { - permissionLunch.SetAdditions(expandOAPIImagePermission(permissionAdditions)) + permissionLunch.SetAdditions(expandImagePermission(permissionAdditions)) } if permissionRemovals, ok := d.GetOk("permission_removals"); ok { - permissionLunch.SetRemovals(expandOAPIImagePermission(permissionRemovals)) + permissionLunch.SetRemovals(expandImagePermission(permissionRemovals)) } request := oscgo.UpdateImageRequest{ @@ -172,11 +172,11 @@ func resourceOutscaleOAPIImageLaunchPermissionCreate(d *schema.ResourceData, met d.SetId(imageID.(string)) - return resourceOutscaleOAPIImageLaunchPermissionRead(d, meta) + return resourceImageLaunchPermissionRead(d, meta) } -func resourceOutscaleOAPIImageLaunchPermissionRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageLaunchPermissionRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var resp oscgo.ReadImagesResponse err := resource.Retry(5*time.Minute, func() *resource.RetryError { @@ -219,8 +219,8 @@ func resourceOutscaleOAPIImageLaunchPermissionRead(d *schema.ResourceData, meta return d.Set("permissions_to_launch", []map[string]interface{}{lp}) } -func resourceOutscaleOAPIImageLaunchPermissionDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceImageLaunchPermissionDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI imageID, ok := d.GetOk("image_id") if !ok { @@ -232,7 +232,7 @@ func resourceOutscaleOAPIImageLaunchPermissionDelete(d *schema.ResourceData, met request := oscgo.UpdateImageRequest{ ImageId: imageID.(string), } - permission.SetRemovals(expandOAPIImagePermission(permissionAdditions)) + permission.SetRemovals(expandImagePermission(permissionAdditions)) request.SetPermissionsToLaunch(permission) err := resource.Retry(5*time.Minute, func() *resource.RetryError { @@ -255,7 +255,7 @@ func resourceOutscaleOAPIImageLaunchPermissionDelete(d *schema.ResourceData, met return nil } -func hasOAPILaunchPermission(conn *oscgo.APIClient, imageID string) (bool, error) { +func hasLaunchPermission(conn *oscgo.APIClient, imageID string) (bool, error) { var resp oscgo.ReadImagesResponse err := resource.Retry(5*time.Minute, func() *resource.RetryError { var err error diff --git a/outscale/resource_outscale_image_launch_permission_test.go b/outscale/resource_outscale_image_launch_permission_test.go index a9e0327b1..49a05d36f 100644 --- a/outscale/resource_outscale_image_launch_permission_test.go +++ b/outscale/resource_outscale_image_launch_permission_test.go @@ -17,7 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIImageLaunchPermission_Basic(t *testing.T) { +func TestAccImageLaunchPermission_Basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") accountID := os.Getenv("OUTSCALE_ACCOUNT") @@ -34,31 +34,31 @@ func TestAccOutscaleOAPIImageLaunchPermission_Basic(t *testing.T) { Steps: []r.TestStep{ // Scaffold everything { - Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, true, rInt, keypair, sgId), + Config: testAccImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, true, rInt, keypair, sgId), Check: r.ComposeTestCheckFunc( - testCheckResourceOAPILPIGetAttr("outscale_image.outscale_image", "id", &imageID), + testCheckResourceLPIGetAttr("outscale_image.outscale_image", "id", &imageID), ), }, // Drop just launch permission to test destruction { - Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, false, rInt, keypair, sgId), + Config: testAccImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, false, rInt, keypair, sgId), Check: r.ComposeTestCheckFunc( - testAccOutscaleOAPIImageLaunchPermissionDestroyed(accountID, &imageID), + testAccImageLaunchPermissionDestroyed(accountID, &imageID), ), }, // Re-add everything so we can test when AMI disappears { - Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, true, rInt, keypair, sgId), + Config: testAccImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, true, rInt, keypair, sgId), Check: r.ComposeTestCheckFunc( - testCheckResourceOAPILPIGetAttr("outscale_image.outscale_image", "id", &imageID), + testCheckResourceLPIGetAttr("outscale_image.outscale_image", "id", &imageID), ), }, // Here we delete the AMI to verify the follow-on refresh after this step // should not error. { - Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, true, rInt, keypair, sgId), + Config: testAccImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, true, rInt, keypair, sgId), Check: r.ComposeTestCheckFunc( - testAccOutscaleOAPIImageDisappears(&imageID), + testAccImageDisappears(&imageID), ), ExpectNonEmptyPlan: true, }, @@ -66,7 +66,7 @@ func TestAccOutscaleOAPIImageLaunchPermission_Basic(t *testing.T) { }) } -func TestAccOutscaleOAPIImageLaunchPermissionDestruction_Basic(t *testing.T) { +func TestAccImageLaunchPermissionDestruction_Basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") accountID := os.Getenv("OUTSCALE_ACCOUNT") @@ -82,23 +82,23 @@ func TestAccOutscaleOAPIImageLaunchPermissionDestruction_Basic(t *testing.T) { Steps: []r.TestStep{ // Scaffold everything { - Config: testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, "tinav4.c2r2p2", region, rInt, true, false, keypair, sgId), + Config: testAccImageLaunchPermissionCreateConfig(omi, "tinav4.c2r2p2", region, rInt, true, false, keypair, sgId), Check: r.ComposeTestCheckFunc( - testCheckResourceOAPILPIGetAttr("outscale_image.outscale_image", "id", &imageID), - testAccOutscaleOAPIImageLaunchPermissionExists(accountID, &imageID), + testCheckResourceLPIGetAttr("outscale_image.outscale_image", "id", &imageID), + testAccImageLaunchPermissionExists(accountID, &imageID), ), }, { - Config: testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, "tinav4.c2r2p2", region, rInt, true, true, keypair, sgId), + Config: testAccImageLaunchPermissionCreateConfig(omi, "tinav4.c2r2p2", region, rInt, true, true, keypair, sgId), Check: r.ComposeTestCheckFunc( - testCheckResourceOAPILPIGetAttr("outscale_image.outscale_image", "id", &imageID), + testCheckResourceLPIGetAttr("outscale_image.outscale_image", "id", &imageID), ), }, }, }) } -func testCheckResourceOAPILPIGetAttr(name, key string, value *string) r.TestCheckFunc { +func testCheckResourceLPIGetAttr(name, key string, value *string) r.TestCheckFunc { return func(s *terraform.State) error { ms := s.RootModule() rs, ok := ms.Resources[name] @@ -116,10 +116,10 @@ func testCheckResourceOAPILPIGetAttr(name, key string, value *string) r.TestChec } } -func testAccOutscaleOAPIImageLaunchPermissionExists(accountID string, imageID *string) r.TestCheckFunc { +func testAccImageLaunchPermissionExists(accountID string, imageID *string) r.TestCheckFunc { return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI - if has, err := hasOAPILaunchPermission(conn, *imageID); err != nil { + conn := testAccProvider.Meta().(*Client).OSCAPI + if has, err := hasLaunchPermission(conn, *imageID); err != nil { return err } else if !has { return fmt.Errorf("launch permission does not exist for '%s' on '%s'", accountID, *imageID) @@ -128,10 +128,10 @@ func testAccOutscaleOAPIImageLaunchPermissionExists(accountID string, imageID *s } } -func testAccOutscaleOAPIImageLaunchPermissionDestroyed(accountID string, imageID *string) r.TestCheckFunc { +func testAccImageLaunchPermissionDestroyed(accountID string, imageID *string) r.TestCheckFunc { return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI - if has, err := hasOAPILaunchPermission(conn, *imageID); err != nil { + conn := testAccProvider.Meta().(*Client).OSCAPI + if has, err := hasLaunchPermission(conn, *imageID); err != nil { return err } else if has { return fmt.Errorf("launch permission still exists for '%s' on '%s'", accountID, *imageID) @@ -140,12 +140,12 @@ func testAccOutscaleOAPIImageLaunchPermissionDestroyed(accountID string, imageID } } -// testAccOutscaleOAPIImageDisappears is technically a "test check function" but really it +// testAccImageDisappears is technically a "test check function" but really it // exists to perform a side effect of deleting an AMI out from under a resource // so we can test that Terraform will react properly -func testAccOutscaleOAPIImageDisappears(imageID *string) r.TestCheckFunc { +func testAccImageDisappears(imageID *string) r.TestCheckFunc { return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI req := oscgo.DeleteImageRequest{ ImageId: aws.StringValue(imageID), } @@ -162,7 +162,7 @@ func testAccOutscaleOAPIImageDisappears(imageID *string) r.TestCheckFunc { return err } - return resourceOutscaleOAPIImageWaitForDestroy(*imageID, conn) + return resourceImageWaitForDestroy(*imageID, conn) } } @@ -184,7 +184,7 @@ func testCheckResourceGetAttr(name, key string, value *string) r.TestCheckFunc { } } -func testAccOutscaleOAPIImageLaunchPermissionConfig(omi, vmType, region, accountID string, includeLaunchPermission bool, r int, keypair, sgId string) string { +func testAccImageLaunchPermissionConfig(omi, vmType, region, accountID string, includeLaunchPermission bool, r int, keypair, sgId string) string { base := fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" @@ -236,7 +236,7 @@ func testAccOutscaleOAPIImageLaunchPermissionConfig(omi, vmType, region, account `, accountID) } -func testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, vmType, region string, r int, includeAddtion, includeRemoval bool, keypair, sgId string) string { +func testAccImageLaunchPermissionCreateConfig(omi, vmType, region string, r int, includeAddtion, includeRemoval bool, keypair, sgId string) string { base := fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_image_test.go b/outscale/resource_outscale_image_test.go index b3965ec88..9266343a7 100644 --- a/outscale/resource_outscale_image_test.go +++ b/outscale/resource_outscale_image_test.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIImage_basic(t *testing.T) { +func TestAccImage_basic(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -26,12 +26,12 @@ func TestAccOutscaleOAPIImage_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIImageDestroy, + CheckDestroy: testAccCheckImageDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIImageConfigBasic(omi, "tinav4.c2r2p2", region, rInt), + Config: testAccImageConfigBasic(omi, "tinav4.c2r2p2", region, rInt), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIImageExists("outscale_image.foo", &ami), + testAccCheckImageExists("outscale_image.foo", &ami), resource.TestCheckResourceAttr( "outscale_image.foo", "image_name", fmt.Sprintf("tf-testing-%d", rInt)), resource.TestCheckResourceAttr( @@ -44,8 +44,8 @@ func TestAccOutscaleOAPIImage_basic(t *testing.T) { }) } -func testAccCheckOAPIImageDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckImageDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_image" { @@ -72,7 +72,7 @@ func testAccCheckOAPIImageDestroy(s *terraform.State) error { return nil } -func testAccCheckOAPIImageExists(n string, ami *oscgo.Image) resource.TestCheckFunc { +func testAccCheckImageExists(n string, ami *oscgo.Image) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -83,7 +83,7 @@ func testAccCheckOAPIImageExists(n string, ami *oscgo.Image) resource.TestCheckF return fmt.Errorf("No OMI ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI filterReq := oscgo.ReadImagesRequest{ Filters: &oscgo.FiltersImage{ImageIds: &[]string{rs.Primary.ID}}, @@ -108,7 +108,7 @@ func testAccCheckOAPIImageExists(n string, ami *oscgo.Image) resource.TestCheckF } } -func testAccOAPIImageConfigBasic(omi, vmType, region string, rInt int) string { +func testAccImageConfigBasic(omi, vmType, region string, rInt int) string { return fmt.Sprintf(` resource "outscale_vm" "basic" { image_id = "%[1]s" diff --git a/outscale/resource_outscale_internet_service.go b/outscale/resource_outscale_internet_service.go index 9ba3ab4c2..d072e59d5 100644 --- a/outscale/resource_outscale_internet_service.go +++ b/outscale/resource_outscale_internet_service.go @@ -12,12 +12,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPIInternetService() *schema.Resource { +func resourceInternetService() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIInternetServiceCreate, - Read: resourceOutscaleOAPIInternetServiceRead, - Update: resourceOutscaleOAPIInternetServiceUpdate, - Delete: resourceOutscaleOAPIInternetServiceDelete, + Create: resourceInternetServiceCreate, + Read: resourceInternetServiceRead, + Update: resourceInternetServiceUpdate, + Delete: resourceInternetServiceDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -39,13 +39,13 @@ func resourceOutscaleOAPIInternetService() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), }, } } -func resourceOutscaleOAPIInternetServiceCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceInternetServiceCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var resp oscgo.CreateInternetServiceResponse var err error @@ -71,11 +71,11 @@ func resourceOutscaleOAPIInternetServiceCreate(d *schema.ResourceData, meta inte d.SetId(resp.InternetService.GetInternetServiceId()) - return resourceOutscaleOAPIInternetServiceRead(d, meta) + return resourceInternetServiceRead(d, meta) } -func resourceOutscaleOAPIInternetServiceRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceInternetServiceRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() @@ -120,26 +120,26 @@ func resourceOutscaleOAPIInternetServiceRead(d *schema.ResourceData, meta interf return err } - return d.Set("tags", tagsOSCAPIToMap(resp.GetInternetServices()[0].GetTags())) + return d.Set("tags", tagsToMap(resp.GetInternetServices()[0].GetTags())) } -func resourceOutscaleOAPIInternetServiceUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceInternetServiceUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOutscaleOAPIInternetServiceRead(d, meta) + return resourceInternetServiceRead(d, meta) } -func resourceOutscaleOAPIInternetServiceDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceInternetServiceDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI internetServiceID := d.Id() filterReq := oscgo.ReadInternetServicesRequest{ @@ -149,7 +149,7 @@ func resourceOutscaleOAPIInternetServiceDelete(d *schema.ResourceData, meta inte stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: []string{"deleted", "available"}, - Refresh: LISOAPIStateRefreshFunction(conn, filterReq, "failed"), + Refresh: LISStateRefreshFunction(conn, filterReq, "failed"), Timeout: 10 * time.Minute, MinTimeout: 30 * time.Second, Delay: 1 * time.Minute, diff --git a/outscale/resource_outscale_internet_service_link.go b/outscale/resource_outscale_internet_service_link.go index f67f63549..70dcd1bcd 100644 --- a/outscale/resource_outscale_internet_service_link.go +++ b/outscale/resource_outscale_internet_service_link.go @@ -12,11 +12,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIInternetServiceLink() *schema.Resource { +func resourceInternetServiceLink() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIInternetServiceLinkCreate, - Read: resourceOutscaleOAPIInternetServiceLinkRead, - Delete: resourceOutscaleOAPIInternetServiceLinkDelete, + Create: resourceInternetServiceLinkCreate, + Read: resourceInternetServiceLinkRead, + Delete: resourceInternetServiceLinkDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -63,8 +63,8 @@ func resourceOutscaleOAPIInternetServiceLink() *schema.Resource { } } -func resourceOutscaleOAPIInternetServiceLinkCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceInternetServiceLinkCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI internetServiceID := d.Get("internet_service_id").(string) req := oscgo.LinkInternetServiceRequest{ @@ -96,7 +96,7 @@ func resourceOutscaleOAPIInternetServiceLinkCreate(d *schema.ResourceData, meta stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: []string{"available"}, - Refresh: LISOAPIStateRefreshFunction(conn, filterReq, "failed"), + Refresh: LISStateRefreshFunction(conn, filterReq, "failed"), Timeout: 10 * time.Minute, MinTimeout: 30 * time.Second, // Delay: 3 * time.Minute, @@ -108,11 +108,11 @@ func resourceOutscaleOAPIInternetServiceLinkCreate(d *schema.ResourceData, meta d.SetId(internetServiceID) - return resourceOutscaleOAPIInternetServiceLinkRead(d, meta) + return resourceInternetServiceLinkRead(d, meta) } -func resourceOutscaleOAPIInternetServiceLinkRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceInternetServiceLinkRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI internetServiceID := d.Id() filterReq := oscgo.ReadInternetServicesRequest{ @@ -122,7 +122,7 @@ func resourceOutscaleOAPIInternetServiceLinkRead(d *schema.ResourceData, meta in stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: []string{"deleted", "available"}, - Refresh: LISOAPIStateRefreshFunction(conn, filterReq, "failed"), + Refresh: LISStateRefreshFunction(conn, filterReq, "failed"), Timeout: 10 * time.Minute, MinTimeout: 30 * time.Second, // Delay: 3 * time.Minute, @@ -152,7 +152,7 @@ func resourceOutscaleOAPIInternetServiceLinkRead(d *schema.ResourceData, meta in return err } - if err := set("tags", getOapiTagSet(internetService.Tags)); err != nil { + if err := set("tags", getTagSet(internetService.GetTags())); err != nil { return err } @@ -160,8 +160,8 @@ func resourceOutscaleOAPIInternetServiceLinkRead(d *schema.ResourceData, meta in }) } -func resourceOutscaleOAPIInternetServiceLinkDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceInternetServiceLinkDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI internetServiceID := d.Id() filterReq := oscgo.ReadInternetServicesRequest{ @@ -171,7 +171,7 @@ func resourceOutscaleOAPIInternetServiceLinkDelete(d *schema.ResourceData, meta stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: []string{"deleted", "available"}, - Refresh: LISOAPIStateRefreshFunction(conn, filterReq, "failed"), + Refresh: LISStateRefreshFunction(conn, filterReq, "failed"), Timeout: 10 * time.Minute, MinTimeout: 30 * time.Second, // Delay: 3 * time.Minute, @@ -206,9 +206,9 @@ func resourceOutscaleOAPIInternetServiceLinkDelete(d *schema.ResourceData, meta return nil } -// LISOAPIStateRefreshFunction returns a resource.StateRefreshFunc that is used to watch +// LISStateRefreshFunction returns a resource.StateRefreshFunc that is used to watch // a Link Internet Service. -func LISOAPIStateRefreshFunction(client *oscgo.APIClient, req oscgo.ReadInternetServicesRequest, failState string) resource.StateRefreshFunc { +func LISStateRefreshFunction(client *oscgo.APIClient, req oscgo.ReadInternetServicesRequest, failState string) resource.StateRefreshFunc { return func() (interface{}, string, error) { var resp oscgo.ReadInternetServicesResponse var err error diff --git a/outscale/resource_outscale_internet_service_link_test.go b/outscale/resource_outscale_internet_service_link_test.go index 26b6c81c0..05ff4dfdc 100644 --- a/outscale/resource_outscale_internet_service_link_test.go +++ b/outscale/resource_outscale_internet_service_link_test.go @@ -13,42 +13,42 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIInternetServiceLink_basic(t *testing.T) { +func TestAccInternetServiceLink_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOSCAPIInternetServiceLinkDestroyed, + CheckDestroy: testAccCheckInternetServiceLinkDestroyed, Steps: []resource.TestStep{ { - Config: testAccOutscaleInternetServiceLinkConfig(), + Config: testAccInternetServiceLinkConfig(), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOSCAPIInternetServiceLinkExists("outscale_internet_service_link.outscale_internet_service_link"), + testAccCheckInternetServiceLinkExists("outscale_internet_service_link.outscale_internet_service_link"), ), }, { - Config: testAccOutscaleInternetServiceLinkConfig(), + Config: testAccInternetServiceLinkConfig(), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOSCAPIInternetServiceLinkExists("outscale_internet_service_link.outscale_internet_service_link"), + testAccCheckInternetServiceLinkExists("outscale_internet_service_link.outscale_internet_service_link"), ), }, }, }) } -func TestAccOutscaleOAPIInternetServiceLink_importBasic(t *testing.T) { +func TestAccInternetServiceLink_importBasic(t *testing.T) { resourceName := "outscale_internet_service_link.outscale_internet_service_link" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOSCAPIInternetServiceLinkDestroyed, + CheckDestroy: testAccCheckInternetServiceLinkDestroyed, Steps: []resource.TestStep{ { - Config: testAccOutscaleInternetServiceLinkConfig(), + Config: testAccInternetServiceLinkConfig(), }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOutscaleInternetServiceLinkImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckInternetServiceLinkImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id"}, @@ -57,7 +57,7 @@ func TestAccOutscaleOAPIInternetServiceLink_importBasic(t *testing.T) { }) } -func testAccCheckOutscaleInternetServiceLinkImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckInternetServiceLinkImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -67,14 +67,14 @@ func testAccCheckOutscaleInternetServiceLinkImportStateIDFunc(resourceName strin } } -func testAccCheckOutscaleOSCAPIInternetServiceLinkExists(n string) resource.TestCheckFunc { +func testAccCheckInternetServiceLinkExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI if rs.Primary.ID == "" { return fmt.Errorf("No internet gateway id is set") @@ -100,8 +100,8 @@ func testAccCheckOutscaleOSCAPIInternetServiceLinkExists(n string) resource.Test } } -func testAccCheckOutscaleOSCAPIInternetServiceLinkDestroyed(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckInternetServiceLinkDestroyed(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_internet_service_link" { @@ -128,7 +128,7 @@ func testAccCheckOutscaleOSCAPIInternetServiceLinkDestroyed(s *terraform.State) return nil } -func testAccOutscaleInternetServiceLinkConfig() string { +func testAccInternetServiceLinkConfig() string { return ` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_internet_service_test.go b/outscale/resource_outscale_internet_service_test.go index d948a3a92..ace9936c9 100644 --- a/outscale/resource_outscale_internet_service_test.go +++ b/outscale/resource_outscale_internet_service_test.go @@ -13,37 +13,37 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIInternetService_basic(t *testing.T) { +func TestAccInternetService_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleInternetServiceDestroyed, + CheckDestroy: testAccCheckInternetServiceDestroyed, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIInternetServiceConfig(), + Config: testAccInternetServiceConfig(), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleInternetServiceExists("outscale_internet_service.outscale_internet_service"), + testAccCheckInternetServiceExists("outscale_internet_service.outscale_internet_service"), ), }, { - Config: testAccOutscaleOAPIInternetServiceConfig(), + Config: testAccInternetServiceConfig(), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleInternetServiceExists("outscale_internet_service.outscale_internet_service"), + testAccCheckInternetServiceExists("outscale_internet_service.outscale_internet_service"), ), }, }, }) } -func testAccCheckOutscaleInternetServiceExists(n string) resource.TestCheckFunc { +func testAccCheckInternetServiceExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI if rs.Primary.ID == "" { return fmt.Errorf("No internet gateway id is set") @@ -70,8 +70,8 @@ func testAccCheckOutscaleInternetServiceExists(n string) resource.TestCheckFunc } } -func testAccCheckOutscaleInternetServiceDestroyed(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckInternetServiceDestroyed(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_internet_service_link" { @@ -99,7 +99,7 @@ func testAccCheckOutscaleInternetServiceDestroyed(s *terraform.State) error { return nil } -func testAccOutscaleOAPIInternetServiceConfig() string { +func testAccInternetServiceConfig() string { return ` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_keypair.go b/outscale/resource_outscale_keypair.go index 949d6edb7..bebc41a68 100644 --- a/outscale/resource_outscale_keypair.go +++ b/outscale/resource_outscale_keypair.go @@ -14,11 +14,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIKeyPair() *schema.Resource { +func resourceKeyPair() *schema.Resource { return &schema.Resource{ - Create: resourceOAPIKeyPairCreate, - Read: resourceOAPIKeyPairRead, - Delete: resourceOAPIKeyPairDelete, + Create: resourceKeyPairCreate, + Read: resourceKeyPairRead, + Delete: resourceKeyPairDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -29,12 +29,12 @@ func resourceOutscaleOAPIKeyPair() *schema.Resource { Delete: schema.DefaultTimeout(10 * time.Minute), }, - Schema: getOAPIKeyPairSchema(), + Schema: getKeyPairSchema(), } } -func resourceOAPIKeyPairCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceKeyPairCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var keyName string if v, ok := d.GetOk("keypair_name"); ok { @@ -70,7 +70,7 @@ func resourceOAPIKeyPairCreate(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] resp keypair: %+v", resp) if err != nil { errString = err.Error() - return fmt.Errorf("Error creating OAPIKeyPair: %s", errString) + return fmt.Errorf("Error creating KeyPair: %s", errString) } d.SetId(resp.Keypair.GetKeypairName()) @@ -85,11 +85,11 @@ func resourceOAPIKeyPairCreate(d *schema.ResourceData, meta interface{}) error { } } - return resourceOAPIKeyPairRead(d, meta) + return resourceKeyPairRead(d, meta) } -func resourceOAPIKeyPairRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceKeyPairRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadKeypairsRequest{ Filters: &oscgo.FiltersKeypair{KeypairNames: &[]string{d.Id()}}, } @@ -108,13 +108,13 @@ func resourceOAPIKeyPairRead(d *schema.ResourceData, meta interface{}) error { var errString string if err != nil { - if strings.Contains(fmt.Sprint(err), "InvalidOAPIKeyPair.NotFound") { + if strings.Contains(fmt.Sprint(err), "InvalidKeyPair.NotFound") { d.SetId("") return nil } errString = err.Error() - return fmt.Errorf("Error retrieving OAPIKeyPair: %s", errString) + return fmt.Errorf("Error retrieving KeyPair: %s", errString) } for _, keyPair := range resp.GetKeypairs() { @@ -132,8 +132,8 @@ func resourceOAPIKeyPairRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Unable to find key pair within: %#v", resp.GetKeypairs()) } -func resourceOAPIKeyPairDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceKeyPairDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI err := resource.Retry(5*time.Minute, func() *resource.RetryError { request := oscgo.DeleteKeypairRequest{ @@ -155,7 +155,7 @@ func resourceOAPIKeyPairDelete(d *schema.ResourceData, meta interface{}) error { return err } -func getOAPIKeyPairSchema() map[string]*schema.Schema { +func getKeyPairSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ // Attributes "keypair_fingerprint": { diff --git a/outscale/resource_outscale_keypair_test.go b/outscale/resource_outscale_keypair_test.go index 3381709ab..2a142b3cf 100644 --- a/outscale/resource_outscale_keypair_test.go +++ b/outscale/resource_outscale_keypair_test.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIKeyPair_basic(t *testing.T) { +func TestAccKeyPair_basic(t *testing.T) { t.Parallel() var conf oscgo.Keypair @@ -23,20 +23,20 @@ func TestAccOutscaleOAPIKeyPair_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIKeyPairDestroy, + CheckDestroy: testAccCheckKeyPairDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIKeyPairConfig(rInt), + Config: testAccKeyPairConfig(rInt), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIKeyPairExists("outscale_keypair.a_key_pair", &conf), - testAccCheckOutscaleOAPIKeyPairFingerprint("8a:47:95:bb:b1:45:66:ef:99:f5:80:91:cc:be:94:48", &conf), + testAccCheckKeyPairExists("outscale_keypair.a_key_pair", &conf), + testAccCheckKeyPairFingerprint("8a:47:95:bb:b1:45:66:ef:99:f5:80:91:cc:be:94:48", &conf), ), }, }, }) } -func TestAccOutscaleOAPIKeyPair_retrieveName(t *testing.T) { +func TestAccKeyPair_retrieveName(t *testing.T) { t.Parallel() var conf oscgo.Keypair @@ -44,12 +44,12 @@ func TestAccOutscaleOAPIKeyPair_retrieveName(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIKeyPairDestroy, + CheckDestroy: testAccCheckKeyPairDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIKeyPairConfigRetrieveName(rInt), + Config: testAccKeyPairConfigRetrieveName(rInt), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIKeyPairExists("outscale_keypair.a_key_pair", &conf), + testAccCheckKeyPairExists("outscale_keypair.a_key_pair", &conf), resource.TestCheckResourceAttr( "outscale_keypair.a_key_pair", "keypair_name", fmt.Sprintf("tf-acc-key-pair-%d", rInt), ), @@ -59,20 +59,20 @@ func TestAccOutscaleOAPIKeyPair_retrieveName(t *testing.T) { }, }) } -func TestAccOutscaleOAPIKeyPair_generatedName(t *testing.T) { +func TestAccKeyPair_generatedName(t *testing.T) { t.Parallel() var conf oscgo.Keypair resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIKeyPairDestroy, + CheckDestroy: testAccCheckKeyPairDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIKeyPairConfigGeneratedName, + Config: testAccKeyPairConfigGeneratedName, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIKeyPairExists("outscale_keypair.a_key_pair", &conf), - testAccCheckOutscaleOAPIKeyPairFingerprint("8a:47:95:bb:b1:45:66:ef:99:f5:80:91:cc:be:94:48", &conf), + testAccCheckKeyPairExists("outscale_keypair.a_key_pair", &conf), + testAccCheckKeyPairFingerprint("8a:47:95:bb:b1:45:66:ef:99:f5:80:91:cc:be:94:48", &conf), func(s *terraform.State) error { if conf.GetKeypairName() == "" { return fmt.Errorf("bad: No SG name") @@ -88,8 +88,8 @@ func TestAccOutscaleOAPIKeyPair_generatedName(t *testing.T) { }) } -func testAccCheckOutscaleOAPIKeyPairDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient) +func testAccCheckKeyPairDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client) for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_keypair" { @@ -124,7 +124,7 @@ func testAccCheckOutscaleOAPIKeyPairDestroy(s *terraform.State) error { return nil } -func testAccCheckOutscaleOAPIKeyPairFingerprint(expectedFingerprint string, conf *oscgo.Keypair) resource.TestCheckFunc { +func testAccCheckKeyPairFingerprint(expectedFingerprint string, conf *oscgo.Keypair) resource.TestCheckFunc { return func(s *terraform.State) error { if conf.GetKeypairFingerprint() != expectedFingerprint { return fmt.Errorf("incorrect fingerprint. expected %s, got %s", expectedFingerprint, conf.GetKeypairFingerprint()) @@ -133,7 +133,7 @@ func testAccCheckOutscaleOAPIKeyPairFingerprint(expectedFingerprint string, conf } } -func testAccCheckOutscaleOAPIKeyPairExists(n string, res *oscgo.Keypair) resource.TestCheckFunc { +func testAccCheckKeyPairExists(n string, res *oscgo.Keypair) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -141,11 +141,11 @@ func testAccCheckOutscaleOAPIKeyPairExists(n string, res *oscgo.Keypair) resourc } if rs.Primary.ID == "" { - return fmt.Errorf("No OAPIKeyPair name is set") + return fmt.Errorf("No KeyPair name is set") } var resp oscgo.ReadKeypairsResponse var statusCode int - conn := testAccProvider.Meta().(*OutscaleClient) + conn := testAccProvider.Meta().(*Client) err := resource.Retry(5*time.Minute, func() *resource.RetryError { rp, httpResp, err := conn.OSCAPI.KeypairApi.ReadKeypairs(context.Background()).ReadKeypairsRequest(oscgo.ReadKeypairsRequest{ @@ -164,7 +164,7 @@ func testAccCheckOutscaleOAPIKeyPairExists(n string, res *oscgo.Keypair) resourc } if len(resp.GetKeypairs()) != 1 || resp.GetKeypairs()[0].GetKeypairName() != rs.Primary.ID { - return fmt.Errorf("OAPIKeyPair not found") + return fmt.Errorf("KeyPair not found") } *res = resp.GetKeypairs()[0] @@ -173,7 +173,7 @@ func testAccCheckOutscaleOAPIKeyPairExists(n string, res *oscgo.Keypair) resourc } } -func testAccOutscaleOAPIKeyPairConfig(r int) string { +func testAccKeyPairConfig(r int) string { return fmt.Sprintf(` resource "outscale_keypair" "a_key_pair" { keypair_name = "tf-acc-key-pair-%d" @@ -182,7 +182,7 @@ func testAccOutscaleOAPIKeyPairConfig(r int) string { `, r) } -func testAccOutscaleOAPIKeyPairConfigRetrieveName(r int) string { +func testAccKeyPairConfigRetrieveName(r int) string { return fmt.Sprintf(` resource "outscale_keypair" "a_key_pair" { keypair_name = "tf-acc-key-pair-%d" @@ -190,7 +190,7 @@ func testAccOutscaleOAPIKeyPairConfigRetrieveName(r int) string { `, r) } -const testAccOutscaleOAPIKeyPairConfigGeneratedName = ` +const testAccKeyPairConfigGeneratedName = ` resource "outscale_keypair" "a_key_pair" { public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" } diff --git a/outscale/resource_outscale_load_balancer.go b/outscale/resource_outscale_load_balancer.go index 51da4ec09..c7c42759d 100644 --- a/outscale/resource_outscale_load_balancer.go +++ b/outscale/resource_outscale_load_balancer.go @@ -34,12 +34,12 @@ func lb_sg_schema() *schema.Schema { } } -func resourceOutscaleOAPILoadBalancer() *schema.Resource { +func resourceLoadBalancer() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPILoadBalancerCreate, - Read: resourceOutscaleOAPILoadBalancerRead, - Update: resourceOutscaleOAPILoadBalancerUpdate, - Delete: resourceOutscaleOAPILoadBalancerDelete, + Create: resourceLoadBalancerCreate, + Read: resourceLoadBalancerRead, + Update: resourceLoadBalancerUpdate, + Delete: resourceLoadBalancerDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -76,7 +76,7 @@ func resourceOutscaleOAPILoadBalancer() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "tags": tagsListOAPISchema2(false), + "tags": tagsListSchema2(false), "dns_name": { Type: schema.TypeString, @@ -228,7 +228,7 @@ func expandSetStringList(ifs *schema.Set) *[]string { } // Flattens an array of Listeners into a []map[string]interface{} -func flattenOAPIListeners(list *[]oscgo.Listener) []map[string]interface{} { +func flattenListeners(list *[]oscgo.Listener) []map[string]interface{} { if list == nil { return make([]map[string]interface{}, 0) } @@ -382,12 +382,12 @@ func lb_listener_schema(computed bool) map[string]*schema.Schema { } } -func resourceOutscaleOAPILoadBalancerCreate(d *schema.ResourceData, meta interface{}) error { - return resourceOutscaleOAPILoadBalancerCreate_(d, meta, false) +func resourceLoadBalancerCreate(d *schema.ResourceData, meta interface{}) error { + return resourceLoadBalancerCreate_(d, meta, false) } -func resourceOutscaleOAPILoadBalancerCreate_(d *schema.ResourceData, meta interface{}, isUpdate bool) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLoadBalancerCreate_(d *schema.ResourceData, meta interface{}, isUpdate bool) error { + conn := meta.(*Client).OSCAPI req := &oscgo.CreateLoadBalancerRequest{} @@ -479,7 +479,7 @@ func resourceOutscaleOAPILoadBalancerCreate_(d *schema.ResourceData, meta interf } } - return resourceOutscaleOAPILoadBalancerRead(d, meta) + return resourceLoadBalancerRead(d, meta) } func flattenStringList(list *[]string) []interface{} { @@ -527,8 +527,8 @@ func readResourceLb(conn *oscgo.APIClient, elbName string) (*oscgo.LoadBalancer, return &lb, &resp, nil } -func resourceOutscaleOAPILoadBalancerRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLoadBalancerRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI elbName := d.Id() lb, _, err := readResourceLb(conn, elbName) @@ -538,11 +538,11 @@ func resourceOutscaleOAPILoadBalancerRead(d *schema.ResourceData, meta interface d.Set("subregion_names", flattenStringList(lb.SubregionNames)) d.Set("dns_name", lb.DnsName) - d.Set("health_check", flattenOAPIHealthCheck(lb.HealthCheck)) - d.Set("access_log", flattenOAPIAccessLog(lb.AccessLog)) + d.Set("health_check", flattenHealthCheck(lb.HealthCheck)) + d.Set("access_log", flattenAccessLog(lb.AccessLog)) d.Set("backend_vm_ids", flattenStringList(lb.BackendVmIds)) - if err := d.Set("listeners", flattenOAPIListeners(lb.Listeners)); err != nil { + if err := d.Set("listeners", flattenListeners(lb.Listeners)); err != nil { log.Printf("[DEBUG] out err %v", err) return err } @@ -607,8 +607,8 @@ func resourceOutscaleOAPILoadBalancerRead(d *schema.ResourceData, meta interface return nil } -func resourceOutscaleOAPILoadBalancerUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLoadBalancerUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var err error d.Partial(true) @@ -944,11 +944,11 @@ func resourceOutscaleOAPILoadBalancerUpdate(d *schema.ResourceData, meta interfa d.Partial(false) - return resourceOutscaleOAPILoadBalancerRead(d, meta) + return resourceLoadBalancerRead(d, meta) } -func resourceOutscaleOAPILoadBalancerDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLoadBalancerDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI log.Printf("[INFO] Deleting Load Balancer: %s", d.Id()) @@ -1009,7 +1009,7 @@ func formatInt32(n int32) string { return strconv.FormatInt(int64(n), 10) } -func flattenOAPIHealthCheck(check *oscgo.HealthCheck) map[string]interface{} { +func flattenHealthCheck(check *oscgo.HealthCheck) map[string]interface{} { chk := make(map[string]interface{}) if check != nil { @@ -1033,7 +1033,7 @@ func flattenOAPIHealthCheck(check *oscgo.HealthCheck) map[string]interface{} { return chk } -func flattenOAPIAccessLog(aclog *oscgo.AccessLog) map[string]interface{} { +func flattenAccessLog(aclog *oscgo.AccessLog) map[string]interface{} { accl := make(map[string]interface{}) if aclog != nil { diff --git a/outscale/resource_outscale_load_balancer_attributes.go b/outscale/resource_outscale_load_balancer_attributes.go index 89d51bd59..d1bdb63c9 100644 --- a/outscale/resource_outscale_load_balancer_attributes.go +++ b/outscale/resource_outscale_load_balancer_attributes.go @@ -15,12 +15,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPILoadBalancerAttributes() *schema.Resource { +func resourceLoadBalancerAttributes() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPILoadBalancerAttributesCreate, - Update: resourceOutscaleOAPILoadBalancerAttributesUpdate, - Read: resourceOutscaleOAPILoadBalancerAttributesRead, - Delete: resourceOutscaleOAPILoadBalancerAttributesDelete, + Create: resourceLoadBalancerAttributesCreate, + Update: resourceLoadBalancerAttributesUpdate, + Read: resourceLoadBalancerAttributesRead, + Delete: resourceLoadBalancerAttributesDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -141,7 +141,7 @@ func resourceOutscaleOAPILoadBalancerAttributes() *schema.Resource { ForceNew: true, }, - "tags": tagsListOAPISchema2(true), + "tags": tagsListSchema2(true), "dns_name": { Type: schema.TypeString, Computed: true, @@ -237,17 +237,17 @@ func lb_atoi_at(hc map[string]interface{}, el string) (int, bool) { return r, err == nil } -func resourceOutscaleOAPILoadBalancerAttributesUpdate(d *schema.ResourceData, +func resourceLoadBalancerAttributesUpdate(d *schema.ResourceData, meta interface{}) error { - return resourceOutscaleOAPILoadBalancerAttributesCreate_(d, meta, true) + return resourceLoadBalancerAttributesCreate_(d, meta, true) } -func resourceOutscaleOAPILoadBalancerAttributesCreate(d *schema.ResourceData, meta interface{}) error { - return resourceOutscaleOAPILoadBalancerAttributesCreate_(d, meta, false) +func resourceLoadBalancerAttributesCreate(d *schema.ResourceData, meta interface{}) error { + return resourceLoadBalancerAttributesCreate_(d, meta, false) } func loadBalancerAttributesDoRequest(d *schema.ResourceData, meta interface{}, req oscgo.UpdateLoadBalancerRequest) error { - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI var err error err = resource.Retry(5*time.Minute, func() *resource.RetryError { _, httpResp, err := conn.LoadBalancerApi.UpdateLoadBalancer( @@ -265,11 +265,11 @@ func loadBalancerAttributesDoRequest(d *schema.ResourceData, meta interface{}, r d.SetId(req.LoadBalancerName) log.Printf("[INFO] LBU Attr ID: %s", d.Id()) - return resourceOutscaleOAPILoadBalancerAttributesRead(d, meta) + return resourceLoadBalancerAttributesRead(d, meta) } -func resourceOutscaleOAPILoadBalancerAttributesCreate_(d *schema.ResourceData, meta interface{}, isUpdate bool) error { +func resourceLoadBalancerAttributesCreate_(d *schema.ResourceData, meta interface{}, isUpdate bool) error { ename, ok := d.GetOk("load_balancer_name") if !ok { @@ -387,8 +387,8 @@ func resourceOutscaleOAPILoadBalancerAttributesCreate_(d *schema.ResourceData, m return loadBalancerAttributesDoRequest(d, meta, req) } -func resourceOutscaleOAPILoadBalancerAttributesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLoadBalancerAttributesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI elbName := d.Id() lb, _, err := readResourceLb(conn, elbName) @@ -477,18 +477,18 @@ func resourceOutscaleOAPILoadBalancerAttributesRead(d *schema.ResourceData, meta } hls := make([]interface{}, 1) - hls[0] = flattenOAPIHealthCheck(lb.HealthCheck) + hls[0] = flattenHealthCheck(lb.HealthCheck) d.Set("health_check", hls) - d.Set("listeners", flattenOAPIListeners(lb.Listeners)) + d.Set("listeners", flattenListeners(lb.Listeners)) d.Set("dns_name", lb.DnsName) return nil } -func resourceOutscaleOAPILoadBalancerAttributesDelete(d *schema.ResourceData, meta interface{}) error { +func resourceLoadBalancerAttributesDelete(d *schema.ResourceData, meta interface{}) error { var err error - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI ename, ok := d.GetOk("load_balancer_name") if !ok { diff --git a/outscale/resource_outscale_load_balancer_attributes_test.go b/outscale/resource_outscale_load_balancer_attributes_test.go index 98cdf6d7a..c7ab07ade 100644 --- a/outscale/resource_outscale_load_balancer_attributes_test.go +++ b/outscale/resource_outscale_load_balancer_attributes_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPILBUAttr_basic(t *testing.T) { +func TestAccLBUAttr_basic(t *testing.T) { t.Parallel() var conf oscgo.AccessLog @@ -25,15 +25,15 @@ func TestAccOutscaleOAPILBUAttr_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILBUAttrConfig(r), + Config: testAccLBUAttrConfig(r), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILBUAttrExists("outscale_load_balancer_attributes.bar2", &conf), + testAccCheckLBUAttrExists("outscale_load_balancer_attributes.bar2", &conf), )}, }, }) } -func testAccCheckOutscaleOAPILBUAttrExists(n string, res *oscgo.AccessLog) resource.TestCheckFunc { +func testAccCheckLBUAttrExists(n string, res *oscgo.AccessLog) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -48,7 +48,7 @@ func testAccCheckOutscaleOAPILBUAttrExists(n string, res *oscgo.AccessLog) resou } } -func testAccOutscaleOAPILBUAttrConfig(r int) string { +func testAccLBUAttrConfig(r int) string { return fmt.Sprintf(` resource "outscale_load_balancer" "bar" { subregion_names = ["eu-west-2a"] diff --git a/outscale/resource_outscale_load_balancer_listener_rule.go b/outscale/resource_outscale_load_balancer_listener_rule.go index 5fe103b7f..b08437c58 100644 --- a/outscale/resource_outscale_load_balancer_listener_rule.go +++ b/outscale/resource_outscale_load_balancer_listener_rule.go @@ -13,12 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleLoadBalancerListenerRule() *schema.Resource { +func resourceLoadBalancerListenerRule() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleLoadBalancerListenerRuleCreate, - Read: resourceOutscaleLoadBalancerListenerRuleRead, - Update: resourceOutscaleLoadBalancerListenerRuleUpdate, - Delete: resourceOutscaleLoadBalancerListenerRuleDelete, + Create: resourceLoadBalancerListenerRuleCreate, + Read: resourceLoadBalancerListenerRuleRead, + Update: resourceLoadBalancerListenerRuleUpdate, + Delete: resourceLoadBalancerListenerRuleDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -97,8 +97,8 @@ func resourceOutscaleLoadBalancerListenerRule() *schema.Resource { } } -func resourceOutscaleLoadBalancerListenerRuleCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLoadBalancerListenerRuleCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := &oscgo.CreateListenerRuleRequest{} if vids, ok := d.GetOk("vm_ids"); ok { @@ -168,11 +168,11 @@ func resourceOutscaleLoadBalancerListenerRuleCreate(d *schema.ResourceData, meta d.SetId(*resp.ListenerRule.ListenerRuleName) - return resourceOutscaleLoadBalancerListenerRuleRead(d, meta) + return resourceLoadBalancerListenerRuleRead(d, meta) } -func resourceOutscaleLoadBalancerListenerRuleRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLoadBalancerListenerRuleRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI lrName := d.Id() filter := &oscgo.FiltersListenerRule{ @@ -239,8 +239,8 @@ func resourceOutscaleLoadBalancerListenerRuleRead(d *schema.ResourceData, meta i return nil } -func resourceOutscaleLoadBalancerListenerRuleUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLoadBalancerListenerRuleUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI if d.HasChange("listener_rule") { var err error @@ -282,11 +282,11 @@ func resourceOutscaleLoadBalancerListenerRuleUpdate(d *schema.ResourceData, meta return err } } - return resourceOutscaleLoadBalancerListenerRuleRead(d, meta) + return resourceLoadBalancerListenerRuleRead(d, meta) } -func resourceOutscaleLoadBalancerListenerRuleDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLoadBalancerListenerRuleDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI log.Printf("[INFO] Deleting Listener Rule: %s", d.Id()) diff --git a/outscale/resource_outscale_load_balancer_policy.go b/outscale/resource_outscale_load_balancer_policy.go index af106e469..897c34af2 100644 --- a/outscale/resource_outscale_load_balancer_policy.go +++ b/outscale/resource_outscale_load_balancer_policy.go @@ -14,11 +14,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleAppCookieStickinessPolicy() *schema.Resource { +func resourceAppCookieStickinessPolicy() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleAppCookieStickinessPolicyCreate, - Read: resourceOutscaleAppCookieStickinessPolicyRead, - Delete: resourceOutscaleAppCookieStickinessPolicyDelete, + Create: resourceAppCookieStickinessPolicyCreate, + Read: resourceAppCookieStickinessPolicyRead, + Delete: resourceAppCookieStickinessPolicyDelete, Schema: map[string]*schema.Schema{ "policy_name": { @@ -193,7 +193,7 @@ func resourceOutscaleAppCookieStickinessPolicy() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "tags": tagsListOAPISchema2(true), + "tags": tagsListSchema2(true), "dns_name": { Type: schema.TypeString, @@ -238,8 +238,8 @@ func resourceOutscaleAppCookieStickinessPolicy() *schema.Resource { } } -func resourceOutscaleAppCookieStickinessPolicyCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceAppCookieStickinessPolicyCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI l := d.Get("load_balancer_name") pn := d.Get("policy_name") @@ -288,8 +288,8 @@ func resourceOutscaleAppCookieStickinessPolicyCreate(d *schema.ResourceData, met if resp.LoadBalancer != nil { lb := resp.LoadBalancer - d.Set("access_log", flattenOAPIAccessLog(lb.AccessLog)) - d.Set("listeners", flattenOAPIListeners(lb.Listeners)) + d.Set("access_log", flattenAccessLog(lb.AccessLog)) + d.Set("listeners", flattenListeners(lb.Listeners)) d.Set("subregion_names", flattenStringList(lb.SubregionNames)) d.Set("load_balancer_type", lb.LoadBalancerType) if lb.SecurityGroups != nil { @@ -299,7 +299,7 @@ func resourceOutscaleAppCookieStickinessPolicyCreate(d *schema.ResourceData, met } d.Set("dns_name", lb.DnsName) d.Set("subnets", flattenStringList(lb.Subnets)) - d.Set("health_check", flattenOAPIHealthCheck(lb.HealthCheck)) + d.Set("health_check", flattenHealthCheck(lb.HealthCheck)) d.Set("backend_vm_ids", flattenStringList(lb.BackendVmIds)) if lb.Tags != nil { ta := make([]map[string]interface{}, len(*lb.Tags)) @@ -358,12 +358,12 @@ func resourceOutscaleAppCookieStickinessPolicyCreate(d *schema.ResourceData, met return nil } -func resourceOutscaleAppCookieStickinessPolicyRead(d *schema.ResourceData, meta interface{}) error { +func resourceAppCookieStickinessPolicyRead(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceOutscaleAppCookieStickinessPolicyDelete(d *schema.ResourceData, meta interface{}) error { - elbconn := meta.(*OutscaleClient).OSCAPI +func resourceAppCookieStickinessPolicyDelete(d *schema.ResourceData, meta interface{}) error { + elbconn := meta.(*Client).OSCAPI l := d.Get("load_balancer_name").(string) p := d.Get("policy_name").(string) diff --git a/outscale/resource_outscale_load_balancer_policy_test.go b/outscale/resource_outscale_load_balancer_policy_test.go index c283bfd3a..1c2918eac 100644 --- a/outscale/resource_outscale_load_balancer_policy_test.go +++ b/outscale/resource_outscale_load_balancer_policy_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleCookieStickinessPolicy_basic(t *testing.T) { +func TestAccCookieStickinessPolicy_basic(t *testing.T) { t.Parallel() lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5)) region := os.Getenv("OUTSCALE_REGION") diff --git a/outscale/resource_outscale_load_balancer_test.go b/outscale/resource_outscale_load_balancer_test.go index 36fd44178..e26745e1d 100644 --- a/outscale/resource_outscale_load_balancer_test.go +++ b/outscale/resource_outscale_load_balancer_test.go @@ -16,7 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPILBUBasic(t *testing.T) { +func TestAccLBUBasic(t *testing.T) { t.Parallel() var conf oscgo.LoadBalancer @@ -32,12 +32,12 @@ func TestAccOutscaleOAPILBUBasic(t *testing.T) { }, IDRefreshName: resourceName, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPILBUDestroy, + CheckDestroy: testAccCheckLBUDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILBUConfig(r), + Config: testAccLBUConfig(r), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILBUExists(resourceName, &conf), + testAccCheckLBUExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "subregion_names.#", "1"), resource.TestCheckResourceAttr(resourceName, "subregion_names.0", zone), resource.TestCheckResourceAttr(resourceName, "listeners.#", "1"), @@ -47,7 +47,7 @@ func TestAccOutscaleOAPILBUBasic(t *testing.T) { }) } -func TestAccOutscaleOAPILBUPublicIp(t *testing.T) { +func TestAccLBUPublicIp(t *testing.T) { t.Parallel() var conf oscgo.LoadBalancer @@ -61,12 +61,12 @@ func TestAccOutscaleOAPILBUPublicIp(t *testing.T) { }, IDRefreshName: resourceName, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPILBUDestroy, + CheckDestroy: testAccCheckLBUDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILBUPublicIpConfig(r), + Config: testAccLBUPublicIpConfig(r), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILBUExists(resourceName, &conf), + testAccCheckLBUExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "listeners.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "public_ip"), )}, @@ -74,8 +74,8 @@ func TestAccOutscaleOAPILBUPublicIp(t *testing.T) { }) } -func testAccCheckOutscaleOAPILBUDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckLBUDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_load_balancer" { @@ -123,7 +123,7 @@ func testAccCheckOutscaleOAPILBUDestroy(s *terraform.State) error { return nil } -func testAccCheckOutscaleOAPILBUExists(n string, res *oscgo.LoadBalancer) resource.TestCheckFunc { +func testAccCheckLBUExists(n string, res *oscgo.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -134,7 +134,7 @@ func testAccCheckOutscaleOAPILBUExists(n string, res *oscgo.LoadBalancer) resour return fmt.Errorf("No LBU ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI var err error var resp oscgo.ReadLoadBalancersResponse @@ -179,7 +179,7 @@ func testAccCheckOutscaleOAPILBUExists(n string, res *oscgo.LoadBalancer) resour } } -func testAccOutscaleOAPILBUConfig(r int) string { +func testAccLBUConfig(r int) string { return fmt.Sprintf(` resource "outscale_load_balancer" "bar" { subregion_names = ["%sa"] @@ -203,7 +203,7 @@ resource "outscale_load_balancer" "bar" { `, os.Getenv("OUTSCALE_REGION"), r) } -func testAccOutscaleOAPILBUPublicIpConfig(r int) string { +func testAccLBUPublicIpConfig(r int) string { return fmt.Sprintf(` resource "outscale_public_ip" "my_public_ip" { diff --git a/outscale/resource_outscale_load_balancer_vms.go b/outscale/resource_outscale_load_balancer_vms.go index 145e6bf09..45777075a 100644 --- a/outscale/resource_outscale_load_balancer_vms.go +++ b/outscale/resource_outscale_load_balancer_vms.go @@ -13,11 +13,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPILBUAttachment() *schema.Resource { +func resourceLBUAttachment() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPILBUAttachmentCreate, - Read: resourceOutscaleOAPILBUAttachmentRead, - Delete: resourceOutscaleOAPILBUAttachmentDelete, + Create: resourceLBUAttachmentCreate, + Read: resourceLBUAttachmentRead, + Delete: resourceLBUAttachmentDelete, Schema: map[string]*schema.Schema{ "load_balancer_name": { @@ -40,8 +40,8 @@ func resourceOutscaleOAPILBUAttachment() *schema.Resource { } } -func resourceOutscaleOAPILBUAttachmentCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLBUAttachmentCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI e, eok := d.GetOk("load_balancer_name") i, iok := d.GetOk("backend_vm_ids") @@ -80,11 +80,11 @@ func resourceOutscaleOAPILBUAttachmentCreate(d *schema.ResourceData, meta interf d.SetId(resource.PrefixedUniqueId(fmt.Sprintf("%s-", e))) - return resourceOutscaleOAPILBUAttachmentRead(d, meta) + return resourceLBUAttachmentRead(d, meta) } -func resourceOutscaleOAPILBUAttachmentRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLBUAttachmentRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI found := false e := d.Get("load_balancer_name").(string) lb, _, err := readResourceLb(conn, e) @@ -111,8 +111,8 @@ func resourceOutscaleOAPILBUAttachmentRead(d *schema.ResourceData, meta interfac return nil } -func resourceOutscaleOAPILBUAttachmentDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLBUAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI e := d.Get("load_balancer_name").(string) i := d.Get("backend_vm_ids").([]interface{}) diff --git a/outscale/resource_outscale_load_balancer_vms_test.go b/outscale/resource_outscale_load_balancer_vms_test.go index d6c406f78..3f57ae545 100644 --- a/outscale/resource_outscale_load_balancer_vms_test.go +++ b/outscale/resource_outscale_load_balancer_vms_test.go @@ -11,7 +11,7 @@ import ( oscgo "github.com/outscale/osc-sdk-go/v2" ) -func TestAccOutscaleOAPILBUAttachment_basic(t *testing.T) { +func TestAccLBUAttachment_basic(t *testing.T) { t.Parallel() var conf oscgo.LoadBalancer omi := os.Getenv("OUTSCALE_IMAGEID") @@ -33,12 +33,12 @@ func TestAccOutscaleOAPILBUAttachment_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_load_balancer.bar", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPILBUDestroy, + CheckDestroy: testAccCheckLBUDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILBUAttachmentConfig1(omi, region), + Config: testAccLBUAttachmentConfig1(omi, region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILBUExists("outscale_load_balancer.bar", &conf), + testAccCheckLBUExists("outscale_load_balancer.bar", &conf), testCheckInstanceAttached(1), ), }, @@ -47,7 +47,7 @@ func TestAccOutscaleOAPILBUAttachment_basic(t *testing.T) { } // add one attachment -func testAccOutscaleOAPILBUAttachmentConfig1(omi, region string) string { +func testAccLBUAttachmentConfig1(omi, region string) string { return fmt.Sprintf(` resource "outscale_load_balancer" "bar" { load_balancer_name = "load-test12" diff --git a/outscale/resource_outscale_nat_service.go b/outscale/resource_outscale_nat_service.go index a7e4c1f5f..f577f951b 100644 --- a/outscale/resource_outscale_nat_service.go +++ b/outscale/resource_outscale_nat_service.go @@ -13,12 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPINatService() *schema.Resource { +func resourceNatService() *schema.Resource { return &schema.Resource{ - Create: resourceOAPINatServiceCreate, - Read: resourceOAPINatServiceRead, - Delete: resourceOAPINatServiceDelete, - Update: resourceOutscaleOAPINatServiceUpdate, + Create: resourceNatServiceCreate, + Read: resourceNatServiceRead, + Delete: resourceNatServiceDelete, + Update: resourceNatServiceUpdate, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -66,13 +66,13 @@ func resourceOutscaleOAPINatService() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), }, } } -func resourceOAPINatServiceCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNatServiceCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.CreateNatServiceRequest{ PublicIpId: d.Get("public_ip_id").(string), @@ -112,7 +112,7 @@ func resourceOAPINatServiceCreate(d *schema.ResourceData, meta interface{}) erro stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: []string{"available"}, - Refresh: NGOAPIStateRefreshFunc(conn, filterReq, "failed"), + Refresh: NGStateRefreshFunc(conn, filterReq, "failed"), Timeout: 10 * time.Minute, } @@ -129,11 +129,11 @@ func resourceOAPINatServiceCreate(d *schema.ResourceData, meta interface{}) erro d.SetId(natService.GetNatServiceId()) - return resourceOAPINatServiceRead(d, meta) + return resourceNatServiceRead(d, meta) } -func resourceOAPINatServiceRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNatServiceRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI filterReq := oscgo.ReadNatServicesRequest{ Filters: &oscgo.FiltersNatService{NatServiceIds: &[]string{d.Id()}}, @@ -142,7 +142,7 @@ func resourceOAPINatServiceRead(d *schema.ResourceData, meta interface{}) error stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: []string{"available", "deleted"}, - Refresh: NGOAPIStateRefreshFunc(conn, filterReq, "failed"), + Refresh: NGStateRefreshFunc(conn, filterReq, "failed"), Timeout: 10 * time.Minute, } @@ -177,7 +177,7 @@ func resourceOAPINatServiceRead(d *schema.ResourceData, meta interface{}) error } public_ips := natService.GetPublicIps() - if err := set("public_ips", getOSCPublicIPs(public_ips)); err != nil { + if err := set("public_ips", flattenPublicIPs(public_ips)); err != nil { return err } @@ -185,7 +185,7 @@ func resourceOAPINatServiceRead(d *schema.ResourceData, meta interface{}) error return err } - if err := d.Set("tags", tagsOSCAPIToMap(natService.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(natService.GetTags())); err != nil { fmt.Printf("[WARN] ERROR TAGS PROBLEME (%s)", err) } @@ -193,23 +193,23 @@ func resourceOAPINatServiceRead(d *schema.ResourceData, meta interface{}) error }) } -func resourceOutscaleOAPINatServiceUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNatServiceUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOAPINatServiceRead(d, meta) + return resourceNatServiceRead(d, meta) } -func resourceOAPINatServiceDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNatServiceDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI log.Printf("[INFO] Deleting NAT Service: %s\n", d.Id()) err := resource.Retry(120*time.Second, func() *resource.RetryError { @@ -233,7 +233,7 @@ func resourceOAPINatServiceDelete(d *schema.ResourceData, meta interface{}) erro stateConf := &resource.StateChangeConf{ Pending: []string{"deleting"}, Target: []string{"deleted", "available"}, - Refresh: NGOAPIStateRefreshFunc(conn, filterReq, "failed"), + Refresh: NGStateRefreshFunc(conn, filterReq, "failed"), Timeout: 30 * time.Minute, Delay: 10 * time.Second, MinTimeout: 10 * time.Second, @@ -246,9 +246,9 @@ func resourceOAPINatServiceDelete(d *schema.ResourceData, meta interface{}) erro return nil } -// NGOAPIStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch +// NGStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch // a NAT Service. -func NGOAPIStateRefreshFunc(client *oscgo.APIClient, req oscgo.ReadNatServicesRequest, failState string) resource.StateRefreshFunc { +func NGStateRefreshFunc(client *oscgo.APIClient, req oscgo.ReadNatServicesRequest, failState string) resource.StateRefreshFunc { return func() (interface{}, string, error) { var resp oscgo.ReadNatServicesResponse err := resource.Retry(120*time.Second, func() *resource.RetryError { @@ -278,7 +278,7 @@ func NGOAPIStateRefreshFunc(client *oscgo.APIClient, req oscgo.ReadNatServicesRe } } -func getOSCPublicIPs(publicIps []oscgo.PublicIpLight) (res []map[string]interface{}) { +func flattenPublicIPs(publicIps []oscgo.PublicIpLight) (res []map[string]interface{}) { for _, p := range publicIps { res = append(res, map[string]interface{}{ "public_ip_id": p.GetPublicIpId(), diff --git a/outscale/resource_outscale_nat_service_test.go b/outscale/resource_outscale_nat_service_test.go index 612701665..0329e4279 100644 --- a/outscale/resource_outscale_nat_service_test.go +++ b/outscale/resource_outscale_nat_service_test.go @@ -13,44 +13,44 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPINatService_basic(t *testing.T) { +func TestAccNatService_basic(t *testing.T) { var natService oscgo.NatService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPINatGatewayDestroy, + CheckDestroy: testAccCheckNatGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPINatGatewayConfig, + Config: testAccNatGatewayConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOAPINatGatewayExists("outscale_nat_service.outscale_nat_service", &natService), + testAccCheckNatGatewayExists("outscale_nat_service.outscale_nat_service", &natService), ), }, }, }) } -func TestAccOutscaleOAPINatService_basicWithDataSource(t *testing.T) { +func TestAccNatService_basicWithDataSource(t *testing.T) { var natService oscgo.NatService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPINatGatewayDestroy, + CheckDestroy: testAccCheckNatGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPINatGatewayConfigWithDataSource, + Config: testAccNatGatewayConfigWithDataSource, Check: resource.ComposeTestCheckFunc( - testAccCheckOAPINatGatewayExists("outscale_nat_service.outscale_nat_service", &natService), + testAccCheckNatGatewayExists("outscale_nat_service.outscale_nat_service", &natService), ), }, }, }) } -func testAccCheckOAPINatGatewayDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckNatGatewayDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_nat_service" { @@ -78,7 +78,7 @@ func testAccCheckOAPINatGatewayDestroy(s *terraform.State) error { return nil } -func testAccCheckOAPINatGatewayExists(n string, ns *oscgo.NatService) resource.TestCheckFunc { +func testAccCheckNatGatewayExists(n string, ns *oscgo.NatService) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -89,7 +89,7 @@ func testAccCheckOAPINatGatewayExists(n string, ns *oscgo.NatService) resource.T return fmt.Errorf("No ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI filterReq := oscgo.ReadNatServicesRequest{ Filters: &oscgo.FiltersNatService{NatServiceIds: &[]string{rs.Primary.ID}}, @@ -115,7 +115,7 @@ func testAccCheckOAPINatGatewayExists(n string, ns *oscgo.NatService) resource.T } } -const testAccOAPINatGatewayConfig = ` +const testAccNatGatewayConfig = ` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -162,7 +162,7 @@ const testAccOAPINatGatewayConfig = ` } ` -const testAccOAPINatGatewayConfigWithDataSource = ` +const testAccNatGatewayConfigWithDataSource = ` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_net.go b/outscale/resource_outscale_net.go index e83c144bb..0dcc672f9 100644 --- a/outscale/resource_outscale_net.go +++ b/outscale/resource_outscale_net.go @@ -13,22 +13,22 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPINet() *schema.Resource { +func resourceNet() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPINetCreate, - Read: resourceOutscaleOAPINetRead, - Update: resourceOutscaleOAPINetUpdate, - Delete: resourceOutscaleOAPINetDelete, + Create: resourceNetCreate, + Read: resourceNetRead, + Update: resourceNetUpdate, + Delete: resourceNetDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, - Schema: getOAPINetSchema(), + Schema: getNetSchema(), } } -func resourceOutscaleOAPINetCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.CreateNetRequest{ IpRange: d.Get("ip_range").(string), @@ -70,7 +70,7 @@ func resourceOutscaleOAPINetCreate(d *schema.ResourceData, meta interface{}) err d.SetId(resp.Net.GetNetId()) return resource.Retry(120*time.Second, func() *resource.RetryError { - err = resourceOutscaleOAPINetRead(d, meta) + err = resourceNetRead(d, meta) if err != nil { return resource.NonRetryableError(err) } @@ -84,8 +84,8 @@ func resourceOutscaleOAPINetCreate(d *schema.ResourceData, meta interface{}) err }) } -func resourceOutscaleOAPINetRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() @@ -133,26 +133,26 @@ func resourceOutscaleOAPINetRead(d *schema.ResourceData, meta interface{}) error return err } - return d.Set("tags", tagsOSCAPIToMap(resp.GetNets()[0].GetTags())) + return d.Set("tags", tagsToMap(resp.GetNets()[0].GetTags())) } -func resourceOutscaleOAPINetUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOutscaleOAPINetRead(d, meta) + return resourceNetRead(d, meta) } -func resourceOutscaleOAPINetDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() @@ -191,7 +191,7 @@ func resourceOutscaleOAPINetDelete(d *schema.ResourceData, meta interface{}) err return nil } -func getOAPINetSchema() map[string]*schema.Schema { +func getNetSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ "ip_range": { Type: schema.TypeString, @@ -214,7 +214,7 @@ func getOAPINetSchema() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "net_id": { Type: schema.TypeString, Computed: true, diff --git a/outscale/resource_outscale_net_access_point.go b/outscale/resource_outscale_net_access_point.go index 46eb576b8..e2e344795 100644 --- a/outscale/resource_outscale_net_access_point.go +++ b/outscale/resource_outscale_net_access_point.go @@ -13,12 +13,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleNetAccessPoint() *schema.Resource { +func resourceNetAccessPoint() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleNetAccessPointCreate, - Read: resourceOutscaleNetAccessPointRead, - Delete: resourceOutscaleNetAccessPointDelete, - Update: resourceOutscaleNetAccessPointUpdate, + Create: resourceNetAccessPointCreate, + Read: resourceNetAccessPointRead, + Delete: resourceNetAccessPointDelete, + Update: resourceNetAccessPointUpdate, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -47,7 +47,7 @@ func resourceOutscaleNetAccessPoint() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "request_id": { Type: schema.TypeString, Computed: true, @@ -56,8 +56,8 @@ func resourceOutscaleNetAccessPoint() *schema.Resource { } } -func resourceOutscaleNetAccessPointUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetAccessPointUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI if d.HasChange("route_table_ids") { o, n := d.GetChange("route_table_ids") @@ -117,7 +117,7 @@ func resourceOutscaleNetAccessPointUpdate(d *schema.ResourceData, meta interface d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } @@ -125,7 +125,7 @@ func resourceOutscaleNetAccessPointUpdate(d *schema.ResourceData, meta interface d.Partial(false) } - return resourceOutscaleNetAccessPointRead(d, meta) + return resourceNetAccessPointRead(d, meta) } func napStateRefreshFunc(conn *oscgo.APIClient, id string) resource.StateRefreshFunc { @@ -164,8 +164,8 @@ func napStateRefreshFunc(conn *oscgo.APIClient, id string) resource.StateRefresh } } -func resourceOutscaleNetAccessPointCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetAccessPointCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := &oscgo.CreateNetAccessPointRequest{} @@ -222,11 +222,11 @@ func resourceOutscaleNetAccessPointCreate(d *schema.ResourceData, meta interface d.Set("net_access_point_id", id) d.SetId(id) - return resourceOutscaleNetAccessPointRead(d, meta) + return resourceNetAccessPointRead(d, meta) } -func resourceOutscaleNetAccessPointRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetAccessPointRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI napid := d.Id() @@ -266,14 +266,14 @@ func resourceOutscaleNetAccessPointRead(d *schema.ResourceData, meta interface{} d.Set("net_id", nap.NetId) d.Set("service_name", nap.ServiceName) d.Set("state", nap.State) - d.Set("tags", tagsOSCAPIToMap(nap.GetTags())) + d.Set("tags", tagsToMap(nap.GetTags())) d.Set("net_access_point_id", nap.GetNetAccessPointId()) return nil } -func resourceOutscaleNetAccessPointDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetAccessPointDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := &oscgo.DeleteNetAccessPointRequest{ NetAccessPointId: d.Id(), diff --git a/outscale/resource_outscale_net_access_point_test.go b/outscale/resource_outscale_net_access_point_test.go index 1853117a9..0b92c59c8 100644 --- a/outscale/resource_outscale_net_access_point_test.go +++ b/outscale/resource_outscale_net_access_point_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPINetAccessPoint_basic(t *testing.T) { +func TestAccNetAccessPoint_basic(t *testing.T) { ServiceName := fmt.Sprintf("com.outscale.%s.api", os.Getenv("OUTSCALE_REGION")) resource.Test(t, resource.TestCase{ @@ -18,13 +18,13 @@ func TestAccOutscaleOAPINetAccessPoint_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPINetAccessPointConfig(ServiceName), + Config: testAccNetAccessPointConfig(ServiceName), }, }, }) } -func testAccOutscaleOAPINetAccessPointConfig(sName string) string { +func testAccNetAccessPointConfig(sName string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_net_attributes.go b/outscale/resource_outscale_net_attributes.go index 53bdb5555..2b4b41ca7 100644 --- a/outscale/resource_outscale_net_attributes.go +++ b/outscale/resource_outscale_net_attributes.go @@ -13,12 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPILinAttributes() *schema.Resource { +func resourceLinAttributes() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPILinAttrCreate, - Read: resourceOutscaleOAPILinAttrRead, - Update: resourceOutscaleOAPILinAttrUpdate, - Delete: resourceOutscaleOAPILinAttrDelete, + Create: resourceLinAttrCreate, + Read: resourceLinAttrRead, + Update: resourceLinAttrUpdate, + Delete: resourceLinAttrDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -49,13 +49,13 @@ func resourceOutscaleOAPILinAttributes() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsOAPIListSchemaComputed(), + "tags": tagsListSchemaComputed(), }, } } -func resourceOutscaleOAPILinAttrCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLinAttrCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.UpdateNetRequest{ NetId: d.Get("net_id").(string), @@ -84,11 +84,11 @@ func resourceOutscaleOAPILinAttrCreate(d *schema.ResourceData, meta interface{}) d.SetId(resp.Net.GetNetId()) - return resourceOutscaleOAPILinAttrRead(d, meta) + return resourceLinAttrRead(d, meta) } -func resourceOutscaleOAPILinAttrUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLinAttrUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.UpdateNetRequest{ NetId: d.Get("net_id").(string), @@ -108,11 +108,11 @@ func resourceOutscaleOAPILinAttrUpdate(d *schema.ResourceData, meta interface{}) d.SetId(d.Get("net_id").(string)) - return resourceOutscaleOAPILinAttrRead(d, meta) + return resourceLinAttrRead(d, meta) } -func resourceOutscaleOAPILinAttrRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLinAttrRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadNetsRequest{ Filters: &oscgo.FiltersNet{ @@ -152,10 +152,10 @@ func resourceOutscaleOAPILinAttrRead(d *schema.ResourceData, meta interface{}) e d.Set("net_id", resp.GetNets()[0].GetNetId()) d.Set("state", resp.GetNets()[0].GetState()) - return d.Set("tags", tagsOSCAPIToMap(resp.GetNets()[0].GetTags())) + return d.Set("tags", tagsToMap(resp.GetNets()[0].GetTags())) } -func resourceOutscaleOAPILinAttrDelete(d *schema.ResourceData, meta interface{}) error { +func resourceLinAttrDelete(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil diff --git a/outscale/resource_outscale_net_attributes_test.go b/outscale/resource_outscale_net_attributes_test.go index 049b184f1..7d2e54f1f 100644 --- a/outscale/resource_outscale_net_attributes_test.go +++ b/outscale/resource_outscale_net_attributes_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPILinAttr_basic(t *testing.T) { +func TestAccLinAttr_basic(t *testing.T) { resourceName := "outscale_net_attributes.outscale_net_attributes" resource.Test(t, resource.TestCase{ @@ -15,7 +15,7 @@ func TestAccOutscaleOAPILinAttr_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILinAttrConfig, + Config: testAccLinAttrConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "dhcp_options_set_id"), resource.TestCheckResourceAttrSet(resourceName, "net_id"), @@ -25,7 +25,7 @@ func TestAccOutscaleOAPILinAttr_basic(t *testing.T) { }) } -func TestAccOutscaleOAPILinAttr_withoutDHCPID(t *testing.T) { +func TestAccLinAttr_withoutDHCPID(t *testing.T) { resourceName := "outscale_net_attributes.outscale_net_attributes" resource.Test(t, resource.TestCase{ @@ -33,14 +33,14 @@ func TestAccOutscaleOAPILinAttr_withoutDHCPID(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILinAttrConfigwithoutDHCPID("outscale_net.vpc.id"), + Config: testAccLinAttrConfigwithoutDHCPID("outscale_net.vpc.id"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "dhcp_options_set_id"), resource.TestCheckResourceAttrSet(resourceName, "net_id"), ), }, { - Config: testAccOutscaleOAPILinAttrConfigwithoutDHCPID("outscale_net.vpc2.id"), + Config: testAccLinAttrConfigwithoutDHCPID("outscale_net.vpc2.id"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "dhcp_options_set_id"), resource.TestCheckResourceAttrSet(resourceName, "net_id"), @@ -50,7 +50,7 @@ func TestAccOutscaleOAPILinAttr_withoutDHCPID(t *testing.T) { }) } -const testAccOutscaleOAPILinAttrConfig = ` +const testAccLinAttrConfig = ` resource "outscale_net" "vpc" { ip_range = "10.0.0.0/16" @@ -75,7 +75,7 @@ const testAccOutscaleOAPILinAttrConfig = ` } ` -func testAccOutscaleOAPILinAttrConfigwithoutDHCPID(vpc string) string { +func testAccLinAttrConfigwithoutDHCPID(vpc string) string { return fmt.Sprintf(` resource "outscale_net" "vpc" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_net_peering.go b/outscale/resource_outscale_net_peering.go index afc48965d..fd1927b76 100644 --- a/outscale/resource_outscale_net_peering.go +++ b/outscale/resource_outscale_net_peering.go @@ -17,12 +17,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPILinPeeringConnection() *schema.Resource { +func resourceLinPeeringConnection() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPILinPeeringCreate, - Read: resourceOutscaleOAPILinPeeringRead, - Update: resourceOutscaleOAPINetPeeringUpdate, - Delete: resourceOutscaleOAPILinPeeringDelete, + Create: resourceLinPeeringCreate, + Read: resourceLinPeeringRead, + Update: resourceNetPeeringUpdate, + Delete: resourceLinPeeringDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -66,9 +66,9 @@ func resourceOutscaleOAPILinPeeringConnection() *schema.Resource { }, }, }, - "accepter_net": vpcOAPIPeeringConnectionOptionsSchema(), - "source_net": vpcOAPIPeeringConnectionOptionsSchema(), - "tags": tagsListOAPISchema(), + "accepter_net": vpcPeeringConnectionOptionsSchema(), + "source_net": vpcPeeringConnectionOptionsSchema(), + "tags": tagsListSchema(), "request_id": { Type: schema.TypeString, Computed: true, @@ -77,8 +77,8 @@ func resourceOutscaleOAPILinPeeringConnection() *schema.Resource { } } -func resourceOutscaleOAPILinPeeringCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLinPeeringCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI // Create the vpc peering connection createOpts := oscgo.CreateNetPeeringRequest{ @@ -123,7 +123,7 @@ func resourceOutscaleOAPILinPeeringCreate(d *schema.ResourceData, meta interface stateConf := &resource.StateChangeConf{ Pending: []string{"initiating-request", "provisioning", "pending"}, Target: []string{"pending-acceptance", "active"}, - Refresh: resourceOutscaleOAPILinPeeringConnectionStateRefreshFunc(conn, d.Id()), + Refresh: resourceLinPeeringConnectionStateRefreshFunc(conn, d.Id()), Timeout: 1 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { @@ -132,11 +132,11 @@ func resourceOutscaleOAPILinPeeringCreate(d *schema.ResourceData, meta interface d.Id()), err) } - return resourceOutscaleOAPILinPeeringRead(d, meta) + return resourceLinPeeringRead(d, meta) } -func resourceOutscaleOAPILinPeeringRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLinPeeringRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var resp oscgo.ReadNetPeeringsResponse var err error err = resource.Retry(5*time.Minute, func() *resource.RetryError { @@ -225,30 +225,30 @@ func resourceOutscaleOAPILinPeeringRead(d *schema.ResourceData, meta interface{} if err := d.Set("net_peering_id", pc.GetNetPeeringId()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(pc.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(pc.GetTags())); err != nil { return errwrap.Wrapf("Error setting Net Peering tags: {{err}}", err) } return nil } -func resourceOutscaleOAPINetPeeringUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetPeeringUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOutscaleOAPILinPeeringRead(d, meta) + return resourceLinPeeringRead(d, meta) } -func resourceOutscaleOAPILinPeeringDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLinPeeringDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var err error err = resource.Retry(5*time.Minute, func() *resource.RetryError { @@ -270,9 +270,9 @@ func resourceOutscaleOAPILinPeeringDelete(d *schema.ResourceData, meta interface return nil } -// resourceOutscaleOAPILinPeeringConnectionStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch +// resourceLinPeeringConnectionStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch // a VPCPeeringConnection. -func resourceOutscaleOAPILinPeeringConnectionStateRefreshFunc(conn *oscgo.APIClient, id string) resource.StateRefreshFunc { +func resourceLinPeeringConnectionStateRefreshFunc(conn *oscgo.APIClient, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { var resp oscgo.ReadNetPeeringsResponse var err error @@ -311,7 +311,7 @@ func resourceOutscaleOAPILinPeeringConnectionStateRefreshFunc(conn *oscgo.APICli } } -func vpcOAPIPeeringConnectionOptionsSchema() *schema.Schema { +func vpcPeeringConnectionOptionsSchema() *schema.Schema { return &schema.Schema{ Type: schema.TypeMap, Computed: true, diff --git a/outscale/resource_outscale_net_peering_acceptation.go b/outscale/resource_outscale_net_peering_acceptation.go index ff947fa85..f8a6872f9 100644 --- a/outscale/resource_outscale_net_peering_acceptation.go +++ b/outscale/resource_outscale_net_peering_acceptation.go @@ -13,11 +13,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPILinPeeringConnectionAccepter() *schema.Resource { +func resourceLinPeeringConnectionAccepter() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPILinPeeringAccepterCreate, - Read: resourceOutscaleOAPILinPeeringRead, - Delete: resourceOutscaleOAPILinPeeringAccepterDelete, + Create: resourceLinPeeringAccepterCreate, + Read: resourceLinPeeringRead, + Delete: resourceLinPeeringAccepterDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -46,9 +46,9 @@ func resourceOutscaleOAPILinPeeringConnectionAccepter() *schema.Resource { }, }, }, - "accepter_net": vpcOAPIPeeringConnectionOptionsSchema(), - "source_net": vpcOAPIPeeringConnectionOptionsSchema(), - "tags": tagsOAPIListSchemaComputed(), + "accepter_net": vpcPeeringConnectionOptionsSchema(), + "source_net": vpcPeeringConnectionOptionsSchema(), + "tags": tagsListSchemaComputed(), "request_id": { Type: schema.TypeString, Computed: true, @@ -65,8 +65,8 @@ func resourceOutscaleOAPILinPeeringConnectionAccepter() *schema.Resource { } } -func resourceOutscaleOAPILinPeeringAccepterCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLinPeeringAccepterCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Get("net_peering_id").(string) d.SetId(id) @@ -90,10 +90,10 @@ func resourceOutscaleOAPILinPeeringAccepterCreate(d *schema.ResourceData, meta i return fmt.Errorf("Error creating Net Peering accepter. Details: %s", errString) } - return resourceOutscaleOAPILinPeeringRead(d, meta) + return resourceLinPeeringRead(d, meta) } -func resourceOutscaleOAPILinPeeringAccepterDelete(d *schema.ResourceData, meta interface{}) error { +func resourceLinPeeringAccepterDelete(d *schema.ResourceData, meta interface{}) error { log.Printf("[WARN] Will not delete VPC peering connection. Terraform will remove this resource from the state file, however resources may remain.") d.SetId("") return nil diff --git a/outscale/resource_outscale_net_peering_acceptation_test.go b/outscale/resource_outscale_net_peering_acceptation_test.go index 90444e631..a8e9a691b 100644 --- a/outscale/resource_outscale_net_peering_acceptation_test.go +++ b/outscale/resource_outscale_net_peering_acceptation_test.go @@ -8,23 +8,23 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPILinPeeringConnectionAccepter_sameAccount(t *testing.T) { +func TestAccLinPeeringConnectionAccepter_sameAccount(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccOutscaleOAPILinPeeringConnectionAccepterDestroy, + CheckDestroy: testAccLinPeeringConnectionAccepterDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILinPeeringConnectionAccepterSameAccountConfig, + Config: testAccLinPeeringConnectionAccepterSameAccountConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILinPeeringConnectionAccepterExists("outscale_net_peering_acceptation.peer"), + testAccCheckLinPeeringConnectionAccepterExists("outscale_net_peering_acceptation.peer"), ), }, }, }) } -func testAccCheckOutscaleOAPILinPeeringConnectionAccepterExists(n string) resource.TestCheckFunc { +func testAccCheckLinPeeringConnectionAccepterExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -38,12 +38,12 @@ func testAccCheckOutscaleOAPILinPeeringConnectionAccepterExists(n string) resour } } -func testAccOutscaleOAPILinPeeringConnectionAccepterDestroy(s *terraform.State) error { +func testAccLinPeeringConnectionAccepterDestroy(s *terraform.State) error { // We don't destroy the underlying VPC Peering Connection. return nil } -const testAccOutscaleOAPILinPeeringConnectionAccepterSameAccountConfig = ` +const testAccLinPeeringConnectionAccepterSameAccountConfig = ` resource "outscale_net" "foo" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_net_peering_test.go b/outscale/resource_outscale_net_peering_test.go index 29d38ad4c..dff7db266 100644 --- a/outscale/resource_outscale_net_peering_test.go +++ b/outscale/resource_outscale_net_peering_test.go @@ -14,19 +14,19 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPILinPeeringConnection_basic(t *testing.T) { +func TestAccLinPeeringConnection_basic(t *testing.T) { var connection oscgo.NetPeering resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_net_peering.foo", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPILinPeeringConnectionDestroy, + CheckDestroy: testAccCheckLinPeeringConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVpcPeeringConfig, + Config: testAccVpcPeeringConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILinPeeringConnectionExists( + testAccCheckLinPeeringConnectionExists( "outscale_net_peering.foo", &connection), ), @@ -35,20 +35,20 @@ func TestAccOutscaleOAPILinPeeringConnection_basic(t *testing.T) { }) } -func TestAccOutscaleOAPILinPeeringConnection_importBasic(t *testing.T) { +func TestAccLinPeeringConnection_importBasic(t *testing.T) { resourceName := "outscale_net_peering.foo" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPILinPeeringConnectionDestroy, + CheckDestroy: testAccCheckLinPeeringConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVpcPeeringConfig, + Config: testAccVpcPeeringConfig, }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOutscaleOAPILinkPeeeringConnectionImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckLinkPeeeringConnectionImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id"}, @@ -57,7 +57,7 @@ func TestAccOutscaleOAPILinPeeringConnection_importBasic(t *testing.T) { }) } -func testAccCheckOutscaleOAPILinkPeeeringConnectionImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckLinkPeeeringConnectionImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -67,12 +67,12 @@ func testAccCheckOutscaleOAPILinkPeeeringConnectionImportStateIDFunc(resourceNam } } -func TestAccOutscaleOAPILinPeeringConnection_plan(t *testing.T) { +func TestAccLinPeeringConnection_plan(t *testing.T) { var connection oscgo.NetPeering // reach out and DELETE the VPC Peering connection outside of Terraform testDestroy := func(*terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI log.Printf("[DEBUG] Test deleting the Net Peering.") err := resource.Retry(3*time.Minute, func() *resource.RetryError { _, httpResp, err := conn.NetPeeringApi.DeleteNetPeering(context.Background()).DeleteNetPeeringRequest(oscgo.DeleteNetPeeringRequest{ @@ -93,12 +93,12 @@ func TestAccOutscaleOAPILinPeeringConnection_plan(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPILinPeeringConnectionDestroy, + CheckDestroy: testAccCheckLinPeeringConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVpcPeeringConfig, + Config: testAccVpcPeeringConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILinPeeringConnectionExists( + testAccCheckLinPeeringConnectionExists( "outscale_net_peering.foo", &connection), testDestroy, @@ -109,8 +109,8 @@ func TestAccOutscaleOAPILinPeeringConnection_plan(t *testing.T) { }) } -func testAccCheckOutscaleOAPILinPeeringConnectionDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckLinPeeringConnectionDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_net_peering" { @@ -159,12 +159,12 @@ func testAccCheckOutscaleOAPILinPeeringConnectionDestroy(s *terraform.State) err // return error here; we've found the vpc_peering object we want, however // it's not in an expected state - return fmt.Errorf("Fall through error for testAccCheckOutscaleOAPILinPeeringConnectionDestroy") + return fmt.Errorf("Fall through error for testAccCheckLinPeeringConnectionDestroy") } return nil } -func testAccCheckOutscaleOAPILinPeeringConnectionExists(n string, connection *oscgo.NetPeering) resource.TestCheckFunc { +func testAccCheckLinPeeringConnectionExists(n string, connection *oscgo.NetPeering) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -175,7 +175,7 @@ func testAccCheckOutscaleOAPILinPeeringConnectionExists(n string, connection *os return fmt.Errorf("No Net Peering ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI var resp oscgo.ReadNetPeeringsResponse var err error @@ -208,7 +208,7 @@ func testAccCheckOutscaleOAPILinPeeringConnectionExists(n string, connection *os } } -const testAccOAPIVpcPeeringConfig = ` +const testAccVpcPeeringConfig = ` resource "outscale_net" "foo" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_net_test.go b/outscale/resource_outscale_net_test.go index eecece9f1..1ea60c306 100644 --- a/outscale/resource_outscale_net_test.go +++ b/outscale/resource_outscale_net_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPILin_basic(t *testing.T) { +func TestAccLin_basic(t *testing.T) { t.Parallel() var conf1 oscgo.Net var conf2 oscgo.Net @@ -21,13 +21,13 @@ func TestAccOutscaleOAPILin_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - // CheckDestroy: testAccCheckOutscaleLinDestroyed, // we need to create the destroyed test case + // CheckDestroy: testAccCheckLinDestroyed, // we need to create the destroyed test case Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILinConfig, + Config: testAccLinConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILinExists("outscale_net.vpc.0", &conf1), - testAccCheckOutscaleOAPILinExists("outscale_net.vpc.1", &conf2), + testAccCheckLinExists("outscale_net.vpc.0", &conf1), + testAccCheckLinExists("outscale_net.vpc.1", &conf2), resource.TestCheckResourceAttr( "outscale_net.vpc.0", "ip_range", "10.0.0.0/16"), resource.TestCheckResourceAttr( @@ -38,26 +38,26 @@ func TestAccOutscaleOAPILin_basic(t *testing.T) { }) } -func TestAccOutscaleOAPILin_UpdateTags(t *testing.T) { +func TestAccLin_UpdateTags(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPINICDestroy, + CheckDestroy: testAccCheckNICDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILinConfigUpdateTags("Terraform_net"), + Config: testAccLinConfigUpdateTags("Terraform_net"), Check: resource.ComposeTestCheckFunc(), }, { - Config: testAccOutscaleOAPILinConfigUpdateTags("Terraform_net2"), + Config: testAccLinConfigUpdateTags("Terraform_net2"), Check: resource.ComposeTestCheckFunc(), }, }, }) } -func testAccCheckOutscaleOAPILinExists(n string, res *oscgo.Net) resource.TestCheckFunc { +func testAccCheckLinExists(n string, res *oscgo.Net) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -68,7 +68,7 @@ func testAccCheckOutscaleOAPILinExists(n string, res *oscgo.Net) resource.TestCh return fmt.Errorf("No internet gateway id is set") } var resp oscgo.ReadNetsResponse - conn := testAccProvider.Meta().(*OutscaleClient) + conn := testAccProvider.Meta().(*Client) err := resource.Retry(5*time.Minute, func() *resource.RetryError { rp, httpResp, err := conn.OSCAPI.NetApi.ReadNets(context.Background()).ReadNetsRequest(oscgo.ReadNetsRequest{ @@ -95,7 +95,7 @@ func testAccCheckOutscaleOAPILinExists(n string, res *oscgo.Net) resource.TestCh } } -const testAccOutscaleOAPILinConfig = ` +const testAccLinConfig = ` resource "outscale_net" "vpc" { ip_range = "10.0.0.0/16" count = 2 @@ -107,7 +107,7 @@ const testAccOutscaleOAPILinConfig = ` } ` -func testAccOutscaleOAPILinConfigUpdateTags(value string) string { +func testAccLinConfigUpdateTags(value string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_nic.go b/outscale/resource_outscale_nic.go index 52a18c4fc..cc2f10e91 100644 --- a/outscale/resource_outscale_nic.go +++ b/outscale/resource_outscale_nic.go @@ -19,12 +19,12 @@ import ( ) // Creates a network interface in the specified subnet -func resourceOutscaleOAPINic() *schema.Resource { +func resourceNic() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPINicCreate, - Read: resourceOutscaleOAPINicRead, - Update: resourceOutscaleOAPINicUpdate, - Delete: resourceOutscaleOAPINicDelete, + Create: resourceNicCreate, + Read: resourceNicRead, + Update: resourceNicUpdate, + Delete: resourceNicDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -32,13 +32,13 @@ func resourceOutscaleOAPINic() *schema.Resource { Create: schema.DefaultTimeout(10 * time.Minute), Delete: schema.DefaultTimeout(10 * time.Minute), }, - Schema: getOAPINicSchema(), + Schema: getNicSchema(), } } -func getOAPINicSchema() map[string]*schema.Schema { +func getNicSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ - // This is attribute part for schema OAPINic + // This is attribute part for schema Nic "description": { Type: schema.TypeString, Optional: true, @@ -225,7 +225,7 @@ func getOAPINicSchema() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "net_id": { Type: schema.TypeString, Computed: true, @@ -233,10 +233,10 @@ func getOAPINicSchema() map[string]*schema.Schema { } } -// Create OAPINic -func resourceOutscaleOAPINicCreate(d *schema.ResourceData, meta interface{}) error { +// Create Nic +func resourceNicCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI request := oscgo.CreateNicRequest{ SubnetId: d.Get("subnet_id").(string), @@ -279,7 +279,7 @@ func resourceOutscaleOAPINicCreate(d *schema.ResourceData, meta interface{}) err d.SetId(resp.Nic.GetNicId()) if d.IsNewResource() { - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") @@ -294,14 +294,14 @@ func resourceOutscaleOAPINicCreate(d *schema.ResourceData, meta interface{}) err log.Printf("[INFO] ENI ID: %s", d.Id()) - return resourceOutscaleOAPINicRead(d, meta) + return resourceNicRead(d, meta) } -// Read OAPINic -func resourceOutscaleOAPINicRead(d *schema.ResourceData, meta interface{}) error { +// Read Nic +func resourceNicRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI dnir := oscgo.ReadNicsRequest{ Filters: &oscgo.FiltersNic{ NicIds: &[]string{d.Id()}, @@ -438,7 +438,7 @@ func resourceOutscaleOAPINicRead(d *schema.ResourceData, meta interface{}) error if err := d.Set("state", eni.GetState()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(eni.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(eni.GetTags())); err != nil { return err } if err := d.Set("net_id", eni.GetNetId()); err != nil { @@ -448,14 +448,14 @@ func resourceOutscaleOAPINicRead(d *schema.ResourceData, meta interface{}) error return nil } -// Delete OAPINic -func resourceOutscaleOAPINicDelete(d *schema.ResourceData, meta interface{}) error { +// Delete Nic +func resourceNicDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI log.Printf("[INFO] Deleting ENI: %s", d.Id()) - err := resourceOutscaleOAPINicDetach(meta, d.Id()) + err := resourceNicDetach(meta, d.Id()) if err != nil { return err } @@ -480,9 +480,9 @@ func resourceOutscaleOAPINicDelete(d *schema.ResourceData, meta interface{}) err return nil } -func resourceOutscaleOAPINicDetach(meta interface{}, nicID string) error { +func resourceNicDetach(meta interface{}, nicID string) error { // if there was an old nic_link, remove it - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI stateConf := &resource.StateChangeConf{ Pending: []string{"attaching", "detaching"}, @@ -524,16 +524,16 @@ func resourceOutscaleOAPINicDetach(meta interface{}, nicID string) error { return nil } -// Update OAPINic -func resourceOutscaleOAPINicUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +// Update Nic +func resourceNicUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) var err error if d.HasChange("link_nic") { _, na := d.GetChange("link_nic") - err := resourceOutscaleOAPINicDetach(meta, d.Id()) + err := resourceNicDetach(meta, d.Id()) if err != nil { return err } @@ -707,7 +707,7 @@ func resourceOutscaleOAPINicUpdate(d *schema.ResourceData, meta interface{}) err d.SetPartial("description") } - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } @@ -715,7 +715,7 @@ func resourceOutscaleOAPINicUpdate(d *schema.ResourceData, meta interface{}) err d.Partial(false) - return resourceOutscaleOAPINicRead(d, meta) + return resourceNicRead(d, meta) } func expandPrivateIPLight(pIPs []interface{}) []oscgo.PrivateIpLight { diff --git a/outscale/resource_outscale_nic_link.go b/outscale/resource_outscale_nic_link.go index 7d28d29e8..daf9f92c5 100644 --- a/outscale/resource_outscale_nic_link.go +++ b/outscale/resource_outscale_nic_link.go @@ -15,13 +15,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPINetworkInterfaceAttachment() *schema.Resource { +func resourceNetworkInterfaceAttachment() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPINetworkInterfaceAttachmentCreate, - Read: resourceOutscaleOAPINetworkInterfaceAttachmentRead, - Delete: resourceOutscaleOAPINetworkInterfaceAttachmentDelete, + Create: resourceNetworkInterfaceAttachmentCreate, + Read: resourceNetworkInterfaceAttachmentRead, + Delete: resourceNetworkInterfaceAttachmentDelete, Importer: &schema.ResourceImporter{ - State: resourceOutscaleNetworkInterfaceAttachmentImportState, + State: resourceNetworkInterfaceAttachmentImportState, }, Schema: map[string]*schema.Schema{ "device_number": { @@ -65,8 +65,8 @@ func resourceOutscaleOAPINetworkInterfaceAttachment() *schema.Resource { } } -func resourceOutscaleOAPINetworkInterfaceAttachmentCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetworkInterfaceAttachmentCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI di := d.Get("device_number").(int) vmID := d.Get("vm_id").(string) @@ -96,11 +96,11 @@ func resourceOutscaleOAPINetworkInterfaceAttachmentCreate(d *schema.ResourceData } d.SetId(resp.GetLinkNicId()) - return resourceOutscaleOAPINetworkInterfaceAttachmentRead(d, meta) + return resourceNetworkInterfaceAttachmentRead(d, meta) } -func resourceOutscaleOAPINetworkInterfaceAttachmentRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetworkInterfaceAttachmentRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI nicID := d.Get("nic_id").(string) @@ -138,8 +138,8 @@ func resourceOutscaleOAPINetworkInterfaceAttachmentRead(d *schema.ResourceData, return nil } -func resourceOutscaleOAPINetworkInterfaceAttachmentDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetworkInterfaceAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI interfaceID := d.Id() @@ -185,7 +185,7 @@ func resourceOutscaleOAPINetworkInterfaceAttachmentDelete(d *schema.ResourceData return nil } -func resourceOutscaleNetworkInterfaceAttachmentImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceNetworkInterfaceAttachmentImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { if d.Id() == "" { return nil, errors.New("import error: to import a Nic Link, use the format {nic_id} it must not be empty") } @@ -193,7 +193,7 @@ func resourceOutscaleNetworkInterfaceAttachmentImportState(d *schema.ResourceDat stateConf := &resource.StateChangeConf{ Pending: []string{"attaching", "detaching"}, Target: []string{"attached", "detached", "failed"}, - Refresh: nicLinkRefreshFunc(meta.(*OutscaleClient).OSCAPI, d.Id()), + Refresh: nicLinkRefreshFunc(meta.(*Client).OSCAPI, d.Id()), Timeout: 5 * time.Minute, Delay: 10 * time.Second, MinTimeout: 3 * time.Second, diff --git a/outscale/resource_outscale_nic_link_test.go b/outscale/resource_outscale_nic_link_test.go index d4949a93b..5e9561682 100644 --- a/outscale/resource_outscale_nic_link_test.go +++ b/outscale/resource_outscale_nic_link_test.go @@ -18,7 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleNicLink_Basic(t *testing.T) { +func TestAccNicLink_Basic(t *testing.T) { var conf oscgo.Nic omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -28,12 +28,12 @@ func TestAccOutscaleNicLink_Basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_nic.outscale_nic", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleNicLinkDestroy, + CheckDestroy: testAccCheckNicLinkDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleNicLinkConfigBasic(rInt, omi, "tinav4.c2r2p2", region), + Config: testAccNicLinkConfigBasic(rInt, omi, "tinav4.c2r2p2", region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIENIExists("outscale_nic.outscale_nic", &conf), + testAccCheckENIExists("outscale_nic.outscale_nic", &conf), resource.TestCheckResourceAttr( "outscale_nic_link.outscale_nic_link", "device_number", "1"), resource.TestCheckResourceAttrSet( @@ -46,7 +46,7 @@ func TestAccOutscaleNicLink_Basic(t *testing.T) { }) } -func TestAccOutscaleNicLink_importBasic(t *testing.T) { +func TestAccNicLink_importBasic(t *testing.T) { resourceName := "outscale_nic_link.outscale_nic_link" omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -55,10 +55,10 @@ func TestAccOutscaleNicLink_importBasic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleNicLinkDestroy, + CheckDestroy: testAccCheckNicLinkDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleNicLinkConfigBasic(rInt, omi, "tinav4.c2r2p2", region), + Config: testAccNicLinkConfigBasic(rInt, omi, "tinav4.c2r2p2", region), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("outscale_nic_link.outscale_nic_link", "device_number", "1"), resource.TestCheckResourceAttrSet("outscale_nic_link.outscale_nic_link", "vm_id"), @@ -67,7 +67,7 @@ func TestAccOutscaleNicLink_importBasic(t *testing.T) { }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOutscaleNicLinkStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckNicLinkStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{""}, @@ -76,7 +76,7 @@ func TestAccOutscaleNicLink_importBasic(t *testing.T) { }) } -func testAccCheckOutscaleNicLinkStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckNicLinkStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -87,8 +87,8 @@ func testAccCheckOutscaleNicLinkStateIDFunc(resourceName string) resource.Import } } -func testAccCheckOutscaleNicLinkDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckNicLinkDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_nic_link" { continue @@ -126,7 +126,7 @@ func testAccCheckOutscaleNicLinkDestroy(s *terraform.State) error { return nil } -func testAccOutscaleNicLinkConfigBasic(sg int, omi, vmType, region string) string { +func testAccNicLinkConfigBasic(sg int, omi, vmType, region string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_nic_private_ip.go b/outscale/resource_outscale_nic_private_ip.go index 3b1ead805..d9c1cb32a 100644 --- a/outscale/resource_outscale_nic_private_ip.go +++ b/outscale/resource_outscale_nic_private_ip.go @@ -12,11 +12,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPINetworkInterfacePrivateIP() *schema.Resource { +func resourceNetworkInterfacePrivateIP() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPINetworkInterfacePrivateIPCreate, - Read: resourceOutscaleOAPINetworkInterfacePrivateIPRead, - Delete: resourceOutscaleOAPINetworkInterfacePrivateIPDelete, + Create: resourceNetworkInterfacePrivateIPCreate, + Read: resourceNetworkInterfacePrivateIPRead, + Delete: resourceNetworkInterfacePrivateIPDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -56,8 +56,8 @@ func resourceOutscaleOAPINetworkInterfacePrivateIP() *schema.Resource { } } -func resourceOutscaleOAPINetworkInterfacePrivateIPCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetworkInterfacePrivateIPCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI input := oscgo.LinkPrivateIpsRequest{ NicId: d.Get("nic_id").(string), @@ -90,11 +90,11 @@ func resourceOutscaleOAPINetworkInterfacePrivateIPCreate(d *schema.ResourceData, d.SetId(input.NicId) - return resourceOutscaleOAPINetworkInterfacePrivateIPRead(d, meta) + return resourceNetworkInterfacePrivateIPRead(d, meta) } -func resourceOutscaleOAPINetworkInterfacePrivateIPRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetworkInterfacePrivateIPRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadNicsRequest{ Filters: &oscgo.FiltersNic{NicIds: &[]string{d.Id()}}, @@ -170,8 +170,8 @@ func resourceOutscaleOAPINetworkInterfacePrivateIPRead(d *schema.ResourceData, m return nil } -func resourceOutscaleOAPINetworkInterfacePrivateIPDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceNetworkInterfacePrivateIPDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI input := oscgo.UnlinkPrivateIpsRequest{ NicId: d.Id(), diff --git a/outscale/resource_outscale_nic_private_ip_test.go b/outscale/resource_outscale_nic_private_ip_test.go index 42f25abf7..b62ae36a0 100644 --- a/outscale/resource_outscale_nic_private_ip_test.go +++ b/outscale/resource_outscale_nic_private_ip_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPINetworkInterfacePrivateIPBasic(t *testing.T) { +func TestAccNetworkInterfacePrivateIPBasic(t *testing.T) { region := os.Getenv("OUTSCALE_REGION") var conf oscgo.Nic @@ -18,12 +18,12 @@ func TestAccOutscaleOAPINetworkInterfacePrivateIPBasic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_nic.outscale_nic", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIENIDestroy, + CheckDestroy: testAccCheckENIDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPINetworkInterfacePrivateIPConfigBasic(region), + Config: testAccNetworkInterfacePrivateIPConfigBasic(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIENIExists("outscale_nic.outscale_nic", &conf), + testAccCheckENIExists("outscale_nic.outscale_nic", &conf), resource.TestCheckResourceAttr("outscale_nic_private_ip.outscale_nic_private_ip", "private_ips.#", "1"), resource.TestCheckResourceAttr("outscale_nic_private_ip.outscale_nic_private_ip", "private_ips.0", "10.0.45.67"), resource.TestCheckResourceAttrSet("outscale_nic_private_ip.outscale_nic_private_ip", "primary_private_ip")), @@ -32,7 +32,7 @@ func TestAccOutscaleOAPINetworkInterfacePrivateIPBasic(t *testing.T) { }) } -func TestAccOutscaleOAPINetworkInterfacePrivateIP_importBasic(t *testing.T) { +func TestAccNetworkInterfacePrivateIP_importBasic(t *testing.T) { region := os.Getenv("OUTSCALE_REGION") resourceName := "outscale_nic_private_ip.outscale_nic_private_ip" @@ -40,10 +40,10 @@ func TestAccOutscaleOAPINetworkInterfacePrivateIP_importBasic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_nic.outscale_nic", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIENIDestroy, + CheckDestroy: testAccCheckENIDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPINetworkInterfacePrivateIPConfigBasic(region), + Config: testAccNetworkInterfacePrivateIPConfigBasic(region), }, { ResourceName: resourceName, @@ -55,7 +55,7 @@ func TestAccOutscaleOAPINetworkInterfacePrivateIP_importBasic(t *testing.T) { }) } -func testAccOutscaleOAPINetworkInterfacePrivateIPConfigBasic(region string) string { +func testAccNetworkInterfacePrivateIPConfigBasic(region string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_nic_test.go b/outscale/resource_outscale_nic_test.go index d734f999a..783149d7d 100644 --- a/outscale/resource_outscale_nic_test.go +++ b/outscale/resource_outscale_nic_test.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIENI_basic(t *testing.T) { +func TestAccENI_basic(t *testing.T) { t.Parallel() var conf oscgo.Nic subregion := os.Getenv("OUTSCALE_REGION") @@ -24,21 +24,21 @@ func TestAccOutscaleOAPIENI_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_nic.outscale_nic", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPINICDestroy, + CheckDestroy: testAccCheckNICDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIENIConfig(subregion), + Config: testAccENIConfig(subregion), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIENIExists("outscale_nic.outscale_nic", &conf), - testAccCheckOutscaleOAPIENIAttributes(&conf, subregion), + testAccCheckENIExists("outscale_nic.outscale_nic", &conf), + testAccCheckENIAttributes(&conf, subregion), resource.TestCheckResourceAttr("outscale_nic.outscale_nic", "private_ips.#", "2"), ), }, { - Config: testAccOutscaleOAPIENIConfigUpdate(subregion), + Config: testAccENIConfigUpdate(subregion), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIENIExists("outscale_nic.outscale_nic", &conf), - testAccCheckOutscaleOAPIENIAttributes(&conf, subregion), + testAccCheckENIExists("outscale_nic.outscale_nic", &conf), + testAccCheckENIAttributes(&conf, subregion), resource.TestCheckResourceAttr("outscale_nic.outscale_nic", "private_ips.#", "3"), ), }, @@ -46,7 +46,7 @@ func TestAccOutscaleOAPIENI_basic(t *testing.T) { }) } -func testAccCheckOutscaleOAPIENIExists(n string, res *oscgo.Nic) resource.TestCheckFunc { +func testAccCheckENIExists(n string, res *oscgo.Nic) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -57,7 +57,7 @@ func testAccCheckOutscaleOAPIENIExists(n string, res *oscgo.Nic) resource.TestCh return fmt.Errorf("No ENI ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI dnir := oscgo.ReadNicsRequest{ Filters: &oscgo.FiltersNic{NicIds: &[]string{rs.Primary.ID}}, } @@ -90,7 +90,7 @@ func testAccCheckOutscaleOAPIENIExists(n string, res *oscgo.Nic) resource.TestCh } } -func testAccCheckOutscaleOAPIENIAttributes(conf *oscgo.Nic, suregion string) resource.TestCheckFunc { +func testAccCheckENIAttributes(conf *oscgo.Nic, suregion string) resource.TestCheckFunc { return func(s *terraform.State) error { if !reflect.DeepEqual(conf.GetLinkNic(), oscgo.LinkNic{}) { @@ -105,7 +105,7 @@ func testAccCheckOutscaleOAPIENIAttributes(conf *oscgo.Nic, suregion string) res } } -func testAccOutscaleOAPIENIConfig(subregion string) string { +func testAccENIConfig(subregion string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -144,7 +144,7 @@ func testAccOutscaleOAPIENIConfig(subregion string) string { `, subregion) } -func testAccOutscaleOAPIENIConfigUpdate(subregion string) string { +func testAccENIConfigUpdate(subregion string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_public_ip.go b/outscale/resource_outscale_public_ip.go index 1c791e4f9..278af92ef 100644 --- a/outscale/resource_outscale_public_ip.go +++ b/outscale/resource_outscale_public_ip.go @@ -13,12 +13,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPIPublicIP() *schema.Resource { +func resourcePublicIP() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIPublicIPCreate, - Read: resourceOutscaleOAPIPublicIPRead, - Delete: resourceOutscaleOAPIPublicIPDelete, - Update: resourceOutscaleOAPIPublicIPUpdate, + Create: resourcePublicIPCreate, + Read: resourcePublicIPRead, + Delete: resourcePublicIPDelete, + Update: resourcePublicIPUpdate, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -28,12 +28,12 @@ func resourceOutscaleOAPIPublicIP() *schema.Resource { Delete: schema.DefaultTimeout(30 * time.Minute), }, - Schema: getOAPIPublicIPSchema(), + Schema: getPublicIPSchema(), } } -func resourceOutscaleOAPIPublicIPCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourcePublicIPCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI allocOpts := oscgo.CreatePublicIpRequest{} @@ -67,11 +67,11 @@ func resourceOutscaleOAPIPublicIPCreate(d *schema.ResourceData, meta interface{} } log.Printf("[INFO] EIP ID: %s (placement: %v)", d.Id(), allocResp.GetPublicIp()) - return resourceOutscaleOAPIPublicIPUpdate(d, meta) + return resourcePublicIPUpdate(d, meta) } -func resourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourcePublicIPRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() @@ -129,7 +129,7 @@ func resourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{}) return err } - if err := d.Set("tags", tagsOSCAPIToMap(publicIP.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(publicIP.GetTags())); err != nil { log.Printf("[WARN] error setting tags for PublicIp(%s): %s", publicIP.GetPublicIp(), err) } @@ -138,8 +138,8 @@ func resourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{}) return nil } -func resourceOutscaleOAPIPublicIPUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourcePublicIPUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI vVm, okInstance := d.GetOk("vm_id") vNic, okInterface := d.GetOk("nic_id") @@ -186,7 +186,7 @@ func resourceOutscaleOAPIPublicIPUpdate(d *schema.ResourceData, meta interface{} } d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } @@ -194,7 +194,7 @@ func resourceOutscaleOAPIPublicIPUpdate(d *schema.ResourceData, meta interface{} d.Partial(false) - return resourceOutscaleOAPIPublicIPRead(d, meta) + return resourcePublicIPRead(d, meta) } func unlinkPublicIp(conn *oscgo.APIClient, publicIpId *string) error { @@ -211,10 +211,10 @@ func unlinkPublicIp(conn *oscgo.APIClient, publicIpId *string) error { return err } -func resourceOutscaleOAPIPublicIPDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourcePublicIPDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI - if err := resourceOutscaleOAPIPublicIPRead(d, meta); err != nil { + if err := resourcePublicIPRead(d, meta); err != nil { return err } if d.Id() == "" { @@ -227,7 +227,7 @@ func resourceOutscaleOAPIPublicIPDelete(d *schema.ResourceData, meta interface{} if (okInstance && vInstance.(string) != "") || (okAssociationID && linkPublicIPID.(string) != "") { log.Printf("[DEBUG] Disassociating EIP: %s", d.Id()) var err error - switch resourceOutscaleOAPIPublicIPDomain(d) { + switch resourcePublicIPDomain(d) { case "vpc": linIpId := d.Get("link_public_ip_id").(string) err = unlinkPublicIp(conn, &linIpId) @@ -260,7 +260,7 @@ func resourceOutscaleOAPIPublicIPDelete(d *schema.ResourceData, meta interface{} }) } -func getOAPIPublicIPSchema() map[string]*schema.Schema { +func getPublicIPSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ "public_ip_id": { Type: schema.TypeString, @@ -294,11 +294,11 @@ func getOAPIPublicIPSchema() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), } } -func resourceOutscaleOAPIPublicIPDomain(d *schema.ResourceData) string { +func resourcePublicIPDomain(d *schema.ResourceData) string { if v, ok := d.GetOk("placement"); ok { return v.(string) } else if strings.Contains(d.Id(), "eipalloc") { diff --git a/outscale/resource_outscale_public_ip_link.go b/outscale/resource_outscale_public_ip_link.go index 676588292..394f17364 100644 --- a/outscale/resource_outscale_public_ip_link.go +++ b/outscale/resource_outscale_public_ip_link.go @@ -14,11 +14,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIPublicIPLink() *schema.Resource { +func resourcePublicIPLink() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIPublicIPLinkCreate, - Read: resourceOutscaleOAPIPublicIPLinkRead, - Delete: resourceOutscaleOAPIPublicIPLinkDelete, + Create: resourcePublicIPLinkCreate, + Read: resourcePublicIPLinkRead, + Delete: resourcePublicIPLinkDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -28,12 +28,12 @@ func resourceOutscaleOAPIPublicIPLink() *schema.Resource { Delete: schema.DefaultTimeout(10 * time.Minute), }, - Schema: getOAPIPublicIPLinkSchema(), + Schema: getPublicIPLinkSchema(), } } -func resourceOutscaleOAPIPublicIPLinkCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourcePublicIPLinkCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI request := oscgo.LinkPublicIpRequest{} @@ -72,7 +72,7 @@ func resourceOutscaleOAPIPublicIPLinkCreate(d *schema.ResourceData, meta interfa }) if err != nil { - log.Printf("[WARN] ERROR resourceOutscaleOAPIPublicIPLinkCreate (%s)", err) + log.Printf("[WARN] ERROR resourcePublicIPLinkCreate (%s)", err) return err } //Using validation with request. @@ -82,11 +82,11 @@ func resourceOutscaleOAPIPublicIPLinkCreate(d *schema.ResourceData, meta interfa d.SetId(request.GetPublicIp()) } - return resourceOutscaleOAPIPublicIPLinkRead(d, meta) + return resourcePublicIPLinkRead(d, meta) } -func resourceOutscaleOAPIPublicIPLinkRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourcePublicIPLinkRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() var request oscgo.ReadPublicIpsRequest @@ -118,7 +118,7 @@ func resourceOutscaleOAPIPublicIPLinkRead(d *schema.ResourceData, meta interface }) if err != nil { - log.Printf("[WARN] ERROR resourceOutscaleOAPIPublicIPLinkRead (%s)", err) + log.Printf("[WARN] ERROR resourcePublicIPLinkRead (%s)", err) return fmt.Errorf("Error reading Outscale VM Public IP %s: %#v", d.Get("public_ip_id").(string), err) } @@ -128,15 +128,15 @@ func resourceOutscaleOAPIPublicIPLinkRead(d *schema.ResourceData, meta interface return nil } - if err := d.Set("tags", getOapiTagSet(response.GetPublicIps()[0].Tags)); err != nil { + if err := d.Set("tags", getTagSet(response.GetPublicIps()[0].GetTags())); err != nil { return err } - return readOutscaleOAPIPublicIPLink(d, &response.GetPublicIps()[0]) + return readPublicIPLink(d, &response.GetPublicIps()[0]) } -func resourceOutscaleOAPIPublicIPLinkDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourcePublicIPLinkDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI linkID := d.Get("link_public_ip_id") @@ -154,66 +154,66 @@ func resourceOutscaleOAPIPublicIPLinkDelete(d *schema.ResourceData, meta interfa }) if err != nil { - log.Printf("[WARN] ERROR resourceOutscaleOAPIPublicIPLinkDelete (%s)", err) + log.Printf("[WARN] ERROR resourcePublicIPLinkDelete (%s)", err) return fmt.Errorf("Error deleting Elastic IP association: %s", err) } return nil } -func readOutscaleOAPIPublicIPLink(d *schema.ResourceData, address *oscgo.PublicIp) error { +func readPublicIPLink(d *schema.ResourceData, address *oscgo.PublicIp) error { // if err := d.Set("public_ip_id", address.ReservationId); err != nil { - // log.Printf("[WARN] ERROR readOutscalePublicIPLink1 (%s)", err) + // log.Printf("[WARN] ERROR readPublicIPLink1 (%s)", err) // return err // } if err := d.Set("vm_id", address.GetVmId()); err != nil { - fmt.Printf("[WARN] ERROR readOutscalePublicIPLink2 (%s)", err) + fmt.Printf("[WARN] ERROR readPublicIPLink2 (%s)", err) return err } if err := d.Set("nic_id", address.GetNicId()); err != nil { - fmt.Printf("[WARN] ERROR readOutscalePublicIPLink3 (%s)", err) + fmt.Printf("[WARN] ERROR readPublicIPLink3 (%s)", err) return err } if err := d.Set("private_ip", address.GetPrivateIp()); err != nil { - fmt.Printf("[WARN] ERROR readOutscalePublicIPLink4 (%s)", err) + fmt.Printf("[WARN] ERROR readPublicIPLink4 (%s)", err) return err } if err := d.Set("public_ip", address.GetPublicIp()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleOAPIPublicIPLink (%s)", err) + fmt.Printf("[WARN] ERROR readPublicIPLink (%s)", err) return err } if err := d.Set("link_public_ip_id", address.GetLinkPublicIpId()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleOAPIPublicIPLink (%s)", err) + fmt.Printf("[WARN] ERROR readPublicIPLink (%s)", err) return err } if err := d.Set("nic_account_id", address.GetNicAccountId()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleOAPIPublicIPLink (%s)", err) + fmt.Printf("[WARN] ERROR readPublicIPLink (%s)", err) return err } if err := d.Set("public_ip_id", address.GetPublicIpId()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleOAPIPublicIPLink (%s)", err) + fmt.Printf("[WARN] ERROR readPublicIPLink (%s)", err) return err } - if err := d.Set("tags", tagsOSCAPIToMap(address.GetTags())); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleOAPIPublicIPLink TAGS PROBLEME (%s)", err) + if err := d.Set("tags", tagsToMap(address.GetTags())); err != nil { + fmt.Printf("[WARN] ERROR readPublicIPLink TAGS PROBLEME (%s)", err) } return nil } -func getOAPIPublicIPLinkSchema() map[string]*schema.Schema { +func getPublicIPLinkSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ "public_ip_id": { Type: schema.TypeString, @@ -263,6 +263,6 @@ func getOAPIPublicIPLinkSchema() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "tags": tagsOAPIListSchemaComputed(), + "tags": tagsListSchemaComputed(), } } diff --git a/outscale/resource_outscale_public_ip_link_test.go b/outscale/resource_outscale_public_ip_link_test.go index 3057d1ed5..b7253c4c2 100644 --- a/outscale/resource_outscale_public_ip_link_test.go +++ b/outscale/resource_outscale_public_ip_link_test.go @@ -16,7 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIPublicIPLink_basic(t *testing.T) { +func TestAccPublicIPLink_basic(t *testing.T) { var a oscgo.PublicIp omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -26,14 +26,14 @@ func TestAccOutscaleOAPIPublicIPLink_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIPublicIPLinkDestroy, + CheckDestroy: testAccCheckPublicIPLinkDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIPublicIPLinkConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccPublicIPLinkConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIPublicIPLExists( + testAccCheckPublicIPLExists( "outscale_public_ip.ip", &a), - testAccCheckOutscaleOAPIPublicIPLinkExists( + testAccCheckPublicIPLinkExists( "outscale_public_ip_link.by_public_ip", &a), ), }, @@ -41,7 +41,7 @@ func TestAccOutscaleOAPIPublicIPLink_basic(t *testing.T) { }) } -func testAccCheckOutscaleOAPIPublicIPLinkExists(name string, res *oscgo.PublicIp) resource.TestCheckFunc { +func testAccCheckPublicIPLinkExists(name string, res *oscgo.PublicIp) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -52,7 +52,7 @@ func testAccCheckOutscaleOAPIPublicIPLinkExists(name string, res *oscgo.PublicIp return fmt.Errorf("No Public IP Link ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient) + conn := testAccProvider.Meta().(*Client) request := oscgo.ReadPublicIpsRequest{ Filters: &oscgo.FiltersPublicIp{ @@ -70,7 +70,7 @@ func testAccCheckOutscaleOAPIPublicIPLinkExists(name string, res *oscgo.PublicIp }) if err != nil { - log.Printf("[DEBUG] ERROR testAccCheckOutscaleOAPIPublicIPLinkExists (%s)", err) + log.Printf("[DEBUG] ERROR testAccCheckPublicIPLinkExists (%s)", err) return err } @@ -88,7 +88,7 @@ func testAccCheckOutscaleOAPIPublicIPLinkExists(name string, res *oscgo.PublicIp } } -func testAccCheckOutscaleOAPIPublicIPLinkDestroy(s *terraform.State) error { +func testAccCheckPublicIPLinkDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_public_ip_link" { continue @@ -100,7 +100,7 @@ func testAccCheckOutscaleOAPIPublicIPLinkDestroy(s *terraform.State) error { id := rs.Primary.Attributes["link_public_ip_id"] - conn := testAccProvider.Meta().(*OutscaleClient) + conn := testAccProvider.Meta().(*Client) request := oscgo.ReadPublicIpsRequest{ Filters: &oscgo.FiltersPublicIp{ @@ -118,7 +118,7 @@ func testAccCheckOutscaleOAPIPublicIPLinkDestroy(s *terraform.State) error { }) if err != nil { - log.Printf("[DEBUG] ERROR testAccCheckOutscaleOAPIPublicIPLinkDestroy (%s)", err) + log.Printf("[DEBUG] ERROR testAccCheckPublicIPLinkDestroy (%s)", err) return err } @@ -129,7 +129,7 @@ func testAccCheckOutscaleOAPIPublicIPLinkDestroy(s *terraform.State) error { return nil } -func testAccCheckOutscaleOAPIPublicIPLExists(n string, res *oscgo.PublicIp) resource.TestCheckFunc { +func testAccCheckPublicIPLExists(n string, res *oscgo.PublicIp) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -140,7 +140,7 @@ func testAccCheckOutscaleOAPIPublicIPLExists(n string, res *oscgo.PublicIp) reso return fmt.Errorf("No PublicIP ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient) + conn := testAccProvider.Meta().(*Client) // Missing on Swagger Spec if strings.Contains(rs.Primary.ID, "reservation") { @@ -211,7 +211,7 @@ func testAccCheckOutscaleOAPIPublicIPLExists(n string, res *oscgo.PublicIp) reso } } -func testAccOutscaleOAPIPublicIPLinkConfig(omi, vmType, region, keypair, sgId string) string { +func testAccPublicIPLinkConfig(omi, vmType, region, keypair, sgId string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_public_ip_test.go b/outscale/resource_outscale_public_ip_test.go index 86d36aa6b..c85093f88 100644 --- a/outscale/resource_outscale_public_ip_test.go +++ b/outscale/resource_outscale_public_ip_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIPublicIP_basic(t *testing.T) { +func TestAccPublicIP_basic(t *testing.T) { t.Parallel() var conf oscgo.PublicIp @@ -22,20 +22,20 @@ func TestAccOutscaleOAPIPublicIP_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_public_ip.bar", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIPublicIPDestroy, + CheckDestroy: testAccCheckPublicIPDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIPublicIPConfig, + Config: testAccPublicIPConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIPublicIPExists("outscale_public_ip.bar", &conf), - testAccCheckOutscaleOAPIPublicIPAttributes(&conf), + testAccCheckPublicIPExists("outscale_public_ip.bar", &conf), + testAccCheckPublicIPAttributes(&conf), ), }, }, }) } -func TestAccOutscaleOAPIPublicIP_instance(t *testing.T) { +func TestAccPublicIP_instance(t *testing.T) { t.Parallel() var conf oscgo.PublicIp omi := os.Getenv("OUTSCALE_IMAGEID") @@ -48,30 +48,30 @@ func TestAccOutscaleOAPIPublicIP_instance(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_public_ip.bar", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIPublicIPDestroy, + CheckDestroy: testAccCheckPublicIPDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIPublicIPInstanceConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccPublicIPInstanceConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIPublicIPExists("outscale_public_ip.bar", &conf), - testAccCheckOutscaleOAPIPublicIPAttributes(&conf), + testAccCheckPublicIPExists("outscale_public_ip.bar", &conf), + testAccCheckPublicIPAttributes(&conf), ), }, { - Config: testAccOutscaleOAPIPublicIPInstanceConfig2(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccPublicIPInstanceConfig2(omi, "tinav4.c2r2p2", region, keypair, sgId), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIPublicIPExists("outscale_public_ip.bar", &conf), - testAccCheckOutscaleOAPIPublicIPAttributes(&conf), + testAccCheckPublicIPExists("outscale_public_ip.bar", &conf), + testAccCheckPublicIPAttributes(&conf), ), }, }, }) } -// // This test is an expansion of TestAccOutscalePublicIP_instance, by testing the +// // This test is an expansion of TestAccPublicIP_instance, by testing the // // associated Private PublicIPs of two instances -func TestAccOutscaleOAPIPublicIP_associated_user_private_ip(t *testing.T) { +func TestAccPublicIP_associated_user_private_ip(t *testing.T) { var one oscgo.PublicIp omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -82,28 +82,28 @@ func TestAccOutscaleOAPIPublicIP_associated_user_private_ip(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_public_ip.bar", Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIPublicIPDestroy, + CheckDestroy: testAccCheckPublicIPDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIPublicIPInstanceConfigAssociated(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccPublicIPInstanceConfigAssociated(omi, "tinav4.c2r2p2", region, keypair, sgId), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIPublicIPExists("outscale_public_ip.bar", &one), - testAccCheckOutscaleOAPIPublicIPAttributes(&one), + testAccCheckPublicIPExists("outscale_public_ip.bar", &one), + testAccCheckPublicIPAttributes(&one), ), }, { - Config: testAccOutscaleOAPIPublicIPInstanceConfigAssociatedSwitch(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccPublicIPInstanceConfigAssociatedSwitch(omi, "tinav4.c2r2p2", region, keypair, sgId), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIPublicIPExists("outscale_public_ip.bar", &one), - testAccCheckOutscaleOAPIPublicIPAttributes(&one), + testAccCheckPublicIPExists("outscale_public_ip.bar", &one), + testAccCheckPublicIPAttributes(&one), ), }, }, }) } -func testAccCheckOutscaleOAPIPublicIPDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient) +func testAccCheckPublicIPDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client) for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_public_ip" { @@ -169,7 +169,7 @@ func testAccCheckOutscaleOAPIPublicIPDestroy(s *terraform.State) error { return nil } -func testAccCheckOutscaleOAPIPublicIPAttributes(conf *oscgo.PublicIp) resource.TestCheckFunc { +func testAccCheckPublicIPAttributes(conf *oscgo.PublicIp) resource.TestCheckFunc { return func(s *terraform.State) error { if conf.GetPublicIp() == "" { return fmt.Errorf("empty public_ip") @@ -179,7 +179,7 @@ func testAccCheckOutscaleOAPIPublicIPAttributes(conf *oscgo.PublicIp) resource.T } } -func testAccCheckOutscaleOAPIPublicIPExists(n string, res *oscgo.PublicIp) resource.TestCheckFunc { +func testAccCheckPublicIPExists(n string, res *oscgo.PublicIp) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -190,7 +190,7 @@ func testAccCheckOutscaleOAPIPublicIPExists(n string, res *oscgo.PublicIp) resou return fmt.Errorf("No PublicIP ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient) + conn := testAccProvider.Meta().(*Client) //Missing on Swagger Spec // if strings.Contains(rs.Primary.ID, "link") { @@ -253,7 +253,7 @@ func testAccCheckOutscaleOAPIPublicIPExists(n string, res *oscgo.PublicIp) resou } } -const testAccOutscaleOAPIPublicIPConfig = ` +const testAccPublicIPConfig = ` resource "outscale_public_ip" "bar" { tags { key = "Name" @@ -262,7 +262,7 @@ resource "outscale_public_ip" "bar" { } ` -func testAccOutscaleOAPIPublicIPInstanceConfig(omi, vmType, region, keypair, sgId string) string { +func testAccPublicIPInstanceConfig(omi, vmType, region, keypair, sgId string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" @@ -297,7 +297,7 @@ func testAccOutscaleOAPIPublicIPInstanceConfig(omi, vmType, region, keypair, sgI `, omi, vmType, region, keypair, sgId) } -func testAccOutscaleOAPIPublicIPInstanceConfig2(omi, vmType, region, keypair, sgId string) string { +func testAccPublicIPInstanceConfig2(omi, vmType, region, keypair, sgId string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" @@ -332,7 +332,7 @@ func testAccOutscaleOAPIPublicIPInstanceConfig2(omi, vmType, region, keypair, sg `, omi, vmType, region, keypair, sgId) } -func testAccOutscaleOAPIPublicIPInstanceConfigAssociated(omi, vmType, region, keypair, sgId string) string { +func testAccPublicIPInstanceConfigAssociated(omi, vmType, region, keypair, sgId string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" @@ -375,7 +375,7 @@ func testAccOutscaleOAPIPublicIPInstanceConfigAssociated(omi, vmType, region, ke `, omi, vmType, region, keypair, sgId) } -func testAccOutscaleOAPIPublicIPInstanceConfigAssociatedSwitch(omi, vmType, region, keypair, sgId string) string { +func testAccPublicIPInstanceConfigAssociatedSwitch(omi, vmType, region, keypair, sgId string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_route.go b/outscale/resource_outscale_route.go index 63d8379d3..eac8125e0 100644 --- a/outscale/resource_outscale_route.go +++ b/outscale/resource_outscale_route.go @@ -17,7 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -var errOAPIRoute = errors.New("Error: more than 1 target specified. Only 1 of gateway_id, " + +var errRoute = errors.New("Error: more than 1 target specified. Only 1 of gateway_id, " + "nat_service_id, vm_id, nic_id or net_peering_id is allowed.") var allowedTargets = []string{ @@ -28,15 +28,15 @@ var allowedTargets = []string{ "net_peering_id", } -func resourceOutscaleOAPIRoute() *schema.Resource { +func resourceRoute() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIRouteCreate, - Read: resourceOutscaleOAPIRouteRead, - Update: resourceOutscaleOAPIRouteUpdate, - Delete: resourceOutscaleOAPIRouteDelete, - Exists: resourceOutscaleOAPIRouteExists, + Create: resourceRouteCreate, + Read: resourceRouteRead, + Update: resourceRouteUpdate, + Delete: resourceRouteDelete, + Exists: resourceRouteExists, Importer: &schema.ResourceImporter{ - State: resourceOutscaleOAPIRouteImportState, + State: resourceRouteImportState, }, Schema: map[string]*schema.Schema{ "creation_method": { @@ -108,13 +108,13 @@ func resourceOutscaleOAPIRoute() *schema.Resource { } } -func resourceOutscaleOAPIRouteCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceRouteCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI numTargets, target := getTarget(d) awaitActiveState := d.Get("await_active_state").(bool) if numTargets > 1 { - return errOAPIRoute + return errRoute } createOpts := oscgo.CreateRouteRequest{ @@ -162,7 +162,7 @@ func resourceOutscaleOAPIRouteCreate(d *schema.ResourceData, meta interface{}) e if v, ok := d.GetOk("destination_ip_range"); ok { err = resource.Retry(2*time.Minute, func() *resource.RetryError { - route, requestID, err = findResourceOAPIRoute(conn, d.Get("route_table_id").(string), v.(string)) + route, requestID, err = findResourceRoute(conn, d.Get("route_table_id").(string), v.(string)) if awaitActiveState && err == nil { if route.GetState() != "active" { return resource.RetryableError(fmt.Errorf("still await route to be active")) @@ -176,25 +176,25 @@ func resourceOutscaleOAPIRouteCreate(d *schema.ResourceData, meta interface{}) e } d.SetId(d.Get("route_table_id").(string)) - resourceOutscaleOAPIRouteSetResourceData(d, route, requestID) + resourceRouteSetResourceData(d, route, requestID) return nil } -func resourceOutscaleOAPIRouteRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceRouteRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI routeTableID := d.Id() destinationIPRange := d.Get("destination_ip_range").(string) var requestID string - route, requestID, err := findResourceOAPIRoute(conn, routeTableID, destinationIPRange) + route, requestID, err := findResourceRoute(conn, routeTableID, destinationIPRange) if err != nil { return err } - return resourceOutscaleOAPIRouteSetResourceData(d, route, requestID) + return resourceRouteSetResourceData(d, route, requestID) } -func resourceOutscaleOAPIRouteSetResourceData(d *schema.ResourceData, route *oscgo.Route, requestID string) error { +func resourceRouteSetResourceData(d *schema.ResourceData, route *oscgo.Route, requestID string) error { if err := d.Set("destination_service_id", route.GetDestinationServiceId()); err != nil { return err } @@ -241,8 +241,8 @@ func getTarget(d *schema.ResourceData) (n int, target string) { return } -func resourceOutscaleOAPIRouteUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceRouteUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI nothingToDo := true o, n := d.GetChange("") os := o.(map[string]interface{}) @@ -335,11 +335,11 @@ func resourceOutscaleOAPIRouteUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("error updating route: %s", utils.GetErrorResponse(err)) } - return resourceOutscaleOAPIRouteRead(d, meta) + return resourceRouteRead(d, meta) } -func resourceOutscaleOAPIRouteDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceRouteDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI deleteOpts := oscgo.DeleteRouteRequest{ RouteTableId: d.Get("route_table_id").(string), @@ -370,8 +370,8 @@ func resourceOutscaleOAPIRouteDelete(d *schema.ResourceData, meta interface{}) e return nil } -func resourceOutscaleOAPIRouteExists(d *schema.ResourceData, meta interface{}) (bool, error) { - conn := meta.(*OutscaleClient).OSCAPI +func resourceRouteExists(d *schema.ResourceData, meta interface{}) (bool, error) { + conn := meta.(*Client).OSCAPI routeTableID := d.Get("route_table_id").(string) findOpts := oscgo.ReadRouteTablesRequest{ @@ -421,7 +421,7 @@ func resourceOutscaleOAPIRouteExists(d *schema.ResourceData, meta interface{}) ( return false, nil } -func findResourceOAPIRoute(conn *oscgo.APIClient, rtbid string, cidr string) (*oscgo.Route, string, error) { +func findResourceRoute(conn *oscgo.APIClient, rtbid string, cidr string) (*oscgo.Route, string, error) { routeTableID := rtbid findOpts := oscgo.ReadRouteTablesRequest{} @@ -472,8 +472,8 @@ func findResourceOAPIRoute(conn *oscgo.APIClient, rtbid string, cidr string) (*o } -func resourceOutscaleOAPIRouteImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - conn := meta.(*OutscaleClient).OSCAPI +func resourceRouteImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + conn := meta.(*Client).OSCAPI parts := strings.SplitN(d.Id(), "_", 2) if len(parts) != 2 { @@ -483,7 +483,7 @@ func resourceOutscaleOAPIRouteImportState(d *schema.ResourceData, meta interface routeTableID := parts[0] destinationIPRange := parts[1] - _, _, err := findResourceOAPIRoute(conn, routeTableID, destinationIPRange) + _, _, err := findResourceRoute(conn, routeTableID, destinationIPRange) if err != nil { if strings.Contains(fmt.Sprint(err), "InvalidRouteTableID.NotFound") { log.Printf("[WARN] Route Table %q could not be found. Removing Route from state.", routeTableID) diff --git a/outscale/resource_outscale_route_table.go b/outscale/resource_outscale_route_table.go index 722c64ae7..28e0c3e80 100644 --- a/outscale/resource_outscale_route_table.go +++ b/outscale/resource_outscale_route_table.go @@ -13,12 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIRouteTable() *schema.Resource { +func resourceRouteTable() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIRouteTableCreate, - Read: resourceOutscaleOAPIRouteTableRead, - Update: resourceOutscaleOAPIRouteTableUpdate, - Delete: resourceOutscaleOAPIRouteTableDelete, + Create: resourceRouteTableCreate, + Read: resourceRouteTableRead, + Update: resourceRouteTableUpdate, + Delete: resourceRouteTableDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -37,7 +37,7 @@ func resourceOutscaleOAPIRouteTable() *schema.Resource { Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "route_propagating_virtual_gateways": { Type: schema.TypeList, @@ -135,8 +135,8 @@ func resourceOutscaleOAPIRouteTable() *schema.Resource { } } -func resourceOutscaleOAPIRouteTableCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceRouteTableCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI createOpts := oscgo.CreateRouteTableRequest{ NetId: d.Get("net_id").(string), @@ -167,7 +167,7 @@ func resourceOutscaleOAPIRouteTableCreate(d *schema.ResourceData, meta interface stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: []string{"ready"}, - Refresh: resourceOutscaleOAPIRouteTableStateRefreshFunc(conn, d.Id()), + Refresh: resourceRouteTableStateRefreshFunc(conn, d.Id()), Timeout: 5 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { @@ -177,7 +177,7 @@ func resourceOutscaleOAPIRouteTableCreate(d *schema.ResourceData, meta interface } if d.IsNewResource() { - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") @@ -193,11 +193,11 @@ func resourceOutscaleOAPIRouteTableCreate(d *schema.ResourceData, meta interface return err } - return resourceOutscaleOAPIRouteTableRead(d, meta) + return resourceRouteTableRead(d, meta) } -func resourceOutscaleOAPIRouteTableRead(d *schema.ResourceData, meta interface{}) error { - rtRaw, _, err := readOAPIRouteTable(meta.(*OutscaleClient).OSCAPI, d.Id()) +func resourceRouteTableRead(d *schema.ResourceData, meta interface{}) error { + rtRaw, _, err := readRouteTable(meta.(*Client).OSCAPI, d.Id()) if err != nil { return err } @@ -213,41 +213,41 @@ func resourceOutscaleOAPIRouteTableRead(d *schema.ResourceData, meta interface{} if err := d.Set("net_id", rt.GetNetId()); err != nil { return err } - if err := d.Set("route_propagating_virtual_gateways", setOSCAPIPropagatingVirtualGateways(rt.GetRoutePropagatingVirtualGateways())); err != nil { + if err := d.Set("route_propagating_virtual_gateways", setPropagatingVirtualGateways(rt.GetRoutePropagatingVirtualGateways())); err != nil { return err } - if err := d.Set("routes", setOSCAPIRoutes(rt.GetRoutes())); err != nil { + if err := d.Set("routes", setRoutes(rt.GetRoutes())); err != nil { return err } - if err := d.Set("link_route_tables", setOSCAPILinkRouteTables(rt.GetLinkRouteTables())); err != nil { + if err := d.Set("link_route_tables", setLinkRouteTables(rt.GetLinkRouteTables())); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(rt.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(rt.GetTags())); err != nil { return err } return nil } -func resourceOutscaleOAPIRouteTableUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceRouteTableUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOutscaleOAPIRouteTableRead(d, meta) + return resourceRouteTableRead(d, meta) } -func resourceOutscaleOAPIRouteTableDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceRouteTableDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI - rtRaw, _, err := readOAPIRouteTable(meta.(*OutscaleClient).OSCAPI, d.Id()) + rtRaw, _, err := readRouteTable(meta.(*Client).OSCAPI, d.Id()) if err != nil { return err } @@ -308,7 +308,7 @@ func resourceOutscaleOAPIRouteTableDelete(d *schema.ResourceData, meta interface stateConf := &resource.StateChangeConf{ Pending: []string{"ready"}, Target: []string{}, - Refresh: resourceOutscaleOAPIRouteTableStateRefreshFunc(conn, d.Id()), + Refresh: resourceRouteTableStateRefreshFunc(conn, d.Id()), Timeout: 5 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { @@ -318,7 +318,7 @@ func resourceOutscaleOAPIRouteTableDelete(d *schema.ResourceData, meta interface return nil } -func readOAPIRouteTable(conn *oscgo.APIClient, routeTableID string, linkIds ...string) (interface{}, string, error) { +func readRouteTable(conn *oscgo.APIClient, routeTableID string, linkIds ...string) (interface{}, string, error) { log.Printf("[DEBUG] Looking for RouteTable with: id %v and link_ids %v", routeTableID, linkIds) var resp oscgo.ReadRouteTablesResponse var err error @@ -347,7 +347,7 @@ func readOAPIRouteTable(conn *oscgo.APIClient, routeTableID string, linkIds ...s return nil, resp.ResponseContext.GetRequestId(), err } - //Fix for OAPI issue when passing routeTableIds and routeTableLinkIds + //Fix for issue when passing routeTableIds and routeTableLinkIds rts := resp.GetRouteTables()[0].GetLinkRouteTables() if len(linkIds) > 0 { @@ -363,9 +363,9 @@ func readOAPIRouteTable(conn *oscgo.APIClient, routeTableID string, linkIds ...s return resp.GetRouteTables()[0], resp.ResponseContext.GetRequestId(), err } -func resourceOutscaleOAPIRouteTableStateRefreshFunc(conn *oscgo.APIClient, routeTableID string, linkIds ...string) resource.StateRefreshFunc { +func resourceRouteTableStateRefreshFunc(conn *oscgo.APIClient, routeTableID string, linkIds ...string) resource.StateRefreshFunc { return func() (interface{}, string, error) { - rtRaw, _, err := readOAPIRouteTable(conn, routeTableID, linkIds...) + rtRaw, _, err := readRouteTable(conn, routeTableID, linkIds...) if rtRaw == nil { return nil, "", err } @@ -373,7 +373,7 @@ func resourceOutscaleOAPIRouteTableStateRefreshFunc(conn *oscgo.APIClient, route } } -func setOSCAPIRoutes(rt []oscgo.Route) []map[string]interface{} { +func setRoutes(rt []oscgo.Route) []map[string]interface{} { route := make([]map[string]interface{}, len(rt)) if len(rt) > 0 { for k, r := range rt { @@ -420,7 +420,7 @@ func setOSCAPIRoutes(rt []oscgo.Route) []map[string]interface{} { return route } -func setOSCAPILinkRouteTables(rt []oscgo.LinkRouteTable) []map[string]interface{} { +func setLinkRouteTables(rt []oscgo.LinkRouteTable) []map[string]interface{} { linkRouteTables := make([]map[string]interface{}, len(rt)) log.Printf("[DEBUG] LinkRouteTable: %#v", rt) if len(rt) > 0 { @@ -445,7 +445,7 @@ func setOSCAPILinkRouteTables(rt []oscgo.LinkRouteTable) []map[string]interface{ return linkRouteTables } -func setOSCAPIPropagatingVirtualGateways(vg []oscgo.RoutePropagatingVirtualGateway) (propagatingVGWs []map[string]interface{}) { +func setPropagatingVirtualGateways(vg []oscgo.RoutePropagatingVirtualGateway) (propagatingVGWs []map[string]interface{}) { propagatingVGWs = make([]map[string]interface{}, len(vg)) if len(vg) > 0 { diff --git a/outscale/resource_outscale_route_table_link.go b/outscale/resource_outscale_route_table_link.go index 4c6484e61..ad05841ff 100644 --- a/outscale/resource_outscale_route_table_link.go +++ b/outscale/resource_outscale_route_table_link.go @@ -19,13 +19,13 @@ const ( errorLinkRouteTableSetting = "error setting `%s` for Link Route Table (%s): %s" ) -func resourceOutscaleOAPILinkRouteTable() *schema.Resource { +func resourceLinkRouteTable() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPILinkRouteTableCreate, - Read: resourceOutscaleOAPILinkRouteTableRead, - Delete: resourceOutscaleOAPILinkRouteTableDelete, + Create: resourceLinkRouteTableCreate, + Read: resourceLinkRouteTableRead, + Delete: resourceLinkRouteTableDelete, Importer: &schema.ResourceImporter{ - State: resourceOutscaleOAPILinkRouteTableImportState, + State: resourceLinkRouteTableImportState, }, Schema: map[string]*schema.Schema{ "subnet_id": { @@ -54,8 +54,8 @@ func resourceOutscaleOAPILinkRouteTable() *schema.Resource { } } -func resourceOutscaleOAPILinkRouteTableCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLinkRouteTableCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI subnetID := d.Get("subnet_id").(string) routeTableID := d.Get("route_table_id").(string) log.Printf("[INFO] Creating route table link: %s => %s", subnetID, routeTableID) @@ -89,12 +89,12 @@ func resourceOutscaleOAPILinkRouteTableCreate(d *schema.ResourceData, meta inter d.SetId(resp.GetLinkRouteTableId()) - return resourceOutscaleOAPILinkRouteTableRead(d, meta) + return resourceLinkRouteTableRead(d, meta) } -func resourceOutscaleOAPILinkRouteTableRead(d *schema.ResourceData, meta interface{}) error { +func resourceLinkRouteTableRead(d *schema.ResourceData, meta interface{}) error { routeTableID := d.Get("route_table_id").(string) - linkRTable, err := readOutscaleLinkRouteTable(meta.(*OutscaleClient), routeTableID, d.Id()) + linkRTable, err := readLinkRouteTable(meta.(*Client), routeTableID, d.Id()) if err != nil { return err } @@ -111,8 +111,8 @@ func resourceOutscaleOAPILinkRouteTableRead(d *schema.ResourceData, meta interfa return nil } -func resourceOutscaleOAPILinkRouteTableDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceLinkRouteTableDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI log.Printf("[INFO] Deleting link route table: %s", d.Id()) @@ -139,7 +139,7 @@ func resourceOutscaleOAPILinkRouteTableDelete(d *schema.ResourceData, meta inter return nil } -func resourceOutscaleOAPILinkRouteTableImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceLinkRouteTableImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { parts := strings.SplitN(d.Id(), "_", 2) if len(parts) != 2 { return nil, errors.New("import format error: to import a Link Route Table, use the format {route_table_id}_{link_route_table_id}") @@ -148,7 +148,7 @@ func resourceOutscaleOAPILinkRouteTableImportState(d *schema.ResourceData, meta routeTableID := parts[0] linkRouteTableID := parts[1] - linkRTable, err := readOutscaleLinkRouteTable(meta.(*OutscaleClient), routeTableID, linkRouteTableID) + linkRTable, err := readLinkRouteTable(meta.(*Client), routeTableID, linkRouteTableID) if err != nil { return nil, fmt.Errorf("couldn't import Link Route Table(%s), error: %s", linkRouteTableID, err) } @@ -168,7 +168,7 @@ func resourceOutscaleOAPILinkRouteTableImportState(d *schema.ResourceData, meta return []*schema.ResourceData{d}, nil } -func readOutscaleLinkRouteTable(meta *OutscaleClient, routeTableID, linkRouteTableID string) (*oscgo.LinkRouteTable, error) { +func readLinkRouteTable(meta *Client, routeTableID, linkRouteTableID string) (*oscgo.LinkRouteTable, error) { conn := meta.OSCAPI var resp oscgo.ReadRouteTablesResponse diff --git a/outscale/resource_outscale_route_table_link_test.go b/outscale/resource_outscale_route_table_link_test.go index 1cf6a8e86..85de10553 100644 --- a/outscale/resource_outscale_route_table_link_test.go +++ b/outscale/resource_outscale_route_table_link_test.go @@ -14,18 +14,18 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPILinkRouteTable_basic(t *testing.T) { +func TestAccLinkRouteTable_basic(t *testing.T) { t.Parallel() var v oscgo.RouteTable resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPILinkRouteTableDestroy, + CheckDestroy: testAccCheckLinkRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPILinkRouteTableConfig, + Config: testAccLinkRouteTableConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOAPILinkRouteTableExists( + testAccCheckLinkRouteTableExists( "outscale_route_table_link.foo", &v), resource.TestCheckResourceAttrSet( "outscale_route_table_link.foo", "link_route_table_id"), @@ -37,20 +37,20 @@ func TestAccOutscaleOAPILinkRouteTable_basic(t *testing.T) { }) } -func TestAccResourceOAPILinkRouteTable_importBasic(t *testing.T) { +func TestAccResourceLinkRouteTable_importBasic(t *testing.T) { resourceName := "outscale_route_table_link.foo" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPILinkRouteTableDestroy, + CheckDestroy: testAccCheckLinkRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPILinkRouteTableConfig, + Config: testAccLinkRouteTableConfig, }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOAPILinkRouteTableImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckLinkRouteTableImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id"}, @@ -59,7 +59,7 @@ func TestAccResourceOAPILinkRouteTable_importBasic(t *testing.T) { }) } -func testAccCheckOAPILinkRouteTableImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckLinkRouteTableImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -69,8 +69,8 @@ func testAccCheckOAPILinkRouteTableImportStateIDFunc(resourceName string) resour } } -func testAccCheckOAPILinkRouteTableDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckLinkRouteTableDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_route_table_link" { @@ -107,7 +107,7 @@ func testAccCheckOAPILinkRouteTableDestroy(s *terraform.State) error { return nil } -func testAccCheckOAPILinkRouteTableExists(n string, v *oscgo.RouteTable) resource.TestCheckFunc { +func testAccCheckLinkRouteTableExists(n string, v *oscgo.RouteTable) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -118,7 +118,7 @@ func testAccCheckOAPILinkRouteTableExists(n string, v *oscgo.RouteTable) resourc return fmt.Errorf("No ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI params := oscgo.ReadRouteTablesRequest{ Filters: &oscgo.FiltersRouteTable{ @@ -152,7 +152,7 @@ func testAccCheckOAPILinkRouteTableExists(n string, v *oscgo.RouteTable) resourc } } -const testAccOAPILinkRouteTableConfig = ` +const testAccLinkRouteTableConfig = ` resource "outscale_net" "foo" { ip_range = "10.1.0.0/16" diff --git a/outscale/resource_outscale_route_table_test.go b/outscale/resource_outscale_route_table_test.go index ece906aaf..172bfa74b 100644 --- a/outscale/resource_outscale_route_table_test.go +++ b/outscale/resource_outscale_route_table_test.go @@ -16,7 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIRouteTable_basic(t *testing.T) { +func TestAccRouteTable_basic(t *testing.T) { var v oscgo.RouteTable testCheck := func(*terraform.State) error { @@ -55,20 +55,20 @@ func TestAccOutscaleOAPIRouteTable_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_route_table.foo", Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIRouteTableDestroy, + CheckDestroy: testAccCheckRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIRouteTableConfig, + Config: testAccRouteTableConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIRouteTableExists("outscale_route_table.foo", &v, nil), + testAccCheckRouteTableExists("outscale_route_table.foo", &v, nil), testCheck, ), }, { - Config: testAccOAPIRouteTableConfigChange, + Config: testAccRouteTableConfigChange, Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIRouteTableExists("outscale_route_table.foo", &v, nil), + testAccCheckRouteTableExists("outscale_route_table.foo", &v, nil), testCheckChange, ), }, @@ -76,7 +76,7 @@ func TestAccOutscaleOAPIRouteTable_basic(t *testing.T) { }) } -func TestAccOutscaleOAPIRouteTable_instance(t *testing.T) { +func TestAccRouteTable_instance(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -102,12 +102,12 @@ func TestAccOutscaleOAPIRouteTable_instance(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_route_table.foo", Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIRouteTableDestroy, + CheckDestroy: testAccCheckRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIRouteTableConfigInstance(omi, "tinav4.c2r2p2", region), + Config: testAccRouteTableConfigInstance(omi, "tinav4.c2r2p2", region), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIRouteTableExists( + testAccCheckRouteTableExists( "outscale_route_table.foo", &v, nil), testCheck, ), @@ -116,7 +116,7 @@ func TestAccOutscaleOAPIRouteTable_instance(t *testing.T) { }) } -func TestAccOutscaleOAPIRouteTable_tags(t *testing.T) { +func TestAccRouteTable_tags(t *testing.T) { value1 := ` tags { key = "name" @@ -141,42 +141,42 @@ func TestAccOutscaleOAPIRouteTable_tags(t *testing.T) { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIRouteTableDestroy, + CheckDestroy: testAccCheckRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIRouteTableConfigTags(value1), + Config: testAccRouteTableConfigTags(value1), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIRouteTableExists("outscale_route_table.foo", &rt, &rtTags), + testAccCheckRouteTableExists("outscale_route_table.foo", &rt, &rtTags), - testAccCheckOAPITags(&rtTags, "name", "Terraform-nic"), + testAccCheckTags(&rtTags, "name", "Terraform-nic"), ), }, { - Config: testAccOAPIRouteTableConfigTags(value2), + Config: testAccRouteTableConfigTags(value2), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIRouteTableExists("outscale_route_table.foo", &rt, &rtTags), - testAccCheckOAPITags(&rtTags, "name", "Terraform-RT"), - testAccCheckOAPITags(&rtTags, "name2", "Terraform-RT2"), + testAccCheckRouteTableExists("outscale_route_table.foo", &rt, &rtTags), + testAccCheckTags(&rtTags, "name", "Terraform-RT"), + testAccCheckTags(&rtTags, "name2", "Terraform-RT2"), ), }, }, }) } -func TestAccOutscaleRouteTable_importBasic(t *testing.T) { +func TestAccRouteTable_importBasic(t *testing.T) { resourceName := "outscale_route_table.foo" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIRouteTableDestroy, + CheckDestroy: testAccCheckRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIRouteTableConfig, + Config: testAccRouteTableConfig, }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOutscaleRouteTableImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckRouteTableImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id"}, @@ -185,7 +185,7 @@ func TestAccOutscaleRouteTable_importBasic(t *testing.T) { }) } -func testAccCheckOutscaleRouteTableImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckRouteTableImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -196,8 +196,8 @@ func testAccCheckOutscaleRouteTableImportStateIDFunc(resourceName string) resour } } -func testAccCheckOAPIRouteTableDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckRouteTableDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_route_table" { @@ -237,7 +237,7 @@ func testAccCheckOAPIRouteTableDestroy(s *terraform.State) error { return nil } -func testAccCheckOAPIRouteTableExists(n string, v *oscgo.RouteTable, t *[]oscgo.ResourceTag) resource.TestCheckFunc { +func testAccCheckRouteTableExists(n string, v *oscgo.RouteTable, t *[]oscgo.ResourceTag) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -248,7 +248,7 @@ func testAccCheckOAPIRouteTableExists(n string, v *oscgo.RouteTable, t *[]oscgo. return fmt.Errorf("No ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI var resp oscgo.ReadRouteTablesResponse var err error @@ -288,7 +288,7 @@ func testAccCheckOAPIRouteTableExists(n string, v *oscgo.RouteTable, t *[]oscgo. // VPC Peering connections are prefixed with pcx // Right now there is no VPC Peering resource -// func TestAccOutscaleRouteTable_vpcPeering(t *testing.T) { +// func TestAccRouteTable_vpcPeering(t *testing.T) { // var v oscgo.RouteTable // testCheck := func(*terraform.State) error { @@ -313,12 +313,12 @@ func testAccCheckOAPIRouteTableExists(n string, v *oscgo.RouteTable, t *[]oscgo. // resource.Test(t, resource.TestCase{ // PreCheck: func() { testAccPreCheck(t) }, // Providers: testAccProviders, -// CheckDestroy: testAccCheckOAPIRouteTableDestroy, +// CheckDestroy: testAccCheckRouteTableDestroy, // Steps: []resource.TestStep{ // { // Config: testAccRouteTableVpcPeeringConfig, // Check: resource.ComposeTestCheckFunc( -// testAccCheckOAPIRouteTableExists( +// testAccCheckRouteTableExists( // "outscale_route_table.foo", &v), // testCheck, // ), @@ -327,7 +327,7 @@ func testAccCheckOAPIRouteTableExists(n string, v *oscgo.RouteTable, t *[]oscgo. // }) // } -// func TestAccOutscaleRouteTable_vgwRoutePropagation(t *testing.T) { +// func TestAccRouteTable_vgwRoutePropagation(t *testing.T) { // var v oscgo.RouteTable // var vgw oscgo.VpnGateway @@ -353,13 +353,13 @@ func testAccCheckOAPIRouteTableExists(n string, v *oscgo.RouteTable, t *[]oscgo. // Providers: testAccProviders, // CheckDestroy: resource.ComposeTestCheckFunc( // testAccCheckVpnGatewayDestroy, -// testAccCheckOAPIRouteTableDestroy, +// testAccCheckRouteTableDestroy, // ), // Steps: []resource.TestStep{ // { // Config: testAccRouteTableVgwRoutePropagationConfig, // Check: resource.ComposeTestCheckFunc( -// testAccCheckOAPIRouteTableExists( +// testAccCheckRouteTableExists( // "outscale_route_table.foo", &v), // testAccCheckVpnGatewayExists( // "aws_vpn_gateway.foo", &vgw), @@ -370,7 +370,7 @@ func testAccCheckOAPIRouteTableExists(n string, v *oscgo.RouteTable, t *[]oscgo. // }) // } -const testAccOAPIRouteTableConfig = ` +const testAccRouteTableConfig = ` resource "outscale_net" "foo" { ip_range = "10.1.0.0/16" @@ -387,7 +387,7 @@ resource "outscale_route_table" "foo" { } ` -const testAccOAPIRouteTableConfigChange = ` +const testAccRouteTableConfigChange = ` resource "outscale_net" "foo" { ip_range = "10.1.0.0/16" @@ -404,7 +404,7 @@ resource "outscale_route_table" "foo" { } ` -func testAccOAPIRouteTableConfigInstance(omi, vmType, region string) string { +func testAccRouteTableConfigInstance(omi, vmType, region string) string { return fmt.Sprintf(` resource "outscale_net" "foo" { ip_range = "10.1.0.0/16" @@ -435,7 +435,7 @@ func testAccOAPIRouteTableConfigInstance(omi, vmType, region string) string { `, omi, vmType, region) } -func testAccOAPIRouteTableConfigTags(value string) string { +func testAccRouteTableConfigTags(value string) string { return fmt.Sprintf(` resource "outscale_net" "foo" { ip_range = "10.1.0.0/16" diff --git a/outscale/resource_outscale_route_test.go b/outscale/resource_outscale_route_test.go index f515d8af3..d79616afd 100644 --- a/outscale/resource_outscale_route_test.go +++ b/outscale/resource_outscale_route_test.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIRoute_noopdiff(t *testing.T) { +func TestAccRoute_noopdiff(t *testing.T) { var route oscgo.Route resource.Test(t, resource.TestCase{ @@ -21,39 +21,39 @@ func TestAccOutscaleOAPIRoute_noopdiff(t *testing.T) { }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIOutscaleRouteDestroy, + CheckDestroy: testAccCheckRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIRouteNoopChange, + Config: testAccRouteNoopChange, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIRouteExists("outscale_route.test", &route), + testAccCheckRouteExists("outscale_route.test", &route), ), }, { - Config: testAccOutscaleOAPIRouteNoopChange, + Config: testAccRouteNoopChange, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIRouteExists("outscale_route.test", &route), + testAccCheckRouteExists("outscale_route.test", &route), ), }, }, }) } -func TestAccOutscaleOAPIRoute_importBasic(t *testing.T) { +func TestAccRoute_importBasic(t *testing.T) { resourceName := "outscale_route.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIOutscaleRouteDestroy, + CheckDestroy: testAccCheckRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIRouteNoopChange, + Config: testAccRouteNoopChange, }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOutscaleOAPIRouteImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckRouteImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id", "await_active_state"}, @@ -62,20 +62,20 @@ func TestAccOutscaleOAPIRoute_importBasic(t *testing.T) { }) } -func TestAccOutscaleOAPIRoute_importWithNatService(t *testing.T) { +func TestAccRoute_importWithNatService(t *testing.T) { resourceName := "outscale_route.outscale_route_nat" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIOutscaleRouteDestroy, + CheckDestroy: testAccCheckRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIRouteWithNatService, + Config: testAccRouteWithNatService, }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOutscaleOAPIRouteImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckRouteImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id", "await_active_state", "routes"}, /*we will remove 'routes' when autorefresh after link resources Ok*/ @@ -84,7 +84,7 @@ func TestAccOutscaleOAPIRoute_importWithNatService(t *testing.T) { }) } -func TestAccOutscaleOAPIRoute_changeTarget(t *testing.T) { +func TestAccRoute_changeTarget(t *testing.T) { var route oscgo.Route resource.Test(t, resource.TestCase{ @@ -93,25 +93,25 @@ func TestAccOutscaleOAPIRoute_changeTarget(t *testing.T) { }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIOutscaleRouteDestroy, + CheckDestroy: testAccCheckRouteDestroy, Steps: []resource.TestStep{ { Config: computeConfigTestChangeTarget([]string{"nat_service_id"}), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIRouteExists("outscale_route.rtnatdef", &route), + testAccCheckRouteExists("outscale_route.rtnatdef", &route), ), }, { Config: computeConfigTestChangeTarget([]string{"gateway_id"}), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIRouteExists("outscale_route.rtnatdef", &route), + testAccCheckRouteExists("outscale_route.rtnatdef", &route), ), }, }, }) } -func TestAccOutscaleOAPIRoute_onlyOneTarget(t *testing.T) { +func TestAccRoute_onlyOneTarget(t *testing.T) { regex := regexp.MustCompile(".*") resource.Test(t, resource.TestCase{ Providers: testAccProviders, @@ -119,7 +119,7 @@ func TestAccOutscaleOAPIRoute_onlyOneTarget(t *testing.T) { testAccPreCheck(t) }, - CheckDestroy: testAccCheckOAPIOutscaleRouteDestroy, + CheckDestroy: testAccCheckRouteDestroy, Steps: []resource.TestStep{ { Config: computeConfigTestChangeTarget([]string{"nat_service_id"}), @@ -204,7 +204,7 @@ func TestAccOutscaleOAPIRoute_onlyOneTarget(t *testing.T) { }) } -func testAccCheckOutscaleOAPIRouteImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckRouteImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -214,7 +214,7 @@ func testAccCheckOutscaleOAPIRouteImportStateIDFunc(resourceName string) resourc } } -func testAccCheckOutscaleOAPIRouteExists(n string, res *oscgo.Route) resource.TestCheckFunc { +func testAccCheckRouteExists(n string, res *oscgo.Route) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -225,8 +225,8 @@ func testAccCheckOutscaleOAPIRouteExists(n string, res *oscgo.Route) resource.Te return fmt.Errorf("No ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI - r, _, err := findResourceOAPIRoute( + conn := testAccProvider.Meta().(*Client).OSCAPI + r, _, err := findResourceRoute( conn, rs.Primary.Attributes["route_table_id"], rs.Primary.Attributes["destination_ip_range"], @@ -246,14 +246,14 @@ func testAccCheckOutscaleOAPIRouteExists(n string, res *oscgo.Route) resource.Te } } -func testAccCheckOAPIOutscaleRouteDestroy(s *terraform.State) error { +func testAccCheckRouteDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_route" { continue } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI - route, _, err := findResourceOAPIRoute( + conn := testAccProvider.Meta().(*Client).OSCAPI + route, _, err := findResourceRoute( conn, rs.Primary.Attributes["route_table_id"], rs.Primary.Attributes["destination_ip_range"], @@ -267,7 +267,7 @@ func testAccCheckOAPIOutscaleRouteDestroy(s *terraform.State) error { return nil } -var testAccOutscaleOAPIRouteNoopChange = fmt.Sprint(` +var testAccRouteNoopChange = fmt.Sprint(` resource "outscale_net" "test" { ip_range = "10.0.0.0/24" } @@ -290,7 +290,7 @@ var testAccOutscaleOAPIRouteNoopChange = fmt.Sprint(` } `) -var testAccOutscaleOAPIRouteWithNatService = fmt.Sprint(` +var testAccRouteWithNatService = fmt.Sprint(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" tags { @@ -382,10 +382,10 @@ func computeConfigTestChangeTarget(targets []string) string { } } - return fmt.Sprintf(testAccOutscaleOAPIRouteTemplateChangeTarget, strings.Join(extra_configs, "\n")) + return fmt.Sprintf(testAccRouteTemplateChangeTarget, strings.Join(extra_configs, "\n")) } -var testAccOutscaleOAPIRouteTemplateChangeTarget = ` +var testAccRouteTemplateChangeTarget = ` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" tags { diff --git a/outscale/resource_outscale_security_group.go b/outscale/resource_outscale_security_group.go index b272635f2..3f7e06883 100644 --- a/outscale/resource_outscale_security_group.go +++ b/outscale/resource_outscale_security_group.go @@ -14,12 +14,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPISecurityGroup() *schema.Resource { +func resourceSecurityGroup() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPISecurityGroupCreate, - Read: resourceOutscaleOAPISecurityGroupRead, - Delete: resourceOutscaleOAPISecurityGroupDelete, - Update: resourceOutscaleOAPISecurityGroupUpdate, + Create: resourceSecurityGroupCreate, + Read: resourceSecurityGroupRead, + Delete: resourceSecurityGroupDelete, + Update: resourceSecurityGroupUpdate, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -57,8 +57,8 @@ func resourceOutscaleOAPISecurityGroup() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "inbound_rules": getOAPIIPPerms(), - "outbound_rules": getOAPIIPPerms(), + "inbound_rules": getIPPerms(), + "outbound_rules": getIPPerms(), "account_id": { Type: schema.TypeString, Computed: true, @@ -69,7 +69,7 @@ func resourceOutscaleOAPISecurityGroup() *schema.Resource { ForceNew: true, Default: false, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "tag": tagsSchema(), "request_id": { Type: schema.TypeString, @@ -79,7 +79,7 @@ func resourceOutscaleOAPISecurityGroup() *schema.Resource { } } -func getOAPIIPPerms() *schema.Schema { +func getIPPerms() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Computed: true, @@ -114,8 +114,8 @@ func getOAPIIPPerms() *schema.Schema { } } -func resourceOutscaleOAPISecurityGroupCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSecurityGroupCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI securityGroupOpts := oscgo.CreateSecurityGroupRequest{} @@ -200,7 +200,7 @@ func resourceOutscaleOAPISecurityGroupCreate(d *schema.ResourceData, meta interf stateConf := &resource.StateChangeConf{ Pending: []string{""}, Target: []string{"exists", "failed"}, - Refresh: SGOAPIStateRefreshFunc(conn, d.Id()), + Refresh: SGStateRefreshFunc(conn, d.Id()), Timeout: 3 * time.Minute, } @@ -212,17 +212,17 @@ func resourceOutscaleOAPISecurityGroupCreate(d *schema.ResourceData, meta interf } if d.IsNewResource() { - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") } - return resourceOutscaleOAPISecurityGroupRead(d, meta) + return resourceSecurityGroupRead(d, meta) } -func resourceOutscaleOAPISecurityGroupRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSecurityGroupRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI sg, _, err := readSecurityGroups(conn, d.Id()) if err != nil { @@ -250,21 +250,21 @@ func resourceOutscaleOAPISecurityGroupRead(d *schema.ResourceData, meta interfac if err := d.Set("account_id", sg.GetAccountId()); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(sg.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(sg.GetTags())); err != nil { return err } - if err := d.Set("inbound_rules", flattenOAPISecurityGroupRule(sg.GetInboundRules())); err != nil { + if err := d.Set("inbound_rules", flattenSecurityGroupRule(sg.GetInboundRules())); err != nil { return err } d.SetId(sg.GetSecurityGroupId()) - return d.Set("outbound_rules", flattenOAPISecurityGroupRule(sg.GetOutboundRules())) + return d.Set("outbound_rules", flattenSecurityGroupRule(sg.GetOutboundRules())) } -func resourceOutscaleOAPISecurityGroupDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI log.Printf("[DEBUG] Security Group destroy: %v", d.Id()) securityGroupID := d.Id() @@ -282,8 +282,8 @@ func resourceOutscaleOAPISecurityGroupDelete(d *schema.ResourceData, meta interf }) } -// SGOAPIStateRefreshFunc ... -func SGOAPIStateRefreshFunc(conn *oscgo.APIClient, id string) resource.StateRefreshFunc { +// SGStateRefreshFunc ... +func SGStateRefreshFunc(conn *oscgo.APIClient, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { securityGroup, _, err := readSecurityGroups(conn, id) if err != nil { @@ -293,19 +293,19 @@ func SGOAPIStateRefreshFunc(conn *oscgo.APIClient, id string) resource.StateRefr } } -func resourceOutscaleOAPISecurityGroupUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOutscaleOAPISecurityGroupRead(d, meta) + return resourceSecurityGroupRead(d, meta) } func readSecurityGroups(client *oscgo.APIClient, securityGroupID string) (*oscgo.SecurityGroup, *oscgo.ReadSecurityGroupsResponse, error) { diff --git a/outscale/resource_outscale_security_group_rule.go b/outscale/resource_outscale_security_group_rule.go index fd65af18c..3115fd8e5 100644 --- a/outscale/resource_outscale_security_group_rule.go +++ b/outscale/resource_outscale_security_group_rule.go @@ -18,13 +18,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) -func resourceOutscaleOAPIOutboundRule() *schema.Resource { +func resourceOutboundRule() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIOutboundRuleCreate, - Read: resourceOutscaleOAPIOutboundRuleRead, - Delete: resourceOutscaleOAPIOutboundRuleDelete, + Create: resourceOutboundRuleCreate, + Read: resourceOutboundRuleRead, + Delete: resourceOutboundRuleDelete, Importer: &schema.ResourceImporter{ - State: resourceOutscaleOAPISecurityGroupRuleImportState, + State: resourceSecurityGroupRuleImportState, }, Schema: map[string]*schema.Schema{ "flow": { @@ -89,8 +89,8 @@ func resourceOutscaleOAPIOutboundRule() *schema.Resource { } } -func resourceOutscaleOAPIOutboundRuleCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceOutboundRuleCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.CreateSecurityGroupRuleRequest{ Flow: d.Get("flow").(string), @@ -135,11 +135,11 @@ func resourceOutscaleOAPIOutboundRuleCreate(d *schema.ResourceData, meta interfa d.SetId(*resp.GetSecurityGroup().SecurityGroupId) - return resourceOutscaleOAPIOutboundRuleRead(d, meta) + return resourceOutboundRuleRead(d, meta) } -func resourceOutscaleOAPIOutboundRuleRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceOutboundRuleRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI sg, _, err := readSecurityGroups(conn, d.Id()) if err != nil { @@ -162,8 +162,8 @@ func resourceOutscaleOAPIOutboundRuleRead(d *schema.ResourceData, meta interface return nil } -func resourceOutscaleOAPIOutboundRuleDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceOutboundRuleDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.DeleteSecurityGroupRuleRequest{ Flow: d.Get("flow").(string), @@ -354,11 +354,11 @@ func getRulesSchema(isForAttr bool) *schema.Schema { } } -func resourceOutscaleOAPISecurityGroupRuleImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceSecurityGroupRuleImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { // example: sg-53173ec7_inbound_tcp_80_80_80.14.129.222/32 // example: sg-53173ec7_inbound_tcp_80_80_sg-53173ec7 - conn := meta.(*OutscaleClient).OSCAPI + conn := meta.(*Client).OSCAPI parts := strings.SplitN(d.Id(), "_", 6) if len(parts) != 6 { diff --git a/outscale/resource_outscale_security_group_rule_test.go b/outscale/resource_outscale_security_group_rule_test.go index cab8ff092..55888d4a0 100644 --- a/outscale/resource_outscale_security_group_rule_test.go +++ b/outscale/resource_outscale_security_group_rule_test.go @@ -16,7 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleSecurityGroupRule_basic(t *testing.T) { +func TestAccSecurityGroupRule_basic(t *testing.T) { t.Parallel() resourceName := "outscale_security_group_rule.outscale_security_group_rule_https" @@ -27,19 +27,19 @@ func TestAccOutscaleSecurityGroupRule_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPISecurityGroupRuleDestroy, + CheckDestroy: testAccCheckSecurityGroupRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISecurityGroupRuleEgressConfig(rInt), + Config: testAccSecurityGroupRuleEgressConfig(rInt), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIRuleExists(resourceName, &group), - testAccCheckOutscaleOAPIRuleAttributes(resourceName, &group, nil, "Inbound"), + testAccCheckRuleExists(resourceName, &group), + testAccCheckRuleAttributes(resourceName, &group, nil, "Inbound"), ), }, { ResourceName: resourceName, ImportState: true, - ImportStateIdFunc: testAccCheckOutscaleOAPIRuleImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckRuleImportStateIDFunc(resourceName), ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id"}, }, @@ -50,7 +50,7 @@ func TestAccOutscaleSecurityGroupRule_basic(t *testing.T) { } } -func TestAccOutscaleSecurityGroupRule_withSecurityGroupMember(t *testing.T) { +func TestAccSecurityGroupRule_withSecurityGroupMember(t *testing.T) { t.Parallel() rInt := acctest.RandInt() accountID := os.Getenv("OUTSCALE_ACCOUNT") @@ -58,17 +58,17 @@ func TestAccOutscaleSecurityGroupRule_withSecurityGroupMember(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPISecurityGroupRuleDestroy, + CheckDestroy: testAccCheckSecurityGroupRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISecurityGroupRuleWithGroupMembers(rInt, accountID), + Config: testAccSecurityGroupRuleWithGroupMembers(rInt, accountID), }, }, }) } -func testAccCheckOutscaleOAPISecurityGroupRuleDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckSecurityGroupRuleDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_security_group_rule" { @@ -83,7 +83,7 @@ func testAccCheckOutscaleOAPISecurityGroupRuleDestroy(s *terraform.State) error return nil } -func testAccCheckOutscaleOAPIRuleAttributes(n string, group *oscgo.SecurityGroup, p *oscgo.SecurityGroupRule, ruleType string) resource.TestCheckFunc { +func testAccCheckRuleAttributes(n string, group *oscgo.SecurityGroup, p *oscgo.SecurityGroupRule, ruleType string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -181,7 +181,7 @@ func testAccCheckOutscaleOAPIRuleAttributes(n string, group *oscgo.SecurityGroup } } -func testAccCheckOutscaleOAPIRuleExists(n string, group *oscgo.SecurityGroup) resource.TestCheckFunc { +func testAccCheckRuleExists(n string, group *oscgo.SecurityGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -192,7 +192,7 @@ func testAccCheckOutscaleOAPIRuleExists(n string, group *oscgo.SecurityGroup) re return fmt.Errorf("No Security Group is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI req := oscgo.ReadSecurityGroupsRequest{ Filters: &oscgo.FiltersSecurityGroup{ SecurityGroupIds: &[]string{rs.Primary.ID}, @@ -223,7 +223,7 @@ func testAccCheckOutscaleOAPIRuleExists(n string, group *oscgo.SecurityGroup) re } } -func testAccCheckOutscaleOAPIRuleImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckRuleImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -233,7 +233,7 @@ func testAccCheckOutscaleOAPIRuleImportStateIDFunc(resourceName string) resource } } -func testAccOutscaleOAPISecurityGroupRuleEgressConfig(rInt int) string { +func testAccSecurityGroupRuleEgressConfig(rInt int) string { return fmt.Sprintf(` resource "outscale_security_group_rule" "outscale_security_group_rule" { flow = "Inbound" @@ -260,7 +260,7 @@ func testAccOutscaleOAPISecurityGroupRuleEgressConfig(rInt int) string { `, rInt) } -func testAccOutscaleOAPISecurityGroupRuleWithGroupMembers(rInt int, accountID string) string { +func testAccSecurityGroupRuleWithGroupMembers(rInt int, accountID string) string { return fmt.Sprintf(` resource "outscale_security_group" "outscale_security_group" { description = "test group" diff --git a/outscale/resource_outscale_security_group_test.go b/outscale/resource_outscale_security_group_test.go index ea7c86c33..9422317ce 100644 --- a/outscale/resource_outscale_security_group_test.go +++ b/outscale/resource_outscale_security_group_test.go @@ -11,19 +11,19 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPISecurityGroup(t *testing.T) { +func TestAccSecurityGroup(t *testing.T) { var group oscgo.SecurityGroup rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPISGRuleDestroy, + CheckDestroy: testAccCheckSGRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISecurityGroupConfig(rInt), + Config: testAccSecurityGroupConfig(rInt), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPISecurityGroupRuleExists("outscale_security_group.web", &group), + testAccCheckSecurityGroupRuleExists("outscale_security_group.web", &group), resource.TestCheckResourceAttr( "outscale_security_group.web", "security_group_name", fmt.Sprintf("terraform_test_%d", rInt)), ), @@ -32,8 +32,8 @@ func TestAccOutscaleOAPISecurityGroup(t *testing.T) { }) } -func testAccCheckOutscaleOAPISGRuleDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckSGRuleDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_security_group" { @@ -48,9 +48,9 @@ func testAccCheckOutscaleOAPISGRuleDestroy(s *terraform.State) error { return nil } -func testAccCheckOutscaleOAPISecurityGroupRuleExists(n string, group *oscgo.SecurityGroup) resource.TestCheckFunc { +func testAccCheckSecurityGroupRuleExists(n string, group *oscgo.SecurityGroup) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI rs, ok := s.RootModule().Resources[n] if !ok { @@ -69,7 +69,7 @@ func testAccCheckOutscaleOAPISecurityGroupRuleExists(n string, group *oscgo.Secu } } -func testAccOutscaleOAPISecurityGroupConfig(rInt int) string { +func testAccSecurityGroupConfig(rInt int) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_server_certificate.go b/outscale/resource_outscale_server_certificate.go index 2df17c79a..c2be2e418 100644 --- a/outscale/resource_outscale_server_certificate.go +++ b/outscale/resource_outscale_server_certificate.go @@ -14,12 +14,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPIServerCertificate() *schema.Resource { +func resourceServerCertificate() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIServerCertificateCreate, - Read: resourceOutscaleOAPIServerCertificateRead, - Update: resourceOutscaleOAPIServerCertificateUpdate, - Delete: resourceOutscaleOAPIServerCertificateDelete, + Create: resourceServerCertificateCreate, + Read: resourceServerCertificateRead, + Update: resourceServerCertificateUpdate, + Delete: resourceServerCertificateDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -71,8 +71,8 @@ func resourceOutscaleOAPIServerCertificate() *schema.Resource { } } -func resourceOutscaleOAPIServerCertificateCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceServerCertificateCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.CreateServerCertificateRequest{ Body: d.Get("body").(string), @@ -113,11 +113,11 @@ func resourceOutscaleOAPIServerCertificateCreate(d *schema.ResourceData, meta in d.SetId(cast.ToString(resp.ServerCertificate.Id)) - return resourceOutscaleOAPIServerCertificateRead(d, meta) + return resourceServerCertificateRead(d, meta) } -func resourceOutscaleOAPIServerCertificateRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceServerCertificateRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() @@ -164,8 +164,8 @@ func resourceOutscaleOAPIServerCertificateRead(d *schema.ResourceData, meta inte return nil } -func resourceOutscaleOAPIServerCertificateUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceServerCertificateUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI oldName, newName := d.GetChange("name") req := oscgo.UpdateServerCertificateRequest{ @@ -191,11 +191,11 @@ func resourceOutscaleOAPIServerCertificateUpdate(d *schema.ResourceData, meta in return fmt.Errorf("[DEBUG] Error update Server Certificate: %s", utils.GetErrorResponse(err)) } - return resourceOutscaleOAPIServerCertificateRead(d, meta) + return resourceServerCertificateRead(d, meta) } -func resourceOutscaleOAPIServerCertificateDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceServerCertificateDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.DeleteServerCertificateRequest{ Name: d.Get("name").(string), diff --git a/outscale/resource_outscale_server_certificate_test.go b/outscale/resource_outscale_server_certificate_test.go index 822fa6fb3..085081933 100644 --- a/outscale/resource_outscale_server_certificate_test.go +++ b/outscale/resource_outscale_server_certificate_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIServerCertificate_basic(t *testing.T) { +func TestAccServerCertificate_basic(t *testing.T) { t.Parallel() resourceName := "outscale_server_certificate.test" rName := acctest.RandomWithPrefix("acc-test") @@ -106,18 +106,18 @@ kbcI5Y2wveEgMqPSRya2OapYGiPeqYhg6JAGPRXtOfOq9IUDcPuc2emnihNpSa8y resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleServerCertificateDestroy, + CheckDestroy: testAccCheckServerCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIServerCertificateConfig(rName, body, private), + Config: testAccServerCertificateConfig(rName, body, private), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleServerCertificateExists(resourceName), + testAccCheckServerCertificateExists(resourceName), ), }, { - Config: testAccOutscaleOAPIServerCertificateConfig(rNameUpdated, body, private), + Config: testAccServerCertificateConfig(rNameUpdated, body, private), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleServerCertificateExists(resourceName), + testAccCheckServerCertificateExists(resourceName), ), }, { @@ -130,14 +130,14 @@ kbcI5Y2wveEgMqPSRya2OapYGiPeqYhg6JAGPRXtOfOq9IUDcPuc2emnihNpSa8y }) } -func testAccCheckOutscaleServerCertificateExists(n string) resource.TestCheckFunc { +func testAccCheckServerCertificateExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI if rs.Primary.ID == "" { return fmt.Errorf("No id is set") @@ -171,8 +171,8 @@ func testAccCheckOutscaleServerCertificateExists(n string) resource.TestCheckFun } } -func testAccCheckOutscaleServerCertificateDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckServerCertificateDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_server_certificate_link" { @@ -209,7 +209,7 @@ func testAccCheckOutscaleServerCertificateDestroy(s *terraform.State) error { return nil } -func testAccOutscaleOAPIServerCertificateConfig(name, body, privateKey string) string { +func testAccServerCertificateConfig(name, body, privateKey string) string { return fmt.Sprintf(` resource "outscale_server_certificate" "test" { name = %[1]q diff --git a/outscale/resource_outscale_snapshot.go b/outscale/resource_outscale_snapshot.go index e4e46fe8b..b63255682 100644 --- a/outscale/resource_outscale_snapshot.go +++ b/outscale/resource_outscale_snapshot.go @@ -13,12 +13,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPISnapshot() *schema.Resource { +func resourceSnapshot() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPISnapshotCreate, - Read: resourceOutscaleOAPISnapshotRead, - Update: resourceOutscaleOAPISnapshotUpdate, - Delete: resourceOutscaleOAPISnapshotDelete, + Create: resourceSnapshotCreate, + Read: resourceSnapshotRead, + Update: resourceSnapshotUpdate, + Delete: resourceSnapshotDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -101,7 +101,7 @@ func resourceOutscaleOAPISnapshot() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "volume_size": { Type: schema.TypeInt, Computed: true, @@ -114,8 +114,8 @@ func resourceOutscaleOAPISnapshot() *schema.Resource { } } -func resourceOutscaleOAPISnapshotCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSnapshotCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI v, ok := d.GetOk("volume_id") snp, sok := d.GetOk("snapshot_size") @@ -170,10 +170,10 @@ func resourceOutscaleOAPISnapshotCreate(d *schema.ResourceData, meta interface{} stateConf := &resource.StateChangeConf{ Pending: []string{"pending", "pending/queued", "queued", "importing"}, Target: []string{"completed"}, - Refresh: SnapshotOAPIStateRefreshFunc(conn, resp.Snapshot.GetSnapshotId()), - Timeout: OutscaleImageRetryTimeout, - Delay: OutscaleImageRetryDelay, - MinTimeout: OutscaleImageRetryMinTimeout, + Refresh: SnapshotStateRefreshFunc(conn, resp.Snapshot.GetSnapshotId()), + Timeout: ImageRetryTimeout, + Delay: ImageRetryDelay, + MinTimeout: ImageRetryMinTimeout, } _, err = stateConf.WaitForState() @@ -190,11 +190,11 @@ func resourceOutscaleOAPISnapshotCreate(d *schema.ResourceData, meta interface{} d.SetId(resp.Snapshot.GetSnapshotId()) - return resourceOutscaleOAPISnapshotRead(d, meta) + return resourceSnapshotRead(d, meta) } -func resourceOutscaleOAPISnapshotRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSnapshotRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.ReadSnapshotsRequest{ Filters: &oscgo.FiltersSnapshot{SnapshotIds: &[]string{d.Id()}}, @@ -236,7 +236,7 @@ func resourceOutscaleOAPISnapshotRead(d *schema.ResourceData, meta interface{}) if err := set("creation_date", snapshot.GetCreationDate()); err != nil { return err } - if err := set("permissions_to_create_volume", omiOAPIPermissionToLuch(&permisions)); err != nil { + if err := set("permissions_to_create_volume", omiPermissionToLuch(&permisions)); err != nil { return err } if err := set("progress", snapshot.GetProgress()); err != nil { @@ -248,7 +248,7 @@ func resourceOutscaleOAPISnapshotRead(d *schema.ResourceData, meta interface{}) if err := set("state", snapshot.GetState()); err != nil { return err } - if err := set("tags", tagsOSCAPIToMap(snapshot.GetTags())); err != nil { + if err := set("tags", tagsToMap(snapshot.GetTags())); err != nil { return err } if err := set("volume_size", snapshot.GetVolumeSize()); err != nil { @@ -258,23 +258,23 @@ func resourceOutscaleOAPISnapshotRead(d *schema.ResourceData, meta interface{}) }) } -func resourceOutscaleOAPISnapshotUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSnapshotUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOutscaleOAPISnapshotRead(d, meta) + return resourceSnapshotRead(d, meta) } -func resourceOutscaleOAPISnapshotDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSnapshotDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI return resource.Retry(5*time.Minute, func() *resource.RetryError { request := oscgo.DeleteSnapshotRequest{SnapshotId: d.Id()} @@ -286,8 +286,8 @@ func resourceOutscaleOAPISnapshotDelete(d *schema.ResourceData, meta interface{} }) } -// SnapshotOAPIStateRefreshFunc ... -func SnapshotOAPIStateRefreshFunc(client *oscgo.APIClient, id string) resource.StateRefreshFunc { +// SnapshotStateRefreshFunc ... +func SnapshotStateRefreshFunc(client *oscgo.APIClient, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { emptyResp := oscgo.ReadSnapshotsResponse{} diff --git a/outscale/resource_outscale_snapshot_attributes.go b/outscale/resource_outscale_snapshot_attributes.go index 3959d56bb..d4df00866 100644 --- a/outscale/resource_outscale_snapshot_attributes.go +++ b/outscale/resource_outscale_snapshot_attributes.go @@ -12,11 +12,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourcedOutscaleOAPISnapshotAttributes() *schema.Resource { +func resourcedSnapshotAttributes() *schema.Resource { return &schema.Resource{ - Create: resourcedOutscaleOAPISnapshotAttributesCreate, - Read: resourcedOutscaleOAPISnapshotAttributesRead, - Delete: resourcedOutscaleOAPISnapshotAttributesDelete, + Create: resourcedSnapshotAttributesCreate, + Read: resourcedSnapshotAttributesRead, + Delete: resourcedSnapshotAttributesDelete, Schema: map[string]*schema.Schema{ "permissions_to_create_volume_additions": { @@ -73,8 +73,8 @@ func resourcedOutscaleOAPISnapshotAttributes() *schema.Resource { } } -func resourcedOutscaleOAPISnapshotAttributesCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourcedSnapshotAttributesCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI snapshotID := d.Get("snapshot_id").(string) @@ -148,11 +148,11 @@ func resourcedOutscaleOAPISnapshotAttributesCreate(d *schema.ResourceData, meta } d.SetId(snapshotID) - return resourcedOutscaleOAPISnapshotAttributesRead(d, meta) + return resourcedSnapshotAttributesRead(d, meta) } -func resourcedOutscaleOAPISnapshotAttributesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourcedSnapshotAttributesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var resp oscgo.ReadSnapshotsResponse err := resource.Retry(2*time.Minute, func() *resource.RetryError { @@ -187,7 +187,7 @@ func resourcedOutscaleOAPISnapshotAttributesRead(d *schema.ResourceData, meta in return nil } -func resourcedOutscaleOAPISnapshotAttributesDelete(d *schema.ResourceData, meta interface{}) error { +func resourcedSnapshotAttributesDelete(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil diff --git a/outscale/resource_outscale_snapshot_attributes_test.go b/outscale/resource_outscale_snapshot_attributes_test.go index 51cbcfa3b..6f43287a5 100644 --- a/outscale/resource_outscale_snapshot_attributes_test.go +++ b/outscale/resource_outscale_snapshot_attributes_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccOutscaleOAPISnapshotAttributes_Basic(t *testing.T) { +func TestAccSnapshotAttributes_Basic(t *testing.T) { t.Skip() var snapshotID string accountID := os.Getenv("OUTSCALE_ACCOUNT") @@ -18,13 +18,13 @@ func TestAccOutscaleOAPISnapshotAttributes_Basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotAttributesConfig(true, false, accountID), + Config: testAccSnapshotAttributesConfig(true, false, accountID), Check: resource.ComposeTestCheckFunc( testCheckResourceGetAttr("outscale_snapshot.test", "id", &snapshotID), ), }, { - Config: testAccOutscaleOAPISnapshotAttributesConfig(true, true, accountID), + Config: testAccSnapshotAttributesConfig(true, true, accountID), Check: resource.ComposeTestCheckFunc( testCheckResourceGetAttr("outscale_snapshot.test", "id", &snapshotID), ), @@ -33,7 +33,7 @@ func TestAccOutscaleOAPISnapshotAttributes_Basic(t *testing.T) { }) } -func testAccOutscaleOAPISnapshotAttributesConfig(includeAddition, includeRemoval bool, aid string) string { +func testAccSnapshotAttributesConfig(includeAddition, includeRemoval bool, aid string) string { base := fmt.Sprintf(` resource "outscale_volume" "description_test" { subregion_name = "eu-west-2a" diff --git a/outscale/resource_outscale_snapshot_export_task.go b/outscale/resource_outscale_snapshot_export_task.go index 2de8c4074..70c94c7d1 100644 --- a/outscale/resource_outscale_snapshot_export_task.go +++ b/outscale/resource_outscale_snapshot_export_task.go @@ -14,12 +14,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPISnapshotExportTask() *schema.Resource { +func resourceSnapshotExportTask() *schema.Resource { return &schema.Resource{ - Create: resourceOAPISnapshotExportTaskCreate, - Read: resourceOAPISnapshotExportTaskRead, - Update: resourceOAPISnapshotExportTaskUpdate, - Delete: resourceOAPISnapshotExportTaskDelete, + Create: resourceSnapshotExportTaskCreate, + Read: resourceSnapshotExportTaskRead, + Update: resourceSnapshotExportTaskUpdate, + Delete: resourceSnapshotExportTaskDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -99,13 +99,13 @@ func resourceOutscaleOAPISnapshotExportTask() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), }, } } -func resourceOAPISnapshotExportTaskCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSnapshotExportTaskCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI eto, etoOk := d.GetOk("osu_export") v, ok := d.GetOk("snapshot_id") @@ -169,21 +169,21 @@ func resourceOAPISnapshotExportTaskCreate(d *schema.ResourceData, meta interface id := resp.SnapshotExportTask.GetTaskId() d.SetId(id) if d.IsNewResource() { - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") } - _, err = resourceOutscaleSnapshotTaskWaitForAvailable(id, conn) + _, err = resourceSnapshotTaskWaitForAvailable(id, conn) if err != nil { return err } - return resourceOAPISnapshotExportTaskRead(d, meta) + return resourceSnapshotExportTaskRead(d, meta) } -func resourceOAPISnapshotExportTaskRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSnapshotExportTaskRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var resp oscgo.ReadSnapshotExportTasksResponse filter := &oscgo.FiltersExportTask{TaskIds: &[]string{d.Id()}} @@ -254,37 +254,37 @@ func resourceOAPISnapshotExportTaskRead(d *schema.ResourceData, meta interface{} if err = d.Set("osu_export", exp); err != nil { return err } - if err = d.Set("tags", tagsOSCAPIToMap(v.GetTags())); err != nil { + if err = d.Set("tags", tagsToMap(v.GetTags())); err != nil { return err } return nil } -func resourceOAPISnapshotExportTaskUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSnapshotExportTaskUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOAPISnapshotExportTaskRead(d, meta) + return resourceSnapshotExportTaskRead(d, meta) } -func resourceOutscaleSnapshotTaskWaitForAvailable(id string, client *oscgo.APIClient) (oscgo.SnapshotExportTask, error) { +func resourceSnapshotTaskWaitForAvailable(id string, client *oscgo.APIClient) (oscgo.SnapshotExportTask, error) { log.Printf("Waiting for Image Task %s to become available...", id) var snap oscgo.SnapshotExportTask stateConf := &resource.StateChangeConf{ Pending: []string{"pending", "pending/queued", "queued"}, Target: []string{"completed", "active"}, Refresh: SnapshotTaskStateRefreshFunc(client, id), - Timeout: OutscaleImageRetryTimeout, - Delay: OutscaleImageRetryDelay, - MinTimeout: OutscaleImageRetryMinTimeout, + Timeout: ImageRetryTimeout, + Delay: ImageRetryDelay, + MinTimeout: ImageRetryMinTimeout, } info, err := stateConf.WaitForState() @@ -295,7 +295,7 @@ func resourceOutscaleSnapshotTaskWaitForAvailable(id string, client *oscgo.APICl return snap, nil } -func resourceOAPISnapshotExportTaskDelete(d *schema.ResourceData, meta interface{}) error { +func resourceSnapshotExportTaskDelete(d *schema.ResourceData, meta interface{}) error { d.SetId("") if err := d.Set("osu_export", nil); err != nil { return err diff --git a/outscale/resource_outscale_snapshot_export_task_test.go b/outscale/resource_outscale_snapshot_export_task_test.go index 30b712557..63d467103 100644 --- a/outscale/resource_outscale_snapshot_export_task_test.go +++ b/outscale/resource_outscale_snapshot_export_task_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform/helper/acctest" ) -func TestAccOutscaleOAPISnapshotExportTask_basic(t *testing.T) { +func TestAccSnapshotExportTask_basic(t *testing.T) { osuBucketNames := []string{ acctest.RandomWithPrefix("terraform-export-bucket-"), acctest.RandomWithPrefix("terraform-export-bucket-"), @@ -29,22 +29,22 @@ func TestAccOutscaleOAPISnapshotExportTask_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotExportTaskConfig("", osuBucketNames[0]), + Config: testAccSnapshotExportTaskConfig("", osuBucketNames[0]), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPISnapshotExportTaskExists("outscale_snapshot_export_task.outscale_snapshot_export_task"), + testAccCheckSnapshotExportTaskExists("outscale_snapshot_export_task.outscale_snapshot_export_task"), ), }, { - Config: testAccOutscaleOAPISnapshotExportTaskConfig(tags, osuBucketNames[1]), + Config: testAccSnapshotExportTaskConfig(tags, osuBucketNames[1]), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPISnapshotExportTaskExists("outscale_snapshot_export_task.outscale_snapshot_export_task"), + testAccCheckSnapshotExportTaskExists("outscale_snapshot_export_task.outscale_snapshot_export_task"), ), }, }, }) } -func testAccCheckOutscaleOAPISnapshotExportTaskExists(n string) resource.TestCheckFunc { +func testAccCheckSnapshotExportTaskExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -59,7 +59,7 @@ func testAccCheckOutscaleOAPISnapshotExportTaskExists(n string) resource.TestChe } } -func testAccOutscaleOAPISnapshotExportTaskConfig(tags, osuBucketName string) string { +func testAccSnapshotExportTaskConfig(tags, osuBucketName string) string { return fmt.Sprintf(` resource "outscale_volume" "outscale_volume_snap" { subregion_name = "eu-west-2a" diff --git a/outscale/resource_outscale_snapshot_test.go b/outscale/resource_outscale_snapshot_test.go index 2f7f8f74f..e08952605 100644 --- a/outscale/resource_outscale_snapshot_test.go +++ b/outscale/resource_outscale_snapshot_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPISnapshot_basic(t *testing.T) { +func TestAccSnapshot_basic(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -24,16 +24,16 @@ func TestAccOutscaleOAPISnapshot_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotConfig(region), + Config: testAccSnapshotConfig(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPISnapshotExists("outscale_snapshot.outscale_snapshot", &v), + testAccCheckSnapshotExists("outscale_snapshot.outscale_snapshot", &v), ), }, }, }) } -func TestAccOutscaleOAPISnapshot_withDescription(t *testing.T) { +func TestAccSnapshot_withDescription(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -43,9 +43,9 @@ func TestAccOutscaleOAPISnapshot_withDescription(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotConfigWithDescription(region), + Config: testAccSnapshotConfigWithDescription(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPISnapshotExists("outscale_snapshot.test", &v), + testAccCheckSnapshotExists("outscale_snapshot.test", &v), resource.TestCheckResourceAttr("outscale_snapshot.test", "description", "Snapshot Acceptance Test"), ), }, @@ -53,7 +53,7 @@ func TestAccOutscaleOAPISnapshot_withDescription(t *testing.T) { }) } -func TestAccOutscaleOAPISnapshot_CopySnapshot(t *testing.T) { +func TestAccSnapshot_CopySnapshot(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -63,9 +63,9 @@ func TestAccOutscaleOAPISnapshot_CopySnapshot(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotConfigCopySnapshot(region), + Config: testAccSnapshotConfigCopySnapshot(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPISnapshotExists("outscale_snapshot.test", &v), + testAccCheckSnapshotExists("outscale_snapshot.test", &v), resource.TestCheckResourceAttr("outscale_snapshot.test", "description", "Target Snapshot Acceptance Test"), ), }, @@ -73,7 +73,7 @@ func TestAccOutscaleOAPISnapshot_CopySnapshot(t *testing.T) { }) } -func TestAccOutscaleOAPISnapshot_UpdateTags(t *testing.T) { +func TestAccSnapshot_UpdateTags(t *testing.T) { region := os.Getenv("OUTSCALE_REGION") //var v oscgo.Snapshot @@ -82,18 +82,18 @@ func TestAccOutscaleOAPISnapshot_UpdateTags(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotConfigUpdateTags(region, "Terraform-Snapshot"), + Config: testAccSnapshotConfigUpdateTags(region, "Terraform-Snapshot"), Check: resource.ComposeTestCheckFunc(), }, { - Config: testAccOutscaleOAPISnapshotConfigUpdateTags(region, "Terraform-Snapshot-2"), + Config: testAccSnapshotConfigUpdateTags(region, "Terraform-Snapshot-2"), Check: resource.ComposeTestCheckFunc(), }, }, }) } -func TestAccOutscaleOAPISnapshot_importBasic(t *testing.T) { +func TestAccSnapshot_importBasic(t *testing.T) { region := os.Getenv("OUTSCALE_REGION") var v oscgo.Snapshot @@ -102,9 +102,9 @@ func TestAccOutscaleOAPISnapshot_importBasic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotConfig(region), + Config: testAccSnapshotConfig(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPISnapshotExists("outscale_snapshot.outscale_snapshot", &v), + testAccCheckSnapshotExists("outscale_snapshot.outscale_snapshot", &v), ), }, { @@ -117,7 +117,7 @@ func TestAccOutscaleOAPISnapshot_importBasic(t *testing.T) { }) } -func testAccCheckOAPISnapshotExists(n string, v *oscgo.Snapshot) resource.TestCheckFunc { +func testAccCheckSnapshotExists(n string, v *oscgo.Snapshot) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -128,7 +128,7 @@ func testAccCheckOAPISnapshotExists(n string, v *oscgo.Snapshot) resource.TestCh return fmt.Errorf("No ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI request := oscgo.ReadSnapshotsRequest{ Filters: &oscgo.FiltersSnapshot{SnapshotIds: &[]string{rs.Primary.ID}}, @@ -155,7 +155,7 @@ func testAccCheckOAPISnapshotExists(n string, v *oscgo.Snapshot) resource.TestCh } } -func testAccOutscaleOAPISnapshotConfig(region string) string { +func testAccSnapshotConfig(region string) string { return fmt.Sprintf(` resource "outscale_volume" "outscale_volume" { subregion_name = "%sa" @@ -173,7 +173,7 @@ resource "outscale_snapshot_attributes" "outscale_snapshot_attributes" { `, region) } -func testAccOutscaleOAPISnapshotConfigWithDescription(region string) string { +func testAccSnapshotConfigWithDescription(region string) string { return fmt.Sprintf(` resource "outscale_volume" "description_test" { subregion_name = "%sa" @@ -187,7 +187,7 @@ func testAccOutscaleOAPISnapshotConfigWithDescription(region string) string { `, region) } -func testAccOutscaleOAPISnapshotConfigCopySnapshot(region string) string { +func testAccSnapshotConfigCopySnapshot(region string) string { return fmt.Sprintf(` resource "outscale_volume" "description_test" { subregion_name = "%[1]sb" @@ -207,7 +207,7 @@ func testAccOutscaleOAPISnapshotConfigCopySnapshot(region string) string { `, region) } -func testAccOutscaleOAPISnapshotConfigUpdateTags(region, value string) string { +func testAccSnapshotConfigUpdateTags(region, value string) string { return fmt.Sprintf(` resource "outscale_volume" "outscale_volume" { subregion_name = "%sa" diff --git a/outscale/resource_outscale_subnet.go b/outscale/resource_outscale_subnet.go index 3b7455134..4201f89e9 100644 --- a/outscale/resource_outscale_subnet.go +++ b/outscale/resource_outscale_subnet.go @@ -12,12 +12,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOAPISubNet() *schema.Resource { +func resourceSubNet() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPISubNetCreate, - Read: resourceOutscaleOAPISubNetRead, - Update: resourceOutscaleOAPISubNetUpdate, - Delete: resourceOutscaleOAPISubNetDelete, + Create: resourceSubNetCreate, + Read: resourceSubNetRead, + Update: resourceSubNetUpdate, + Delete: resourceSubNetDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -25,13 +25,13 @@ func resourceOutscaleOAPISubNet() *schema.Resource { Create: schema.DefaultTimeout(10 * time.Minute), Delete: schema.DefaultTimeout(10 * time.Minute), }, - Schema: getOAPISubNetSchema(), + Schema: getSubNetSchema(), } } // Create SubNet -func resourceOutscaleOAPISubNetCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSubNetCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.CreateSubnetRequest{ IpRange: d.Get("ip_range").(string), NetId: d.Get("net_id").(string), @@ -64,7 +64,7 @@ func resourceOutscaleOAPISubNetCreate(d *schema.ResourceData, meta interface{}) stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: []string{"available"}, - Refresh: SubnetStateOApiRefreshFunc(conn, result.GetSubnetId()), + Refresh: SubnetStateRefreshFunc(conn, result.GetSubnetId()), Timeout: d.Timeout(schema.TimeoutCreate), Delay: 6 * time.Second, MinTimeout: 1 * time.Second, @@ -76,12 +76,12 @@ func resourceOutscaleOAPISubNetCreate(d *schema.ResourceData, meta interface{}) } } d.SetId(result.GetSubnetId()) - return resourceOutscaleOAPISubNetRead(d, meta) + return resourceSubNetRead(d, meta) } // Read SubNet -func resourceOutscaleOAPISubNetRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSubNetRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() log.Printf("[DEBUG] Reading Subnet(%s)", id) req := oscgo.ReadSubnetsRequest{ @@ -103,22 +103,22 @@ func resourceOutscaleOAPISubNetRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("[DEBUG] Error reading Subnet (%s)", errString) } if len(resp.GetSubnets()) > 0 { - return readOutscaleOAPISubNet(d, &resp.GetSubnets()[0]) + return readSubNet(d, &resp.GetSubnets()[0]) } return fmt.Errorf("No subnet (%s) found", d.Id()) } -func resourceOutscaleOAPISubNetUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSubNetUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") d.Partial(false) - return resourceOutscaleOAPISubNetRead(d, meta) + return resourceSubNetRead(d, meta) } -func resourceOutscaleOAPISubNetDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceSubNetDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() log.Printf("[DEBUG] Deleting Subnet (%s)", id) req := oscgo.DeleteSubnetRequest{ @@ -139,7 +139,7 @@ func resourceOutscaleOAPISubNetDelete(d *schema.ResourceData, meta interface{}) stateConf := &resource.StateChangeConf{ Pending: []string{"pending", "available"}, Target: []string{"deleted"}, - Refresh: SubnetStateOApiRefreshFunc(conn, id), + Refresh: SubnetStateRefreshFunc(conn, id), Timeout: d.Timeout(schema.TimeoutCreate), Delay: 2 * time.Second, MinTimeout: 1 * time.Second, @@ -151,39 +151,39 @@ func resourceOutscaleOAPISubNetDelete(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } -func readOutscaleOAPISubNet(d *schema.ResourceData, subnet *oscgo.Subnet) error { +func readSubNet(d *schema.ResourceData, subnet *oscgo.Subnet) error { if err := d.Set("subregion_name", subnet.GetSubregionName()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleSubNet1 (%s)", err) + fmt.Printf("[WARN] ERROR readSubNet1 (%s)", err) return err } if err := d.Set("available_ips_count", subnet.GetAvailableIpsCount()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleSubNet2 (%s)", err) + fmt.Printf("[WARN] ERROR readSubNet2 (%s)", err) return err } if err := d.Set("ip_range", subnet.GetIpRange()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleSubNet (%s)", err) + fmt.Printf("[WARN] ERROR readSubNet (%s)", err) return err } if err := d.Set("state", subnet.GetState()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleSubNet4 (%s)", err) + fmt.Printf("[WARN] ERROR readSubNet4 (%s)", err) return err } if err := d.Set("subnet_id", subnet.GetSubnetId()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleSubNet5 (%s)", err) + fmt.Printf("[WARN] ERROR readSubNet5 (%s)", err) return err } if err := d.Set("net_id", subnet.GetNetId()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleSubNet6 (%s)", err) + fmt.Printf("[WARN] ERROR readSubNet6 (%s)", err) return err } if err := d.Set("map_public_ip_on_launch", subnet.GetMapPublicIpOnLaunch()); err != nil { - fmt.Printf("[WARN] ERROR readOutscaleSubNet6 (%s)", err) + fmt.Printf("[WARN] ERROR readSubNet6 (%s)", err) return err } - return d.Set("tags", tagsOSCAPIToMap(subnet.GetTags())) + return d.Set("tags", tagsToMap(subnet.GetTags())) } -func SubnetStateOApiRefreshFunc(conn *oscgo.APIClient, subnetID string) resource.StateRefreshFunc { +func SubnetStateRefreshFunc(conn *oscgo.APIClient, subnetID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { var resp oscgo.ReadSubnetsResponse err := resource.Retry(5*time.Minute, func() *resource.RetryError { @@ -209,7 +209,7 @@ func SubnetStateOApiRefreshFunc(conn *oscgo.APIClient, subnetID string) resource return resp.GetSubnets()[0], resp.GetSubnets()[0].GetState(), nil } } -func getOAPISubNetSchema() map[string]*schema.Schema { +func getSubNetSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ //This is attribute part for schema SubNet "net_id": { @@ -249,6 +249,6 @@ func getOAPISubNetSchema() map[string]*schema.Schema { Type: schema.TypeBool, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), } } diff --git a/outscale/resource_outscale_subnet_test.go b/outscale/resource_outscale_subnet_test.go index e965b7a86..35070e908 100644 --- a/outscale/resource_outscale_subnet_test.go +++ b/outscale/resource_outscale_subnet_test.go @@ -14,7 +14,7 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func TestAccOutscaleOAPISubNet_basic(t *testing.T) { +func TestAccSubNet_basic(t *testing.T) { t.Parallel() var conf oscgo.Subnet region := os.Getenv("OUTSCALE_REGION") @@ -22,19 +22,19 @@ func TestAccOutscaleOAPISubNet_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPISubNetDestroyed, // we need to create the destroyed test case + CheckDestroy: testAccCheckSubNetDestroyed, // we need to create the destroyed test case Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISubnetConfig(region), + Config: testAccSubnetConfig(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPISubNetExists("outscale_subnet.subnet", &conf), + testAccCheckSubNetExists("outscale_subnet.subnet", &conf), ), }, }, }) } -func testAccCheckOutscaleOAPISubNetExists(n string, res *oscgo.Subnet) resource.TestCheckFunc { +func testAccCheckSubNetExists(n string, res *oscgo.Subnet) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -45,7 +45,7 @@ func testAccCheckOutscaleOAPISubNetExists(n string, res *oscgo.Subnet) resource. return fmt.Errorf("No Subnet id is set") } var resp oscgo.ReadSubnetsResponse - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI err := resource.Retry(30*time.Second, func() *resource.RetryError { var err error @@ -77,7 +77,7 @@ func testAccCheckOutscaleOAPISubNetExists(n string, res *oscgo.Subnet) resource. } } -func testAccCheckOutscaleOAPISubNetDestroyed(s *terraform.State) error { +func testAccCheckSubNetDestroyed(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_subnet" { continue @@ -85,7 +85,7 @@ func testAccCheckOutscaleOAPISubNetDestroyed(s *terraform.State) error { // Try to find a subnet var resp oscgo.ReadSubnetsResponse - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI err := resource.Retry(30*time.Second, func() *resource.RetryError { rp, httpResp, err := conn.SubnetApi.ReadSubnets(context.Background()).ReadSubnetsRequest(oscgo.ReadSubnetsRequest{ Filters: &oscgo.FiltersSubnet{ @@ -114,7 +114,7 @@ func testAccCheckOutscaleOAPISubNetDestroyed(s *terraform.State) error { return nil } -func testAccOutscaleOAPISubnetConfig(region string) string { +func testAccSubnetConfig(region string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_tags.go b/outscale/resource_outscale_tags.go index 57995c072..abf7f8192 100644 --- a/outscale/resource_outscale_tags.go +++ b/outscale/resource_outscale_tags.go @@ -12,11 +12,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPITags() *schema.Resource { +func resourceTags() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPITagsCreate, - Read: resourceOutscaleOAPITagsRead, - Delete: resourceOutscaleOAPITagsDelete, + Create: resourceTagsCreate, + Read: resourceTagsRead, + Delete: resourceTagsDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -26,12 +26,12 @@ func resourceOutscaleOAPITags() *schema.Resource { Delete: schema.DefaultTimeout(10 * time.Minute), }, - Schema: getOAPITagsSchema(), + Schema: getTagsSchema(), } } -func resourceOutscaleOAPITagsCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceTagsCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI request := oscgo.CreateTagsRequest{} @@ -71,11 +71,11 @@ func resourceOutscaleOAPITagsCreate(d *schema.ResourceData, meta interface{}) er d.SetId(resource.UniqueId()) - return resourceOutscaleOAPITagsRead(d, meta) + return resourceTagsRead(d, meta) } -func resourceOutscaleOAPITagsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceTagsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI // Build up search parameters params := oscgo.ReadTagsRequest{ @@ -127,7 +127,7 @@ func resourceOutscaleOAPITagsRead(d *schema.ResourceData, meta interface{}) erro return err } - tg := oapiTagsDescToList(resp.GetTags()) + tg := tagsDescToList(resp.GetTags()) if err := d.Set("tags", tg); err != nil { return err } @@ -135,8 +135,8 @@ func resourceOutscaleOAPITagsRead(d *schema.ResourceData, meta interface{}) erro return err } -func resourceOutscaleOAPITagsDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceTagsDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI request := oscgo.DeleteTagsRequest{} @@ -179,7 +179,7 @@ func resourceOutscaleOAPITagsDelete(d *schema.ResourceData, meta interface{}) er return nil } -func getOAPITagsSchema() map[string]*schema.Schema { +func getTagsSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ "resource_ids": { Type: schema.TypeSet, diff --git a/outscale/resource_outscale_tags_test.go b/outscale/resource_outscale_tags_test.go index 56e0df29b..5dc90d10a 100644 --- a/outscale/resource_outscale_tags_test.go +++ b/outscale/resource_outscale_tags_test.go @@ -1,24 +1,20 @@ package outscale import ( - "context" "fmt" "log" "os" "testing" - "time" "github.com/go-test/deep" - "github.com/terraform-providers/terraform-provider-outscale/utils" oscgo "github.com/outscale/osc-sdk-go/v2" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIVM_tags(t *testing.T) { +func TestAccVM_tags(t *testing.T) { v := &oscgo.Vm{} omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -27,23 +23,23 @@ func TestAccOutscaleOAPIVM_tags(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOAPIInstanceConfigTags(omi, "tinav4.c2r2p2", region, "keyOriginal", "valueOriginal"), + Config: testAccCheckInstanceConfigTags(omi, "tinav4.c2r2p2", region, "keyOriginal", "valueOriginal"), Check: resource.ComposeTestCheckFunc( - oapiTestAccCheckOutscaleVMExists("outscale_vm.vm", v), - testAccCheckOAPIVMTags(v, "keyOriginal", "valueOriginal"), + testAccCheckVMExists("outscale_vm.vm", v), + testAccCheckVMTags(v, "keyOriginal", "valueOriginal"), // Guard against regression of https://github.com/hashicorp/terraform/issues/914 resource.TestCheckResourceAttr( "outscale_tag.foo", "tags.#", "1"), ), }, { - Config: testAccCheckOAPIInstanceConfigTags(omi, "tinav4.c2r2p2", region, "keyUpdated", "valueUpdated"), + Config: testAccCheckInstanceConfigTags(omi, "tinav4.c2r2p2", region, "keyUpdated", "valueUpdated"), Check: resource.ComposeTestCheckFunc( - oapiTestAccCheckOutscaleVMExists("outscale_vm.vm", v), - testAccCheckOAPIVMTags(v, "keyUpdated", "valueUpdated"), + testAccCheckVMExists("outscale_vm.vm", v), + testAccCheckVMTags(v, "keyUpdated", "valueUpdated"), // Guard against regression of https://github.com/hashicorp/terraform/issues/914 resource.TestCheckResourceAttr( "outscale_tag.foo", "tags.#", "1"), @@ -56,76 +52,21 @@ func TestAccOutscaleOAPIVM_tags(t *testing.T) { } } -func testAccCheckOAPIVMTags(vm *oscgo.Vm, key, value string) resource.TestCheckFunc { +func testAccCheckVMTags(vm *oscgo.Vm, key, value string) resource.TestCheckFunc { return func(s *terraform.State) error { tags := vm.GetTags() - return checkOAPITags(tags, key, value) + return checkTags(tags, key, value) } } -func oapiTestAccCheckOutscaleVMExists(n string, i *oscgo.Vm) resource.TestCheckFunc { - providers := []*schema.Provider{testAccProvider} - return oapiTestAccCheckOutscaleVMExistsWithProviders(n, i, &providers) -} - -func oapiTestAccCheckOutscaleVMExistsWithProviders(n string, i *oscgo.Vm, providers *[]*schema.Provider) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - for _, provider := range *providers { - // Ignore if Meta is empty, this can happen for validation providers - if provider.Meta() == nil { - continue - } - - conn := provider.Meta().(*OutscaleClient) - var resp oscgo.ReadVmsResponse - var err error - - err = resource.Retry(30*time.Second, func() *resource.RetryError { - rp, httpResp, err := conn.OSCAPI.VmApi.ReadVms(context.Background()).ReadVmsRequest(oscgo.ReadVmsRequest{ - Filters: &oscgo.FiltersVm{ - VmIds: &[]string{rs.Primary.ID}, - }, - }).Execute() - if err != nil { - return utils.CheckThrottling(httpResp.StatusCode, err) - } - resp = rp - return nil - }) - if err != nil { - return err - } - - if len(resp.GetVms()) == 0 { - return fmt.Errorf("VM not found") - } - - if len(resp.GetVms()) > 0 { - *i = resp.GetVms()[0] - log.Printf("[DEBUG] VMS READ %+v", i) - return nil - } - } - return fmt.Errorf("VM not found") - } -} - -func testAccCheckOAPITags( +func testAccCheckTags( ts *[]oscgo.ResourceTag, key string, value string) resource.TestCheckFunc { return func(s *terraform.State) error { expected := map[string]string{ "key": key, "value": value, } - tags := tagsOSCAPIToMap(*ts) + tags := tagsToMap(*ts) for _, tag := range tags { if diff := deep.Equal(tag, expected); diff != nil { continue @@ -136,9 +77,9 @@ func testAccCheckOAPITags( } } -func checkOAPITags(ts []oscgo.ResourceTag, key, value string) error { - m := tagsOSCAPIToMap(ts) - log.Printf("[DEBUG], tagsOAPIToMap=%+v", m) +func checkTags(ts []oscgo.ResourceTag, key, value string) error { + m := tagsToMap(ts) + log.Printf("[DEBUG], tagsToMap=%+v", m) tag := m[0] if tag["key"] != key || tag["value"] != value { @@ -147,7 +88,7 @@ func checkOAPITags(ts []oscgo.ResourceTag, key, value string) error { return nil } -func testAccCheckOAPIInstanceConfigTags(omi, vmType, region, key, value string) string { +func testAccCheckInstanceConfigTags(omi, vmType, region, key, value string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_virtual_gateway.go b/outscale/resource_outscale_virtual_gateway.go index 778732679..417eca303 100644 --- a/outscale/resource_outscale_virtual_gateway.go +++ b/outscale/resource_outscale_virtual_gateway.go @@ -14,12 +14,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIVirtualGateway() *schema.Resource { +func resourceVirtualGateway() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIVirtualGatewayCreate, - Read: resourceOutscaleOAPIVirtualGatewayRead, - Update: resourceOutscaleOAPIVirtualGatewayUpdate, - Delete: resourceOutscaleOAPIVirtualGatewayDelete, + Create: resourceVirtualGatewayCreate, + Read: resourceVirtualGatewayRead, + Update: resourceVirtualGatewayUpdate, + Delete: resourceVirtualGatewayDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -62,13 +62,13 @@ func resourceOutscaleOAPIVirtualGateway() *schema.Resource { Optional: true, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), }, } } -func resourceOutscaleOAPIVirtualGatewayCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVirtualGatewayCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI connectType, connecTypeOk := d.GetOk("connection_type") createOpts := oscgo.CreateVirtualGatewayRequest{} if connecTypeOk { @@ -108,17 +108,17 @@ func resourceOutscaleOAPIVirtualGatewayCreate(d *schema.ResourceData, meta inter d.SetId(virtualGateway.GetVirtualGatewayId()) if d.IsNewResource() { - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tag") } - return resourceOutscaleOAPIVirtualGatewayRead(d, meta) + return resourceVirtualGatewayRead(d, meta) } -func resourceOutscaleOAPIVirtualGatewayRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVirtualGatewayRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var resp oscgo.ReadVirtualGatewaysResponse var err error @@ -154,7 +154,7 @@ func resourceOutscaleOAPIVirtualGatewayRead(d *schema.ResourceData, meta interfa d.SetId("") return nil } - vpnLink := oapiVpnGatewayGetLink(virtualGateway) + vpnLink := getVpnGatewayLink(virtualGateway) if len(virtualGateway.GetNetToVirtualGatewayLinks()) == 0 || vpnLink.GetState() == "detached" { d.Set("net_id", "") } else { @@ -175,15 +175,15 @@ func resourceOutscaleOAPIVirtualGatewayRead(d *schema.ResourceData, meta interfa d.Set("virtual_gateway_id", virtualGateway.GetVirtualGatewayId()) d.Set("net_to_virtual_gateway_links", vs) d.Set("state", virtualGateway.State) - d.Set("tags", tagsOSCAPIToMap(virtualGateway.GetTags())) + d.Set("tags", tagsToMap(virtualGateway.GetTags())) return nil } -func resourceOutscaleOAPIVirtualGatewayUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVirtualGatewayUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") @@ -192,8 +192,8 @@ func resourceOutscaleOAPIVirtualGatewayUpdate(d *schema.ResourceData, meta inter return nil } -func resourceOutscaleOAPIVirtualGatewayDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVirtualGatewayDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI return resource.Retry(5*time.Minute, func() *resource.RetryError { _, httpResp, err := conn.VirtualGatewayApi.DeleteVirtualGateway(context.Background()).DeleteVirtualGatewayRequest( @@ -248,12 +248,12 @@ func vpnGatewayAttachStateRefreshFunc(conn *oscgo.APIClient, id string, expected return virtualGateway, "detached", nil } - vpnAttachment := oapiVpnGatewayGetLink(virtualGateway) + vpnAttachment := getVpnGatewayLink(virtualGateway) return virtualGateway, vpnAttachment.GetState(), nil } } -func oapiVpnGatewayGetLink(vgw oscgo.VirtualGateway) *oscgo.NetToVirtualGatewayLink { +func getVpnGatewayLink(vgw oscgo.VirtualGateway) *oscgo.NetToVirtualGatewayLink { for _, v := range vgw.GetNetToVirtualGatewayLinks() { if v.GetState() == "attached" { return &v diff --git a/outscale/resource_outscale_virtual_gateway_link.go b/outscale/resource_outscale_virtual_gateway_link.go index 571d744fb..fa3a35703 100644 --- a/outscale/resource_outscale_virtual_gateway_link.go +++ b/outscale/resource_outscale_virtual_gateway_link.go @@ -13,11 +13,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIVirtualGatewayLink() *schema.Resource { +func resourceVirtualGatewayLink() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIVirtualGatewayLinkCreate, - Read: resourceOutscaleOAPIVirtualGatewayLinkRead, - Delete: resourceOutscaleOAPIVirtualGatewayLinkDelete, + Create: resourceVirtualGatewayLinkCreate, + Read: resourceVirtualGatewayLinkRead, + Delete: resourceVirtualGatewayLinkDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -63,8 +63,8 @@ func resourceOutscaleOAPIVirtualGatewayLink() *schema.Resource { } } -func resourceOutscaleOAPIVirtualGatewayLinkCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVirtualGatewayLinkCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI netID := d.Get("net_id").(string) vgwID := d.Get("virtual_gateway_id").(string) @@ -112,11 +112,11 @@ func resourceOutscaleOAPIVirtualGatewayLinkCreate(d *schema.ResourceData, meta i d.SetId(vgwID) - return resourceOutscaleOAPIVirtualGatewayLinkRead(d, meta) + return resourceVirtualGatewayLinkRead(d, meta) } -func resourceOutscaleOAPIVirtualGatewayLinkRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVirtualGatewayLinkRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI vgwID := d.Id() @@ -152,7 +152,7 @@ func resourceOutscaleOAPIVirtualGatewayLinkRead(d *schema.ResourceData, meta int return nil } - vga := oapiVpnGatewayGetLink(vgw) + vga := getVpnGatewayLink(vgw) if len(vgw.GetNetToVirtualGatewayLinks()) == 0 || vga.GetState() == "detached" { //d.Set("net_id", "") return nil @@ -186,8 +186,8 @@ func flattenNetToVirtualGatewayLinks(netToVirtualGatewayLinks *[]oscgo.NetToVirt return res } -func resourceOutscaleOAPIVirtualGatewayLinkDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVirtualGatewayLinkDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI // Get the old VPC ID to detach from netID, _ := d.GetChange("net_id") @@ -290,7 +290,7 @@ func vpnGatewayLinkStateRefresh(conn *oscgo.APIClient, vpcID, vgwID string) reso return vgw, "detached", nil } - vga := oapiVpnGatewayGetLink(vgw) + vga := getVpnGatewayLink(vgw) log.Printf("[DEBUG] VPN Gateway %q attachment status: %s", vgwID, *vga.State) return vgw, *vga.State, nil diff --git a/outscale/resource_outscale_virtual_gateway_link_test.go b/outscale/resource_outscale_virtual_gateway_link_test.go index 9baef1030..d50593254 100644 --- a/outscale/resource_outscale_virtual_gateway_link_test.go +++ b/outscale/resource_outscale_virtual_gateway_link_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIVpnGatewayAttachment_basic(t *testing.T) { +func TestAccVpnGatewayAttachment_basic(t *testing.T) { var vpc oscgo.Net var vgw oscgo.VirtualGateway t.Parallel() @@ -25,12 +25,12 @@ func TestAccOutscaleOAPIVpnGatewayAttachment_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOAPIVpnGatewayAttachmentConfig, + Config: testAccVpnGatewayAttachmentConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILinExists( + testAccCheckLinExists( "outscale_net.test", &vpc), - testAccCheckOAPIVirtualGatewayExists( + testAccCheckVirtualGatewayExists( "outscale_virtual_gateway.test", &vgw), ), @@ -45,10 +45,10 @@ func TestAccResourceVpnGatewayAttachment_importBasic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIVpnGatewayAttachmentDestroy, + CheckDestroy: testAccCheckVpnGatewayAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVpnGatewayAttachmentConfig, + Config: testAccVpnGatewayAttachmentConfig, }, { ResourceName: resourceName, @@ -71,7 +71,7 @@ func testAccCheckVpnGatewayAttachmentImportStateIDFunc(resourceName string) reso } } -func TestAccAWSOAPIVpnGatewayAttachment_deleted(t *testing.T) { +func TestAccAWSVpnGatewayAttachment_deleted(t *testing.T) { t.Parallel() var vgw oscgo.VirtualGateway var vpc oscgo.Net @@ -92,24 +92,24 @@ func TestAccAWSOAPIVpnGatewayAttachment_deleted(t *testing.T) { }, IDRefreshName: "outscale_virtual_gateway_link.test", Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIVpnGatewayAttachmentDestroy, + CheckDestroy: testAccCheckVpnGatewayAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVpnGatewayAttachmentConfig, + Config: testAccVpnGatewayAttachmentConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPILinExists( + testAccCheckLinExists( "outscale_net.test", &vpc), - testAccCheckOAPIVirtualGatewayExists( + testAccCheckVirtualGatewayExists( "outscale_virtual_gateway.test", &vgw), - testAccCheckOAPIVpnGatewayAttachmentExists( + testAccCheckVpnGatewayAttachmentExists( "outscale_virtual_gateway_link.test", &vgw), ), }, { - Config: testAccNoOAPIVpnGatewayAttachmentConfig, + Config: testAccNoVpnGatewayAttachmentConfig, Check: resource.ComposeTestCheckFunc( testDeleted("outscale_virtual_gateway_link.test"), ), @@ -118,7 +118,7 @@ func TestAccAWSOAPIVpnGatewayAttachment_deleted(t *testing.T) { }) } -func testAccCheckOAPIVpnGatewayAttachmentExists(n string, vgw *oscgo.VirtualGateway) resource.TestCheckFunc { +func testAccCheckVpnGatewayAttachmentExists(n string, vgw *oscgo.VirtualGateway) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -150,8 +150,8 @@ func testAccCheckOAPIVpnGatewayAttachmentExists(n string, vgw *oscgo.VirtualGate } } -func testAccCheckOAPIVpnGatewayAttachmentDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckVpnGatewayAttachmentDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_virtual_gateway_link" { @@ -189,7 +189,7 @@ func testAccCheckOAPIVpnGatewayAttachmentDestroy(s *terraform.State) error { return nil } -const testAccNoOAPIVpnGatewayAttachmentConfig = ` +const testAccNoVpnGatewayAttachmentConfig = ` resource "outscale_net" "test" { ip_range = "10.0.0.0/16" } @@ -199,7 +199,7 @@ const testAccNoOAPIVpnGatewayAttachmentConfig = ` } ` -const testAccOAPIVpnGatewayAttachmentConfig = ` +const testAccVpnGatewayAttachmentConfig = ` resource "outscale_virtual_gateway" "test" { connection_type = "ipsec.1" } diff --git a/outscale/resource_outscale_virtual_gateway_route_propagation.go b/outscale/resource_outscale_virtual_gateway_route_propagation.go index e52fcd08f..bfed72969 100644 --- a/outscale/resource_outscale_virtual_gateway_route_propagation.go +++ b/outscale/resource_outscale_virtual_gateway_route_propagation.go @@ -13,11 +13,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIVirtualGatewayRoutePropagation() *schema.Resource { +func resourceVirtualGatewayRoutePropagation() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleOAPIVpnGatewayRoutePropagationEnable, - Read: resourceOutscaleOAPIVpnGatewayRoutePropagationRead, - Delete: resourceOutscaleOAPIVpnGatewayRoutePropagationDisable, + Create: resourceVpnGatewayRoutePropagationEnable, + Read: resourceVpnGatewayRoutePropagationRead, + Delete: resourceVpnGatewayRoutePropagationDisable, Schema: map[string]*schema.Schema{ "virtual_gateway_id": { @@ -43,8 +43,8 @@ func resourceOutscaleOAPIVirtualGatewayRoutePropagation() *schema.Resource { } } -func resourceOutscaleOAPIVpnGatewayRoutePropagationEnable(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVpnGatewayRoutePropagationEnable(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI gwID := d.Get("virtual_gateway_id").(string) rtID := d.Get("route_table_id").(string) @@ -75,8 +75,8 @@ func resourceOutscaleOAPIVpnGatewayRoutePropagationEnable(d *schema.ResourceData return nil } -func resourceOutscaleOAPIVpnGatewayRoutePropagationDisable(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVpnGatewayRoutePropagationDisable(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI gwID := d.Get("virtual_gateway_id").(string) rtID := d.Get("route_table_id").(string) @@ -106,8 +106,8 @@ func resourceOutscaleOAPIVpnGatewayRoutePropagationDisable(d *schema.ResourceDat return nil } -func resourceOutscaleOAPIVpnGatewayRoutePropagationRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVpnGatewayRoutePropagationRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI gwID := d.Get("virtual_gateway_id").(string) rtID := d.Get("route_table_id").(string) diff --git a/outscale/resource_outscale_virtual_gateway_route_propagation_test.go b/outscale/resource_outscale_virtual_gateway_route_propagation_test.go index cc2b35914..b728aa49b 100644 --- a/outscale/resource_outscale_virtual_gateway_route_propagation_test.go +++ b/outscale/resource_outscale_virtual_gateway_route_propagation_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIVirtualRoutePropagation_basic(t *testing.T) { +func TestAccVirtualRoutePropagation_basic(t *testing.T) { t.Parallel() rBgpAsn := acctest.RandIntRange(64512, 65534) @@ -23,12 +23,12 @@ func TestAccOutscaleOAPIVirtualRoutePropagation_basic(t *testing.T) { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIVirtualRoutePropagationDestroy, + CheckDestroy: testAccCheckVirtualRoutePropagationDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIVpnRoutePropagationConfig(rBgpAsn), + Config: testAccVpnRoutePropagationConfig(rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccOutscaleOAPIVpnRoutePropagation( + testAccVpnRoutePropagation( "outscale_virtual_gateway_route_propagation.outscale_virtual_gateway_route_propagation", ), ), @@ -37,8 +37,8 @@ func TestAccOutscaleOAPIVirtualRoutePropagation_basic(t *testing.T) { }) } -func testAccCheckOAPIVirtualRoutePropagationDestroy(s *terraform.State) error { - oscapi := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckVirtualRoutePropagationDestroy(s *terraform.State) error { + oscapi := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_virtual_gateway_route_propagation" { @@ -83,7 +83,7 @@ func testAccCheckOAPIVirtualRoutePropagationDestroy(s *terraform.State) error { return nil } -func testAccOutscaleOAPIVpnRoutePropagation(routeProp string) resource.TestCheckFunc { +func testAccVpnRoutePropagation(routeProp string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[routeProp] if !ok { @@ -98,7 +98,7 @@ func testAccOutscaleOAPIVpnRoutePropagation(routeProp string) resource.TestCheck } } -func testAccOutscaleOAPIVpnRoutePropagationConfig(rBgpAsn int) string { +func testAccVpnRoutePropagationConfig(rBgpAsn int) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "outscale_virtual_gateway" { connection_type = "ipsec.1" diff --git a/outscale/resource_outscale_virtual_gateway_test.go b/outscale/resource_outscale_virtual_gateway_test.go index 57edcc530..1b9324b59 100644 --- a/outscale/resource_outscale_virtual_gateway_test.go +++ b/outscale/resource_outscale_virtual_gateway_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIVirtualGateway_basic(t *testing.T) { +func TestAccVirtualGateway_basic(t *testing.T) { t.Parallel() var v, v2 oscgo.VirtualGateway @@ -24,20 +24,20 @@ func TestAccOutscaleOAPIVirtualGateway_basic(t *testing.T) { }, IDRefreshName: "outscale_virtual_gateway.foo", Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIVirtualGatewayDestroy, + CheckDestroy: testAccCheckVirtualGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVirtualGatewayConfig, + Config: testAccVirtualGatewayConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIVirtualGatewayExists( + testAccCheckVirtualGatewayExists( "outscale_virtual_gateway.foo", &v), ), }, { - Config: testAccOAPIVirtualGatewayConfigChangeVPC, + Config: testAccVirtualGatewayConfigChangeVPC, Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIVirtualGatewayExists( + testAccCheckVirtualGatewayExists( "outscale_virtual_gateway.foo", &v2), ), }, @@ -45,25 +45,25 @@ func TestAccOutscaleOAPIVirtualGateway_basic(t *testing.T) { }) } -func TestAccOutscaleOAPIVirtualGatewayChangeTags(t *testing.T) { +func TestAccVirtualGatewayChangeTags(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIVirtualGatewayDestroy, + CheckDestroy: testAccCheckVirtualGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVirtualGatewayConfigChangeTags("ipsec.1", "test-VGW"), + Config: testAccVirtualGatewayConfigChangeTags("ipsec.1", "test-VGW"), }, { - Config: testAccOAPIVirtualGatewayConfigChangeTags("ipsec.1", "test-VGW2"), + Config: testAccVirtualGatewayConfigChangeTags("ipsec.1", "test-VGW2"), }, }, }) } -func TestAccOutscaleOAPIVirtualGateway_delete(t *testing.T) { +func TestAccVirtualGateway_delete(t *testing.T) { var virtualGateway oscgo.VirtualGateway testDeleted := func(r string) resource.TestCheckFunc { @@ -82,31 +82,31 @@ func TestAccOutscaleOAPIVirtualGateway_delete(t *testing.T) { }, IDRefreshName: "outscale_virtual_gateway.foo", Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIVirtualGatewayDestroy, + CheckDestroy: testAccCheckVirtualGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVirtualGatewayConfig, + Config: testAccVirtualGatewayConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIVirtualGatewayExists("outscale_virtual_gateway.foo", &virtualGateway)), + testAccCheckVirtualGatewayExists("outscale_virtual_gateway.foo", &virtualGateway)), }, { - Config: testAccOAPINoVirtualGatewayConfig, + Config: testAccNoVirtualGatewayConfig, Check: resource.ComposeTestCheckFunc(testDeleted("outscale_virtual_gateway.foo")), }, }, }) } -func TestAccOutscaleOAPIVirtualGateway_importBasic(t *testing.T) { +func TestAccVirtualGateway_importBasic(t *testing.T) { resourceName := "outscale_virtual_gateway.foo" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIVirtualGatewayDestroy, + CheckDestroy: testAccCheckVirtualGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVirtualGatewayConfig, + Config: testAccVirtualGatewayConfig, }, { ResourceName: resourceName, @@ -118,9 +118,9 @@ func TestAccOutscaleOAPIVirtualGateway_importBasic(t *testing.T) { }) } -func testAccOutscaleOAPIVirtualGatewayDisappears(gateway *oscgo.VirtualGateway) resource.TestCheckFunc { +func testAccVirtualGatewayDisappears(gateway *oscgo.VirtualGateway) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI var err error opts := oscgo.DeleteVirtualGatewayRequest{ @@ -164,8 +164,8 @@ func testAccOutscaleOAPIVirtualGatewayDisappears(gateway *oscgo.VirtualGateway) } } -func testAccCheckOAPIVirtualGatewayDestroy(s *terraform.State) error { - OSCAPI := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccCheckVirtualGatewayDestroy(s *terraform.State) error { + OSCAPI := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_virtual_gateway" { @@ -208,7 +208,7 @@ func testAccCheckOAPIVirtualGatewayDestroy(s *terraform.State) error { return nil } -func testAccCheckOAPIVirtualGatewayExists(n string, ig *oscgo.VirtualGateway) resource.TestCheckFunc { +func testAccCheckVirtualGatewayExists(n string, ig *oscgo.VirtualGateway) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -219,7 +219,7 @@ func testAccCheckOAPIVirtualGatewayExists(n string, ig *oscgo.VirtualGateway) re return fmt.Errorf("No ID is set") } - OSCAPI := testAccProvider.Meta().(*OutscaleClient).OSCAPI + OSCAPI := testAccProvider.Meta().(*Client).OSCAPI var resp oscgo.ReadVirtualGatewaysResponse var err error @@ -247,13 +247,13 @@ func testAccCheckOAPIVirtualGatewayExists(n string, ig *oscgo.VirtualGateway) re } } -const testAccOAPINoVirtualGatewayConfig = ` +const testAccNoVirtualGatewayConfig = ` resource "outscale_net" "foo" { ip_range = "10.1.0.0/16" } ` -const testAccOAPIVirtualGatewayConfig = ` +const testAccVirtualGatewayConfig = ` resource "outscale_net" "foo" { ip_range = "10.1.0.0/16" } @@ -264,7 +264,7 @@ const testAccOAPIVirtualGatewayConfig = ` ` -const testAccOAPIVirtualGatewayConfigChangeVPC = ` +const testAccVirtualGatewayConfigChangeVPC = ` resource "outscale_net" "bar" { ip_range = "10.2.0.0/16" } @@ -274,7 +274,7 @@ const testAccOAPIVirtualGatewayConfigChangeVPC = ` } ` -func testAccOAPIVirtualGatewayConfigChangeTags(connectionType, name string) string { +func testAccVirtualGatewayConfigChangeTags(connectionType, name string) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "outscale_virtual_gateway" { connection_type = "%s" @@ -287,7 +287,7 @@ func testAccOAPIVirtualGatewayConfigChangeTags(connectionType, name string) stri `, connectionType, name) } -func testAccCheckOutscaleVirtualGatewayImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckVirtualGatewayImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { diff --git a/outscale/resource_outscale_vm.go b/outscale/resource_outscale_vm.go index 1215f36b4..eefddb474 100644 --- a/outscale/resource_outscale_vm.go +++ b/outscale/resource_outscale_vm.go @@ -18,12 +18,12 @@ import ( "github.com/terraform-providers/terraform-provider-outscale/utils" ) -func resourceOutscaleOApiVM() *schema.Resource { +func resourceVM() *schema.Resource { return &schema.Resource{ - Create: resourceOAPIVMCreate, - Read: resourceOAPIVMRead, - Update: resourceOAPIVMUpdate, - Delete: resourceOAPIVMDelete, + Create: resourceVMCreate, + Read: resourceVMRead, + Update: resourceVMUpdate, + Delete: resourceVMDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -517,13 +517,13 @@ func resourceOutscaleOApiVM() *schema.Resource { Type: schema.TypeBool, Optional: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), }, } } -func resourceOAPIVMCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVMCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI vmOpts, err := buildCreateVmsRequest(d, meta) if err != nil { @@ -565,7 +565,7 @@ func resourceOAPIVMCreate(d *schema.ResourceData, meta interface{}) error { if get_psswd := d.Get("get_admin_password").(bool); get_psswd { psswd_err := resource.Retry(2500*time.Second, func() *resource.RetryError { - psswd, err := getOAPIVMAdminPassword(vm.GetVmId(), conn) + psswd, err := getVMAdminPassword(vm.GetVmId(), conn) if err != nil || len(psswd) < 1 { return resource.RetryableError(errors.New("timeout awaiting windows password")) } @@ -629,11 +629,11 @@ func resourceOAPIVMCreate(d *schema.ResourceData, meta interface{}) error { } } - return resourceOAPIVMRead(d, meta) + return resourceVMRead(d, meta) } -func resourceOAPIVMRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVMRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI var resp oscgo.ReadVmsResponse err := resource.Retry(60*time.Second, func() *resource.RetryError { @@ -663,7 +663,7 @@ func resourceOAPIVMRead(d *schema.ResourceData, meta interface{}) error { vm := resp.GetVms()[0] // Get the admin password from the server to save in the state - adminPassword, err := getOAPIVMAdminPassword(vm.GetVmId(), conn) + adminPassword, err := getVMAdminPassword(vm.GetVmId(), conn) if err != nil { return err } @@ -673,11 +673,11 @@ func resourceOAPIVMRead(d *schema.ResourceData, meta interface{}) error { return err } d.SetId(vm.GetVmId()) - return oapiVMDescriptionAttributes(set, &vm) + return setVMAttributes(set, &vm) }) } -func getOAPIVMAdminPassword(VMID string, conn *oscgo.APIClient) (string, error) { +func getVMAdminPassword(VMID string, conn *oscgo.APIClient) (string, error) { var resp oscgo.ReadAdminPasswordResponse err := resource.Retry(60*time.Second, func() *resource.RetryError { rp, httpResp, err := conn.VmApi.ReadAdminPassword(context.Background()).ReadAdminPasswordRequest(oscgo.ReadAdminPasswordRequest{VmId: VMID}).Execute() @@ -694,8 +694,8 @@ func getOAPIVMAdminPassword(VMID string, conn *oscgo.APIClient) (string, error) return resp.GetAdminPassword(), nil } -func resourceOAPIVMUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVMUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) @@ -881,7 +881,7 @@ func resourceOAPIVMUpdate(d *schema.ResourceData, meta interface{}) error { } } - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } @@ -914,11 +914,11 @@ func resourceOAPIVMUpdate(d *schema.ResourceData, meta interface{}) error { } out: - return resourceOAPIVMRead(d, meta) + return resourceVMRead(d, meta) } -func resourceOAPIVMDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVMDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI id := d.Id() @@ -981,7 +981,7 @@ func buildCreateVmsRequest(d *schema.ResourceData, meta interface{}) (oscgo.Crea if subNet != "" { request.SetSubnetId(subNet) } - blockDevices, err := expandBlockDeviceOApiMappings(d) + blockDevices, err := expandBlockDeviceMappings(d) if err != nil { return request, err } @@ -989,7 +989,7 @@ func buildCreateVmsRequest(d *schema.ResourceData, meta interface{}) (oscgo.Crea request.SetBlockDeviceMappings(blockDevices) } - if nics := buildNetworkOApiInterfaceOpts(d); len(nics) > 0 { + if nics := buildNetworkInterfaceOpts(d); len(nics) > 0 { if subNet != "" || placement != nil { return request, errors.New("If you specify nics parameter, you must not specify subnet_id and placement parameters.") } @@ -1041,7 +1041,7 @@ func buildCreateVmsRequest(d *schema.ResourceData, meta interface{}) (oscgo.Crea return request, nil } -func expandBlockDeviceOApiMappings(d *schema.ResourceData) ([]oscgo.BlockDeviceMappingVmCreation, error) { +func expandBlockDeviceMappings(d *schema.ResourceData) ([]oscgo.BlockDeviceMappingVmCreation, error) { var blockDevices []oscgo.BlockDeviceMappingVmCreation block := d.Get("block_device_mappings").([]interface{}) @@ -1103,7 +1103,7 @@ func expandBlockDeviceBSU(bsu map[string]interface{}) (oscgo.BsuToCreate, error) return bsuToCreate, nil } -func buildNetworkOApiInterfaceOpts(d *schema.ResourceData) []oscgo.NicForVmCreation { +func buildNetworkInterfaceOpts(d *schema.ResourceData) []oscgo.NicForVmCreation { nics := d.Get("nics").(*schema.Set).List() networkInterfaces := []oscgo.NicForVmCreation{} diff --git a/outscale/resource_outscale_vm_test.go b/outscale/resource_outscale_vm_test.go index e640f5f6d..51e97b8a8 100644 --- a/outscale/resource_outscale_vm_test.go +++ b/outscale/resource_outscale_vm_test.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIVM_Basic(t *testing.T) { +func TestAccVM_Basic(t *testing.T) { t.Parallel() var server oscgo.Vm @@ -28,13 +28,13 @@ func TestAccOutscaleOAPIVM_Basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigBasic(omi, "tinav4.c2r2p2", region, keypair), + Config: testAccCheckVMConfigBasic(omi, "tinav4.c2r2p2", region, keypair), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists(resourceName, &server), - testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), + testAccCheckVMExists(resourceName, &server), + testAccCheckVMAttributes(t, &server, omi), resource.TestCheckResourceAttr(resourceName, "image_id", omi), resource.TestCheckResourceAttr(resourceName, "vm_type", "tinav4.c2r2p2"), @@ -46,7 +46,7 @@ func TestAccOutscaleOAPIVM_Basic(t *testing.T) { }) } -func TestAccOutscaleOAPIVMBehavior_Basic(t *testing.T) { +func TestAccVMBehavior_Basic(t *testing.T) { t.Parallel() var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") @@ -56,13 +56,13 @@ func TestAccOutscaleOAPIVMBehavior_Basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMBehaviorConfigBasic(omi, "tinav4.c2r2p2", region, keypair, "high", "stop"), + Config: testAccCheckVMBehaviorConfigBasic(omi, "tinav4.c2r2p2", region, keypair, "high", "stop"), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), - testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), + testAccCheckVMExists("outscale_vm.basic", &server), + testAccCheckVMAttributes(t, &server, omi), resource.TestCheckResourceAttr( "outscale_vm.basic", "image_id", omi), resource.TestCheckResourceAttr( @@ -70,10 +70,10 @@ func TestAccOutscaleOAPIVMBehavior_Basic(t *testing.T) { ), }, { - Config: testAccCheckOutscaleOAPIVMBehaviorConfigBasic(omi, "tinav4.c2r2p2", region, keypair, "highest", "restart"), + Config: testAccCheckVMBehaviorConfigBasic(omi, "tinav4.c2r2p2", region, keypair, "highest", "restart"), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), - testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), + testAccCheckVMExists("outscale_vm.basic", &server), + testAccCheckVMAttributes(t, &server, omi), resource.TestCheckResourceAttr( "outscale_vm.basic", "image_id", omi), resource.TestCheckResourceAttr( @@ -84,7 +84,7 @@ func TestAccOutscaleOAPIVMBehavior_Basic(t *testing.T) { }) } -func TestAccOutscaleOAPIVM_importBasic(t *testing.T) { +func TestAccVM_importBasic(t *testing.T) { var ( server oscgo.Vm resourceName = "outscale_vm.basic" @@ -96,12 +96,12 @@ func TestAccOutscaleOAPIVM_importBasic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigBasic(omi, "tinav4.c2r2p2", region, keypair), + Config: testAccCheckVMConfigBasic(omi, "tinav4.c2r2p2", region, keypair), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists(resourceName, &server), + testAccCheckVMExists(resourceName, &server), resource.TestCheckResourceAttr(resourceName, "image_id", omi), resource.TestCheckResourceAttr(resourceName, "vm_type", "tinav4.c2r2p2"), resource.TestCheckResourceAttr(resourceName, "keypair_name", keypair), @@ -112,7 +112,7 @@ func TestAccOutscaleOAPIVM_importBasic(t *testing.T) { }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOutscaleVMImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckVMImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"private_ips", "request_id"}, @@ -121,7 +121,7 @@ func TestAccOutscaleOAPIVM_importBasic(t *testing.T) { }) } -func testAccCheckOutscaleVMImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckVMImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -131,7 +131,7 @@ func testAccCheckOutscaleVMImportStateIDFunc(resourceName string) resource.Impor } } -func TestAccOutscaleOAPIVM_withNicAttached(t *testing.T) { +func TestAccVM_withNicAttached(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -140,13 +140,13 @@ func TestAccOutscaleOAPIVM_withNicAttached(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigBasicWithNicAttached(omi, "tinav4.c2r2p2", region, keypair), + Config: testAccCheckVMConfigBasicWithNicAttached(omi, "tinav4.c2r2p2", region, keypair), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), - testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), + testAccCheckVMExists("outscale_vm.basic", &server), + testAccCheckVMAttributes(t, &server, omi), resource.TestCheckResourceAttr( "outscale_vm.basic", "image_id", omi), resource.TestCheckResourceAttr( @@ -157,7 +157,7 @@ func TestAccOutscaleOAPIVM_withNicAttached(t *testing.T) { }) } -func TestAccOutscaleOAPIVM_withTags(t *testing.T) { +func TestAccVM_withTags(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -167,13 +167,13 @@ func TestAccOutscaleOAPIVM_withTags(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccVmsConfigUpdateOAPIVMTags(omi, "tinav4.c2r2p2", region, "Terraform-VM", keypair, sgId), + Config: testAccVmsConfigUpdateVMTags(omi, "tinav4.c2r2p2", region, "Terraform-VM", keypair, sgId), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), - testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), + testAccCheckVMExists("outscale_vm.basic", &server), + testAccCheckVMAttributes(t, &server, omi), resource.TestCheckResourceAttr( "outscale_vm.basic", "image_id", omi), resource.TestCheckResourceAttr( @@ -184,7 +184,7 @@ func TestAccOutscaleOAPIVM_withTags(t *testing.T) { }) } -func TestAccOutscaleOAPIVM_withNics(t *testing.T) { +func TestAccVM_withNics(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") keypair := os.Getenv("OUTSCALE_KEYPAIR") @@ -192,13 +192,13 @@ func TestAccOutscaleOAPIVM_withNics(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, "tinav4.c2r2p2", keypair), + Config: testAccCheckVMConfigBasicWithNics(omi, "tinav4.c2r2p2", keypair), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), - testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), + testAccCheckVMExists("outscale_vm.basic", &server), + testAccCheckVMAttributes(t, &server, omi), resource.TestCheckResourceAttr( "outscale_vm.basic", "image_id", omi), resource.TestCheckResourceAttr( @@ -209,7 +209,7 @@ func TestAccOutscaleOAPIVM_withNics(t *testing.T) { }) } -func TestAccOutscaleOAPIVM_Update(t *testing.T) { +func TestAccVM_Update(t *testing.T) { region := os.Getenv("OUTSCALE_REGION") omi := os.Getenv("OUTSCALE_IMAGEID") keypair := os.Getenv("OUTSCALE_KEYPAIR") @@ -221,22 +221,22 @@ func TestAccOutscaleOAPIVM_Update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccVmsConfigUpdateOAPIVMKey(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccVmsConfigUpdateVMKey(omi, "tinav4.c2r2p2", region, keypair, sgId), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &before), - testAccCheckOutscaleOAPIVMAttributes(t, &before, omi), + testAccCheckVMExists("outscale_vm.basic", &before), + testAccCheckVMAttributes(t, &before, omi), resource.TestCheckResourceAttr("outscale_vm.basic", "image_id", omi), resource.TestCheckResourceAttr("outscale_vm.basic", "vm_type", "tinav4.c2r2p2"), ), }, { - Config: testAccVmsConfigUpdateOAPIVMKey(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccVmsConfigUpdateVMKey(omi, "tinav4.c2r2p2", region, keypair, sgId), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIVMExists("outscale_vm.basic", &after), - testAccCheckOAPIVMNotRecreated(t, &before, &after), + testAccCheckVMExists("outscale_vm.basic", &after), + testAccCheckVMNotRecreated(t, &before, &after), resource.TestCheckResourceAttr("outscale_vm.basic", "vm_type", "tinav4.c2r2p2"), ), }, @@ -244,7 +244,7 @@ func TestAccOutscaleOAPIVM_Update(t *testing.T) { }) } -func TestAccOutscaleOAPIVM_WithSubnet(t *testing.T) { +func TestAccVM_WithSubnet(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -253,13 +253,13 @@ func TestAccOutscaleOAPIVM_WithSubnet(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigWithSubnet(omi, "tinav4.c2r2p2", region, keypair), + Config: testAccCheckVMConfigWithSubnet(omi, "tinav4.c2r2p2", region, keypair), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), - testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), + testAccCheckVMExists("outscale_vm.basic", &server), + testAccCheckVMAttributes(t, &server, omi), resource.TestCheckResourceAttr( "outscale_vm.basic", "image_id", omi), resource.TestCheckResourceAttr( @@ -270,7 +270,7 @@ func TestAccOutscaleOAPIVM_WithSubnet(t *testing.T) { }) } -func TestAccOutscaleOAPIVM_WithBlockDeviceMappings(t *testing.T) { +func TestAccVM_WithBlockDeviceMappings(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -280,13 +280,13 @@ func TestAccOutscaleOAPIVM_WithBlockDeviceMappings(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigWithBlockDeviceMappings(omi, vmType, region, keypair), + Config: testAccCheckVMConfigWithBlockDeviceMappings(omi, vmType, region, keypair), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), - testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), + testAccCheckVMExists("outscale_vm.basic", &server), + testAccCheckVMAttributes(t, &server, omi), resource.TestCheckResourceAttr( "outscale_vm.basic", "image_id", omi), resource.TestCheckResourceAttr( @@ -297,23 +297,23 @@ func TestAccOutscaleOAPIVM_WithBlockDeviceMappings(t *testing.T) { }) } -func TestAccOutscaleOAPIVM_DeletionProtectionUpdate(t *testing.T) { +func TestAccVM_DeletionProtectionUpdate(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") keypair := os.Getenv("OUTSCALE_KEYPAIR") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleDeletionProtectionUpdateBasic(omi, "true", keypair), + Config: testAccCheckDeletionProtectionUpdateBasic(omi, "true", keypair), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("outscale_vm.outscale_vm", "deletion_protection", "true"), ), }, { - Config: testAccCheckOutscaleDeletionProtectionUpdateBasic(omi, "false", keypair), + Config: testAccCheckDeletionProtectionUpdateBasic(omi, "false", keypair), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("outscale_vm.outscale_vm", "deletion_protection", "false"), ), @@ -322,7 +322,7 @@ func TestAccOutscaleOAPIVM_DeletionProtectionUpdate(t *testing.T) { }) } -func TestAccOutscaleOAPIVMTags_Update(t *testing.T) { +func TestAccVMTags_Update(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") @@ -332,21 +332,21 @@ func TestAccOutscaleOAPIVMTags_Update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccVmsConfigUpdateOAPIVMTags(omi, "tinav4.c2r2p2", region, "Terraform-VM", keypair, sgId), + Config: testAccVmsConfigUpdateVMTags(omi, "tinav4.c2r2p2", region, "Terraform-VM", keypair, sgId), //Check: resource.ComposeTestCheckFunc(), }, { - Config: testAccVmsConfigUpdateOAPIVMTags(omi, "tinav4.c2r2p2", region, "Terraform-VM2", keypair, sgId), + Config: testAccVmsConfigUpdateVMTags(omi, "tinav4.c2r2p2", region, "Terraform-VM2", keypair, sgId), //Check: resource.ComposeTestCheckFunc(), }, }, }) } -func TestAccOutscaleOAPIVM_WithNet(t *testing.T) { +func TestAccVM_WithNet(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -356,13 +356,13 @@ func TestAccOutscaleOAPIVM_WithNet(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigWithNet(omi, vmType, region, keypair), + Config: testAccCheckVMConfigWithNet(omi, vmType, region, keypair), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.outscale_vmnet", &server), - testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), + testAccCheckVMExists("outscale_vm.outscale_vmnet", &server), + testAccCheckVMAttributes(t, &server, omi), resource.TestCheckResourceAttr( "outscale_vm.outscale_vmnet", "image_id", omi), resource.TestCheckResourceAttr( @@ -373,7 +373,7 @@ func TestAccOutscaleOAPIVM_WithNet(t *testing.T) { }) } -func TestAccOutscaleOAPIVM_multiBlockDeviceMapping(t *testing.T) { +func TestAccVM_multiBlockDeviceMapping(t *testing.T) { var server oscgo.Vm region := os.Getenv("OUTSCALE_REGION") omi := os.Getenv("OUTSCALE_IMAGEID") @@ -382,12 +382,12 @@ func TestAccOutscaleOAPIVM_multiBlockDeviceMapping(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, + CheckDestroy: testAccCheckVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleVMWithMultiBlockDeviceMapping(region, omi, keypair), + Config: testAccCheckVMWithMultiBlockDeviceMapping(region, omi, keypair), Check: resource.ComposeTestCheckFunc( - testAccCheckOutscaleOAPIVMExists("outscale_vm.outscale_vm", &server), + testAccCheckVMExists("outscale_vm.outscale_vm", &server), resource.TestCheckResourceAttr("outscale_vm.outscale_vm", "image_id", omi), resource.TestCheckResourceAttr("outscale_vm.outscale_vm", "vm_type", "tinav4.c2r2p2"), ), @@ -396,7 +396,7 @@ func TestAccOutscaleOAPIVM_multiBlockDeviceMapping(t *testing.T) { }) } -func testAccCheckOutscaleVMWithMultiBlockDeviceMapping(region, omi, keypair string) string { +func testAccCheckVMWithMultiBlockDeviceMapping(region, omi, keypair string) string { return fmt.Sprintf(` resource "outscale_volume" "example" { subregion_name = "%sa" @@ -440,7 +440,7 @@ func testAccCheckOutscaleVMWithMultiBlockDeviceMapping(region, omi, keypair stri `, region, omi, keypair) } -func testAccCheckOutscaleDeletionProtectionUpdateBasic(omi, deletionProtection, keypair string) string { +func testAccCheckDeletionProtectionUpdateBasic(omi, deletionProtection, keypair string) string { return fmt.Sprintf(` resource "outscale_vm" "outscale_vm" { image_id = "%[1]s" @@ -452,7 +452,7 @@ func testAccCheckOutscaleDeletionProtectionUpdateBasic(omi, deletionProtection, } //TODO: check if is needed -// func testAccCheckOAPIVMSecurityGroupsUpdated(t *testing.T, before, after *oscgo.Vm) resource.TestCheckFunc { +// func testAccCheckVMSecurityGroupsUpdated(t *testing.T, before, after *oscgo.Vm) resource.TestCheckFunc { // return func(s *terraform.State) error { // log.Printf("[DEBUG] ATTRS: %+v, %+v", before.GetSecurityGroups(), after.GetSecurityGroups()) // if len(after.GetSecurityGroups()) > 0 && len(before.GetSecurityGroups()) > 0 { @@ -466,9 +466,9 @@ func testAccCheckOutscaleDeletionProtectionUpdateBasic(omi, deletionProtection, // } // } -func testAccCheckOAPIVMExists(n string, i *oscgo.Vm) resource.TestCheckFunc { +func testAccCheckVMExists(n string, i *oscgo.Vm) resource.TestCheckFunc { providers := []*schema.Provider{testAccProvider} - return testAccCheckOAPIVMExistsWithProviders(n, i, &providers) + return testAccCheckVMExistsWithProviders(n, i, &providers) } func getVMsFilterByVMID(vmID string) *oscgo.FiltersVm { @@ -477,7 +477,7 @@ func getVMsFilterByVMID(vmID string) *oscgo.FiltersVm { } } -func testAccCheckOAPIVMExistsWithProviders(n string, i *oscgo.Vm, providers *[]*schema.Provider) resource.TestCheckFunc { +func testAccCheckVMExistsWithProviders(n string, i *oscgo.Vm, providers *[]*schema.Provider) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -493,7 +493,7 @@ func testAccCheckOAPIVMExistsWithProviders(n string, i *oscgo.Vm, providers *[]* continue } - client := provider.Meta().(*OutscaleClient) + client := provider.Meta().(*Client) var resp oscgo.ReadVmsResponse var err error @@ -512,6 +512,10 @@ func testAccCheckOAPIVMExistsWithProviders(n string, i *oscgo.Vm, providers *[]* return err } + if resp.Vms == nil { + return fmt.Errorf("Vms not found") + } + if len(resp.GetVms()) > 0 { *i = resp.GetVms()[0] return nil @@ -522,25 +526,25 @@ func testAccCheckOAPIVMExistsWithProviders(n string, i *oscgo.Vm, providers *[]* } } -func testAccCheckOAPIVMNotRecreated(t *testing.T, before, after *oscgo.Vm) resource.TestCheckFunc { +func testAccCheckVMNotRecreated(t *testing.T, before, after *oscgo.Vm) resource.TestCheckFunc { return func(s *terraform.State) error { assertNotEqual(t, before.VmId, after.VmId, "Outscale VM IDs have changed.") return nil } } -func testAccCheckOutscaleOAPIVMDestroy(s *terraform.State) error { - return testAccCheckOutscaleOAPIVMDestroyWithProvider(s, testAccProvider) +func testAccCheckVMDestroy(s *terraform.State) error { + return testAccCheckVMDestroyWithProvider(s, testAccProvider) } //TODO: check if it is needed -// func testAccCheckOutscaleOAPIVMDestroyWithProviders(providers *[]*schema.Provider) resource.TestCheckFunc { +// func testAccCheckVMDestroyWithProviders(providers *[]*schema.Provider) resource.TestCheckFunc { // return func(s *terraform.State) error { // for _, provider := range *providers { // if provider.Meta() == nil { // continue // } -// if err := testAccCheckOutscaleOAPIVMDestroyWithProvider(s, provider); err != nil { +// if err := testAccCheckVMDestroyWithProvider(s, provider); err != nil { // return err // } // } @@ -548,8 +552,8 @@ func testAccCheckOutscaleOAPIVMDestroy(s *terraform.State) error { // } // } -func testAccCheckOutscaleOAPIVMDestroyWithProvider(s *terraform.State, provider *schema.Provider) error { - conn := provider.Meta().(*OutscaleClient) +func testAccCheckVMDestroyWithProvider(s *terraform.State, provider *schema.Provider) error { + conn := provider.Meta().(*Client) for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_vm" { @@ -592,67 +596,14 @@ func testAccCheckOutscaleOAPIVMDestroyWithProvider(s *terraform.State, provider return nil } -func testAccCheckOutscaleOAPIVMExists(n string, i *oscgo.Vm) resource.TestCheckFunc { - providers := []*schema.Provider{testAccProvider} - return testAccCheckOutscaleOAPIVMExistsWithProviders(n, i, &providers) -} - -func testAccCheckOutscaleOAPIVMExistsWithProviders(n string, i *oscgo.Vm, providers *[]*schema.Provider) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - for _, provider := range *providers { - // Ignore if Meta is empty, this can happen for validation providers - if provider.Meta() == nil { - continue - } - - conn := provider.Meta().(*OutscaleClient) - var resp oscgo.ReadVmsResponse - var err error - - err = resource.Retry(120*time.Second, func() *resource.RetryError { - rp, httpResp, err := conn.OSCAPI.VmApi.ReadVms(context.Background()).ReadVmsRequest(oscgo.ReadVmsRequest{ - Filters: getVMsFilterByVMID(rs.Primary.ID), - }).Execute() - if err != nil { - return utils.CheckThrottling(httpResp.StatusCode, err) - } - resp = rp - return nil - }) - - if err != nil { - return err - } - - if resp.Vms == nil { - return fmt.Errorf("Vms not found") - } - - if len(resp.GetVms()) > 0 { - *i = resp.GetVms()[0] - return nil - } - } - return fmt.Errorf("Vms not found") - } -} - -func testAccCheckOutscaleOAPIVMAttributes(t *testing.T, server *oscgo.Vm, omi string) resource.TestCheckFunc { +func testAccCheckVMAttributes(t *testing.T, server *oscgo.Vm, omi string) resource.TestCheckFunc { return func(s *terraform.State) error { assertEqual(t, omi, server.GetImageId(), "Bad image_id.") return nil } } -func testAccCheckOutscaleOAPIVMConfigBasic(omi, vmType, region, keypair string) string { +func testAccCheckVMConfigBasic(omi, vmType, region, keypair string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -686,7 +637,7 @@ func testAccCheckOutscaleOAPIVMConfigBasic(omi, vmType, region, keypair string) }`, omi, vmType, region, keypair) } -func testAccCheckOutscaleOAPIVMConfigBasicWithNicAttached(omi, vmType, region, keypair string) string { +func testAccCheckVMConfigBasicWithNicAttached(omi, vmType, region, keypair string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -736,7 +687,7 @@ func testAccCheckOutscaleOAPIVMConfigBasicWithNicAttached(omi, vmType, region, k }`, omi, vmType, region, keypair) } -func testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, vmType, keypair string) string { +func testAccCheckVMConfigBasicWithNics(omi, vmType, keypair string) string { return fmt.Sprintf(`resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" } @@ -787,7 +738,7 @@ func testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, vmType, keypair string) }`, omi, vmType, keypair) } -func testAccVmsConfigUpdateOAPIVMKey(omi, vmType, region, keypair, sgId string) string { +func testAccVmsConfigUpdateVMKey(omi, vmType, region, keypair, sgId string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" @@ -820,7 +771,7 @@ func testAccVmsConfigUpdateOAPIVMKey(omi, vmType, region, keypair, sgId string) `, omi, vmType, region, keypair, sgId) } -func testAccVmsConfigUpdateOAPIVMTags(omi, vmType string, region, value, keypair, sgId string) string { +func testAccVmsConfigUpdateVMTags(omi, vmType string, region, value, keypair, sgId string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" @@ -858,7 +809,7 @@ func testAccVmsConfigUpdateOAPIVMTags(omi, vmType string, region, value, keypair `, omi, vmType, region, value, keypair, sgId) } -func testAccCheckOutscaleOAPIVMConfigWithSubnet(omi, vmType, region, keypair string) string { +func testAccCheckVMConfigWithSubnet(omi, vmType, region, keypair string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -893,7 +844,7 @@ func testAccCheckOutscaleOAPIVMConfigWithSubnet(omi, vmType, region, keypair str `, omi, vmType, region, keypair) } -func testAccCheckOutscaleOAPIVMConfigWithBlockDeviceMappings(omi, vmType, region, keypair string) string { +func testAccCheckVMConfigWithBlockDeviceMappings(omi, vmType, region, keypair string) string { return fmt.Sprintf(` resource "outscale_volume" "external1" { subregion_name = "%[3]sa" @@ -944,7 +895,7 @@ func testAccCheckOutscaleOAPIVMConfigWithBlockDeviceMappings(omi, vmType, region `, omi, vmType, region, keypair) } -func testAccCheckOutscaleOAPIVMConfigWithNet(omi, vmType, region, keypair string) string { +func testAccCheckVMConfigWithNet(omi, vmType, region, keypair string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -1028,7 +979,7 @@ func assertEqual(t *testing.T, a interface{}, b interface{}, message string) { } } -func testAccCheckOutscaleOAPIVMBehaviorConfigBasic(omi, vmType, region, keypair, perfomance, vmBehavior string) string { +func testAccCheckVMBehaviorConfigBasic(omi, vmType, region, keypair, perfomance, vmBehavior string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_volume.go b/outscale/resource_outscale_volume.go index 57df83080..30c7701f5 100644 --- a/outscale/resource_outscale_volume.go +++ b/outscale/resource_outscale_volume.go @@ -16,12 +16,12 @@ import ( const defaultIops = 150 -func resourceOutscaleOAPIVolume() *schema.Resource { +func resourceVolume() *schema.Resource { return &schema.Resource{ - Create: resourceOAPIVolumeCreate, - Read: resourceOAPIVolumeRead, - Update: resourceOAPIVolumeUpdate, - Delete: resourceOAPIVolumeDelete, + Create: resourceVolumeCreate, + Read: resourceVolumeRead, + Update: resourceVolumeUpdate, + Delete: resourceVolumeDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -107,7 +107,7 @@ func resourceOutscaleOAPIVolume() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "volume_id": { Type: schema.TypeString, Computed: true, @@ -120,8 +120,8 @@ func resourceOutscaleOAPIVolume() *schema.Resource { } } -func resourceOAPIVolumeCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVolumeCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI request := oscgo.CreateVolumeRequest{ SubregionName: d.Get("subregion_name").(string), @@ -168,7 +168,7 @@ func resourceOAPIVolumeCreate(d *schema.ResourceData, meta interface{}) error { stateConf := &resource.StateChangeConf{ Pending: []string{"creating"}, Target: []string{"available"}, - Refresh: volumeOAPIStateRefreshFunc(conn, resp.Volume.GetVolumeId()), + Refresh: volumeStateRefreshFunc(conn, resp.Volume.GetVolumeId()), Timeout: 5 * time.Minute, Delay: 10 * time.Second, MinTimeout: 3 * time.Second, @@ -182,17 +182,17 @@ func resourceOAPIVolumeCreate(d *schema.ResourceData, meta interface{}) error { d.SetId(resp.Volume.GetVolumeId()) if d.IsNewResource() { - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } d.SetPartial("tags") } - return resourceOAPIVolumeRead(d, meta) + return resourceVolumeRead(d, meta) } -func resourceOAPIVolumeRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVolumeRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI request := oscgo.ReadVolumesRequest{ Filters: &oscgo.FiltersVolume{VolumeIds: &[]string{d.Id()}}, @@ -218,15 +218,15 @@ func resourceOAPIVolumeRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error reading Outscale volume %s: %s", d.Id(), err) } - return readOAPIVolume(d, resp.GetVolumes()[0]) + return readVolume(d, resp.GetVolumes()[0]) } -func resourceOAPIVolumeUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVolumeUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } @@ -235,7 +235,7 @@ func resourceOAPIVolumeUpdate(d *schema.ResourceData, meta interface{}) error { stateConf := &resource.StateChangeConf{ Pending: []string{"creating"}, Target: []string{"available"}, - Refresh: volumeOAPIStateRefreshFunc(conn, d.Id()), + Refresh: volumeStateRefreshFunc(conn, d.Id()), Timeout: 5 * time.Minute, Delay: 10 * time.Second, MinTimeout: 3 * time.Second, @@ -247,11 +247,11 @@ func resourceOAPIVolumeUpdate(d *schema.ResourceData, meta interface{}) error { } d.Partial(false) - return resourceOAPIVolumeRead(d, meta) + return resourceVolumeRead(d, meta) } -func resourceOAPIVolumeDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVolumeDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI return resource.Retry(5*time.Minute, func() *resource.RetryError { request := oscgo.DeleteVolumeRequest{ @@ -268,7 +268,7 @@ func resourceOAPIVolumeDelete(d *schema.ResourceData, meta interface{}) error { }) } -func volumeOAPIStateRefreshFunc(conn *oscgo.APIClient, volumeID string) resource.StateRefreshFunc { +func volumeStateRefreshFunc(conn *oscgo.APIClient, volumeID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { var resp oscgo.ReadVolumesResponse var err error @@ -292,7 +292,7 @@ func volumeOAPIStateRefreshFunc(conn *oscgo.APIClient, volumeID string) resource } } -func readOAPIVolume(d *schema.ResourceData, volume oscgo.Volume) error { +func readVolume(d *schema.ResourceData, volume oscgo.Volume) error { d.SetId(volume.GetVolumeId()) if err := d.Set("subregion_name", volume.GetSubregionName()); err != nil { @@ -371,7 +371,7 @@ func readOAPIVolume(d *schema.ResourceData, volume oscgo.Volume) error { } } if volume.GetTags() != nil { - if err := d.Set("tags", tagsOSCAPIToMap(volume.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(volume.GetTags())); err != nil { return err } } else { diff --git a/outscale/resource_outscale_volume_test.go b/outscale/resource_outscale_volume_test.go index 76694a793..34dd01572 100644 --- a/outscale/resource_outscale_volume_test.go +++ b/outscale/resource_outscale_volume_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIVolume_basic(t *testing.T) { +func TestAccVolume_basic(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -25,9 +25,9 @@ func TestAccOutscaleOAPIVolume_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIVolumeConfig(region), + Config: testAccVolumeConfig(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIVolumeExists("outscale_volume.test", &v), + testAccCheckVolumeExists("outscale_volume.test", &v), ), }, { @@ -39,7 +39,7 @@ func TestAccOutscaleOAPIVolume_basic(t *testing.T) { }) } -func TestAccOutscaleOAPIVolume_updateSize(t *testing.T) { +func TestAccVolume_updateSize(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -53,16 +53,16 @@ func TestAccOutscaleOAPIVolume_updateSize(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIVolumeConfig(region), + Config: testAccVolumeConfig(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIVolumeExists("outscale_volume.test", &v), + testAccCheckVolumeExists("outscale_volume.test", &v), resource.TestCheckResourceAttr("outscale_volume.test", "size", "1"), ), }, { - Config: testOutscaleOAPIVolumeConfigUpdateSize(region), + Config: testVolumeConfigUpdateSize(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIVolumeExists("outscale_volume.test", &v), + testAccCheckVolumeExists("outscale_volume.test", &v), resource.TestCheckResourceAttr("outscale_volume.test", "size", "10"), ), }, @@ -70,7 +70,7 @@ func TestAccOutscaleOAPIVolume_updateSize(t *testing.T) { }) } -func TestAccOutscaleOAPIVolume_io1Type(t *testing.T) { +func TestAccVolume_io1Type(t *testing.T) { t.Parallel() region := os.Getenv("OUTSCALE_REGION") @@ -84,16 +84,16 @@ func TestAccOutscaleOAPIVolume_io1Type(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testOutscaleOAPIVolumeConfigIO1Type(region), + Config: testVolumeConfigIO1Type(region), Check: resource.ComposeTestCheckFunc( - testAccCheckOAPIVolumeExists("outscale_volume.test-io", &v), + testAccCheckVolumeExists("outscale_volume.test-io", &v), ), }, }, }) } -func testAccCheckOAPIVolumeExists(n string, v *oscgo.Volume) resource.TestCheckFunc { +func testAccCheckVolumeExists(n string, v *oscgo.Volume) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -104,7 +104,7 @@ func testAccCheckOAPIVolumeExists(n string, v *oscgo.Volume) resource.TestCheckF return fmt.Errorf("No ID is set") } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI request := oscgo.ReadVolumesRequest{ Filters: &oscgo.FiltersVolume{VolumeIds: &[]string{rs.Primary.ID}}, @@ -131,7 +131,7 @@ func testAccCheckOAPIVolumeExists(n string, v *oscgo.Volume) resource.TestCheckF } } -func testAccOutscaleOAPIVolumeConfig(region string) string { +func testAccVolumeConfig(region string) string { return fmt.Sprintf(` resource "outscale_volume" "test" { subregion_name = "%sa" @@ -146,7 +146,7 @@ func testAccOutscaleOAPIVolumeConfig(region string) string { `, region) } -func testOutscaleOAPIVolumeConfigUpdateSize(region string) string { +func testVolumeConfigUpdateSize(region string) string { return fmt.Sprintf(` resource "outscale_volume" "test" { subregion_name = "%sa" @@ -161,7 +161,7 @@ func testOutscaleOAPIVolumeConfigUpdateSize(region string) string { `, region) } -func testOutscaleOAPIVolumeConfigIO1Type(region string) string { +func testVolumeConfigIO1Type(region string) string { return fmt.Sprintf(` resource "outscale_volume" "test-io" { subregion_name = "%sa" diff --git a/outscale/resource_outscale_volumes_link.go b/outscale/resource_outscale_volumes_link.go index a674f0e20..be467f5df 100644 --- a/outscale/resource_outscale_volumes_link.go +++ b/outscale/resource_outscale_volumes_link.go @@ -15,11 +15,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceOutscaleOAPIVolumeLink() *schema.Resource { +func resourceVolumeLink() *schema.Resource { return &schema.Resource{ - Create: resourceOAPIVolumeLinkCreate, - Read: resourceOAPIVolumeLinkRead, - Delete: resourceOAPIVolumeLinkDelete, + Create: resourceVolumeLinkCreate, + Read: resourceVolumeLinkRead, + Delete: resourceVolumeLinkDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -29,11 +29,11 @@ func resourceOutscaleOAPIVolumeLink() *schema.Resource { Delete: schema.DefaultTimeout(10 * time.Minute), }, - Schema: getOAPIVolumeLinkSchema(), + Schema: getVolumeLinkSchema(), } } -func getOAPIVolumeLinkSchema() map[string]*schema.Schema { +func getVolumeLinkSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ // Arguments "device_name": { @@ -74,8 +74,8 @@ func getOAPIVolumeLinkSchema() map[string]*schema.Schema { } } -func resourceOAPIVolumeLinkCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVolumeLinkCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI name := d.Get("device_name").(string) iID := d.Get("vm_id").(string) vID := d.Get("volume_id").(string) @@ -145,7 +145,7 @@ func resourceOAPIVolumeLinkCreate(d *schema.ResourceData, meta interface{}) erro stateConf := &resource.StateChangeConf{ Pending: []string{"attaching"}, Target: []string{"attached"}, - Refresh: volumeOAPIAttachmentStateRefreshFunc(conn, vID, iID), + Refresh: volumeAttachmentStateRefreshFunc(conn, vID, iID), Timeout: 5 * time.Minute, Delay: 10 * time.Second, MinTimeout: 3 * time.Second, @@ -159,7 +159,7 @@ func resourceOAPIVolumeLinkCreate(d *schema.ResourceData, meta interface{}) erro } d.SetId(vID) - return resourceOAPIVolumeLinkRead(d, meta) + return resourceVolumeLinkRead(d, meta) } func isElegibleToLink(volumes []oscgo.Volume, instanceID string) bool { @@ -177,7 +177,7 @@ func isElegibleToLink(volumes []oscgo.Volume, instanceID string) bool { return elegible } -func volumeOAPIAttachmentStateRefreshFunc(conn *oscgo.APIClient, volumeID, instanceID string) resource.StateRefreshFunc { +func volumeAttachmentStateRefreshFunc(conn *oscgo.APIClient, volumeID, instanceID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { request := oscgo.ReadVolumesRequest{ @@ -216,8 +216,8 @@ func volumeOAPIAttachmentStateRefreshFunc(conn *oscgo.APIClient, volumeID, insta } } -func resourceOAPIVolumeLinkRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVolumeLinkRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI request := oscgo.ReadVolumesRequest{ Filters: &oscgo.FiltersVolume{ @@ -274,8 +274,8 @@ func resourceOAPIVolumeLinkRead(d *schema.ResourceData, meta interface{}) error return nil } -func resourceOAPIVolumeLinkDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVolumeLinkDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI if _, ok := d.GetOk("skip_destroy"); ok { log.Printf("[INFO] Found skip_destroy to be true, removing attachment %q from state", d.Id()) @@ -316,7 +316,7 @@ func resourceOAPIVolumeLinkDelete(d *schema.ResourceData, meta interface{}) erro stateConf := &resource.StateChangeConf{ Pending: []string{"detaching"}, Target: []string{"detached"}, - Refresh: volumeOAPIAttachmentStateRefreshFunc(conn, vID, iID), + Refresh: volumeAttachmentStateRefreshFunc(conn, vID, iID), Timeout: 5 * time.Minute, Delay: 10 * time.Second, MinTimeout: 3 * time.Second, diff --git a/outscale/resource_outscale_volumes_link_test.go b/outscale/resource_outscale_volumes_link_test.go index 05903c2ab..79c69fa0f 100644 --- a/outscale/resource_outscale_volumes_link_test.go +++ b/outscale/resource_outscale_volumes_link_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleOAPIVolumeAttachment_basic(t *testing.T) { +func TestAccVolumeAttachment_basic(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") @@ -27,15 +27,15 @@ func TestAccOutscaleOAPIVolumeAttachment_basic(t *testing.T) { }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIVolumeAttachmentDestroy, + CheckDestroy: testAccCheckVolumeAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVolumeAttachmentConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccVolumeAttachmentConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "outscale_volumes_link.ebs_att", "device_name", "/dev/sdh"), - testAccCheckOutscaleOAPIVMExists("outscale_vm.web", &i), - testAccCheckOAPIVolumeAttachmentExists( + testAccCheckVMExists("outscale_vm.web", &i), + testAccCheckVolumeAttachmentExists( "outscale_volumes_link.ebs_att", &i, &v), ), }, @@ -43,7 +43,7 @@ func TestAccOutscaleOAPIVolumeAttachment_basic(t *testing.T) { }) } -func TestAccOutscaleOAPIVolumeAttachment_importBasic(t *testing.T) { +func TestAccVolumeAttachment_importBasic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") @@ -54,14 +54,14 @@ func TestAccOutscaleOAPIVolumeAttachment_importBasic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckOAPIVolumeAttachmentDestroy, + CheckDestroy: testAccCheckVolumeAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVolumeAttachmentConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccVolumeAttachmentConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckOAPIVolumeAttachmentImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckVolumeAttachmentImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id"}, @@ -70,7 +70,7 @@ func TestAccOutscaleOAPIVolumeAttachment_importBasic(t *testing.T) { }) } -func testAccCheckOAPIVolumeAttachmentImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func testAccCheckVolumeAttachmentImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -80,7 +80,7 @@ func testAccCheckOAPIVolumeAttachmentImportStateIDFunc(resourceName string) reso } } -func testAccCheckOAPIVolumeAttachmentDestroy(s *terraform.State) error { +func testAccCheckVolumeAttachmentDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_volume_link" { continue @@ -89,7 +89,7 @@ func testAccCheckOAPIVolumeAttachmentDestroy(s *terraform.State) error { return nil } -func testAccCheckOAPIVolumeAttachmentExists(n string, i *oscgo.Vm, v *oscgo.Volume) resource.TestCheckFunc { +func testAccCheckVolumeAttachmentExists(n string, i *oscgo.Vm, v *oscgo.Volume) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -113,7 +113,7 @@ func testAccCheckOAPIVolumeAttachmentExists(n string, i *oscgo.Vm, v *oscgo.Volu } } -func testAccOAPIVolumeAttachmentConfig(omi, vmType, region, keypair, sgId string) string { +func testAccVolumeAttachmentConfig(omi, vmType, region, keypair, sgId string) string { return fmt.Sprintf(` resource "outscale_net" "net" { ip_range = "10.0.0.0/16" diff --git a/outscale/resource_outscale_vpn_connection.go b/outscale/resource_outscale_vpn_connection.go index f57ab4088..99dd7fa66 100644 --- a/outscale/resource_outscale_vpn_connection.go +++ b/outscale/resource_outscale_vpn_connection.go @@ -13,12 +13,12 @@ import ( oscgo "github.com/outscale/osc-sdk-go/v2" ) -func resourceOutscaleVPNConnection() *schema.Resource { +func resourceVPNConnection() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleVPNConnectionCreate, - Read: resourceOutscaleVPNConnectionRead, - Update: resourceOutscaleVPNConnectionUpdate, - Delete: resourceOutscaleVPNConnectionDelete, + Create: resourceVPNConnectionCreate, + Read: resourceVPNConnectionRead, + Update: resourceVPNConnectionUpdate, + Delete: resourceVPNConnectionDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -82,7 +82,7 @@ func resourceOutscaleVPNConnection() *schema.Resource { }, }, }, - "tags": tagsListOAPISchema(), + "tags": tagsListSchema(), "vgw_telemetries": { Type: schema.TypeList, Computed: true, @@ -119,8 +119,8 @@ func resourceOutscaleVPNConnection() *schema.Resource { } } -func resourceOutscaleVPNConnectionCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVPNConnectionCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI req := oscgo.CreateVpnConnectionRequest{ ClientGatewayId: d.Get("client_gateway_id").(string), @@ -142,7 +142,7 @@ func resourceOutscaleVPNConnectionCreate(d *schema.ResourceData, meta interface{ }) if err != nil { - return fmt.Errorf("Error creating Outscale VPN Conecction: %s", err) + return fmt.Errorf("Error creating Outscale VPN Connection: %s", err) } if tags, ok := d.GetOk("tags"); ok { @@ -154,11 +154,11 @@ func resourceOutscaleVPNConnectionCreate(d *schema.ResourceData, meta interface{ d.SetId(*resp.GetVpnConnection().VpnConnectionId) - return resourceOutscaleVPNConnectionRead(d, meta) + return resourceVPNConnectionRead(d, meta) } -func resourceOutscaleVPNConnectionRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVPNConnectionRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI vpnConnectionID := d.Id() @@ -203,7 +203,7 @@ func resourceOutscaleVPNConnectionRead(d *schema.ResourceData, meta interface{}) if err := d.Set("routes", flattenVPNConnection(vpnConnection.GetRoutes())); err != nil { return err } - if err := d.Set("tags", tagsOSCAPIToMap(vpnConnection.GetTags())); err != nil { + if err := d.Set("tags", tagsToMap(vpnConnection.GetTags())); err != nil { return err } if err := d.Set("vgw_telemetries", flattenVgwTelemetries(vpnConnection.GetVgwTelemetries())); err != nil { @@ -212,12 +212,12 @@ func resourceOutscaleVPNConnectionRead(d *schema.ResourceData, meta interface{}) return nil } -func resourceOutscaleVPNConnectionUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVPNConnectionUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI d.Partial(true) - if err := setOSCAPITags(conn, d); err != nil { + if err := setTags(conn, d); err != nil { return err } @@ -225,11 +225,11 @@ func resourceOutscaleVPNConnectionUpdate(d *schema.ResourceData, meta interface{ d.Partial(false) - return resourceOutscaleVPNConnectionRead(d, meta) + return resourceVPNConnectionRead(d, meta) } -func resourceOutscaleVPNConnectionDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVPNConnectionDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI vpnConnectionID := d.Id() diff --git a/outscale/resource_outscale_vpn_connection_route.go b/outscale/resource_outscale_vpn_connection_route.go index 8918941e4..83c516e4b 100644 --- a/outscale/resource_outscale_vpn_connection_route.go +++ b/outscale/resource_outscale_vpn_connection_route.go @@ -15,13 +15,13 @@ import ( oscgo "github.com/outscale/osc-sdk-go/v2" ) -func resourceOutscaleVPNConnectionRoute() *schema.Resource { +func resourceVPNConnectionRoute() *schema.Resource { return &schema.Resource{ - Create: resourceOutscaleVPNConnectionRouteCreate, - Read: resourceOutscaleVPNConnectionRouteRead, - Delete: resourceOutscaleVPNConnectionRouteDelete, + Create: resourceVPNConnectionRouteCreate, + Read: resourceVPNConnectionRouteRead, + Delete: resourceVPNConnectionRouteDelete, Importer: &schema.ResourceImporter{ - State: resourceOutscaleOAPIVPNConnectionRouteImportState, + State: resourceVPNConnectionRouteImportState, }, Schema: map[string]*schema.Schema{ @@ -43,8 +43,8 @@ func resourceOutscaleVPNConnectionRoute() *schema.Resource { } } -func resourceOutscaleVPNConnectionRouteCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVPNConnectionRouteCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI destinationIPRange := d.Get("destination_ip_range").(string) vpnConnectionID := d.Get("vpn_connection_id").(string) @@ -61,18 +61,18 @@ func resourceOutscaleVPNConnectionRouteCreate(d *schema.ResourceData, meta inter return nil }) if err != nil { - return fmt.Errorf("Error creating Outscale VPN Conecction Route: %s", err) + return fmt.Errorf("Error creating Outscale VPN Connection Route: %s", err) } d.SetId(fmt.Sprintf("%s:%s", destinationIPRange, vpnConnectionID)) - return resourceOutscaleVPNConnectionRouteRead(d, meta) + return resourceVPNConnectionRouteRead(d, meta) } -func resourceOutscaleVPNConnectionRouteRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVPNConnectionRouteRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI - destinationIPRange, vpnConnectionID := resourceOutscaleVPNConnectionRouteParseID(d.Id()) + destinationIPRange, vpnConnectionID := resourceVPNConnectionRouteParseID(d.Id()) stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, @@ -91,10 +91,10 @@ func resourceOutscaleVPNConnectionRouteRead(d *schema.ResourceData, meta interfa return nil } -func resourceOutscaleVPNConnectionRouteDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVPNConnectionRouteDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*Client).OSCAPI - destinationIPRange, vpnConnectionID := resourceOutscaleVPNConnectionRouteParseID(d.Id()) + destinationIPRange, vpnConnectionID := resourceVPNConnectionRouteParseID(d.Id()) req := oscgo.DeleteVpnConnectionRouteRequest{ DestinationIpRange: destinationIPRange, @@ -169,13 +169,13 @@ func vpnConnectionRouteRefreshFunc(conn *oscgo.APIClient, destinationIPRange, vp } } -func resourceOutscaleVPNConnectionRouteParseID(ID string) (string, string) { +func resourceVPNConnectionRouteParseID(ID string) (string, string) { parts := strings.SplitN(ID, ":", 2) return parts[0], parts[1] } -func resourceOutscaleOAPIVPNConnectionRouteImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - conn := meta.(*OutscaleClient).OSCAPI +func resourceVPNConnectionRouteImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + conn := meta.(*Client).OSCAPI parts := strings.SplitN(d.Id(), "_", 2) if len(parts) != 2 { diff --git a/outscale/resource_outscale_vpn_connection_route_test.go b/outscale/resource_outscale_vpn_connection_route_test.go index ea7eec5be..d418e610d 100644 --- a/outscale/resource_outscale_vpn_connection_route_test.go +++ b/outscale/resource_outscale_vpn_connection_route_test.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleVPNConnectionRoute_basic(t *testing.T) { +func TestAccVPNConnectionRoute_basic(t *testing.T) { t.Parallel() resourceName := "outscale_vpn_connection_route.foo" @@ -25,12 +25,12 @@ func TestAccOutscaleVPNConnectionRoute_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccOutscaleVPNConnectionRouteDestroy, + CheckDestroy: testAccVPNConnectionRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionRouteConfig(publicIP, destinationIPRange), + Config: testAccVPNConnectionRouteConfig(publicIP, destinationIPRange), Check: resource.ComposeTestCheckFunc( - testAccOutscaleVPNConnectionRouteExists(resourceName), + testAccVPNConnectionRouteExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "destination_ip_range"), resource.TestCheckResourceAttrSet(resourceName, "vpn_connection_id"), ), @@ -39,7 +39,7 @@ func TestAccOutscaleVPNConnectionRoute_basic(t *testing.T) { }) } -func TestAccOutscaleVPNConnectionRouteimport_basic(t *testing.T) { +func TestAccVPNConnectionRouteimport_basic(t *testing.T) { t.Parallel() if os.Getenv("TEST_QUOTA") == "true" { resourceName := "outscale_vpn_connection_route.foo" @@ -50,12 +50,12 @@ func TestAccOutscaleVPNConnectionRouteimport_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccOutscaleVPNConnectionRouteDestroy, + CheckDestroy: testAccVPNConnectionRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionRouteConfig(publicIP, destinationIPRange), + Config: testAccVPNConnectionRouteConfig(publicIP, destinationIPRange), Check: resource.ComposeTestCheckFunc( - testAccOutscaleVPNConnectionRouteExists(resourceName), + testAccVPNConnectionRouteExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "destination_ip_range"), resource.TestCheckResourceAttrSet(resourceName, "vpn_connection_id"), ), @@ -63,7 +63,7 @@ func TestAccOutscaleVPNConnectionRouteimport_basic(t *testing.T) { { ResourceName: resourceName, ImportState: true, - ImportStateIdFunc: testAccCheckOutscaleOAPIRouteImportStateIDFunc(resourceName), + ImportStateIdFunc: testAccCheckRouteImportStateIDFunc(resourceName), ImportStateVerify: true, ImportStateVerifyIgnore: []string{"request_id"}, }, @@ -74,20 +74,20 @@ func TestAccOutscaleVPNConnectionRouteimport_basic(t *testing.T) { } } -func testAccOutscaleVPNConnectionRouteExists(resourceName string) resource.TestCheckFunc { +func testAccVPNConnectionRouteExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("Not found: %s", resourceName) } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI if rs.Primary.ID == "" { return fmt.Errorf("No VPN Connection Route ID is set") } - destinationIPRange, vpnConnectionID := resourceOutscaleVPNConnectionRouteParseID(rs.Primary.ID) + destinationIPRange, vpnConnectionID := resourceVPNConnectionRouteParseID(rs.Primary.ID) filter := oscgo.ReadVpnConnectionsRequest{ Filters: &oscgo.FiltersVpnConnection{ @@ -122,14 +122,14 @@ func testAccOutscaleVPNConnectionRouteExists(resourceName string) resource.TestC } } -func testAccOutscaleVPNConnectionRouteDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccVPNConnectionRouteDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_vpn_connection_route" { continue } - destinationIPRange, vpnConnectionID := resourceOutscaleVPNConnectionRouteParseID(rs.Primary.ID) + destinationIPRange, vpnConnectionID := resourceVPNConnectionRouteParseID(rs.Primary.ID) filter := oscgo.ReadVpnConnectionsRequest{ Filters: &oscgo.FiltersVpnConnection{ @@ -165,7 +165,7 @@ func testAccOutscaleVPNConnectionRouteDestroy(s *terraform.State) error { return nil } -func testAccOutscaleVPNConnectionRouteConfig(publicIP, destinationIPRange string) string { +func testAccVPNConnectionRouteConfig(publicIP, destinationIPRange string) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "virtual_gateway" { connection_type = "ipsec.1" diff --git a/outscale/resource_outscale_vpn_connection_test.go b/outscale/resource_outscale_vpn_connection_test.go index 08318bcb6..e9ba58ce8 100644 --- a/outscale/resource_outscale_vpn_connection_test.go +++ b/outscale/resource_outscale_vpn_connection_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccOutscaleVPNConnection_basic(t *testing.T) { +func TestAccVPNConnection_basic(t *testing.T) { t.Parallel() resourceName := "outscale_vpn_connection.foo" @@ -24,12 +24,12 @@ func TestAccOutscaleVPNConnection_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: resourceName, Providers: testAccProviders, - CheckDestroy: testAccOutscaleVPNConnectionDestroy, + CheckDestroy: testAccVPNConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionConfigWithoutStaticRoutes(publicIP), + Config: testAccVPNConnectionConfigWithoutStaticRoutes(publicIP), Check: resource.ComposeTestCheckFunc( - testAccOutscaleVPNConnectionExists(resourceName), + testAccVPNConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "client_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "virtual_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "connection_type"), @@ -39,9 +39,9 @@ func TestAccOutscaleVPNConnection_basic(t *testing.T) { ), }, { - Config: testAccOutscaleVPNConnectionConfig(publicIP, true), + Config: testAccVPNConnectionConfig(publicIP, true), Check: resource.ComposeTestCheckFunc( - testAccOutscaleVPNConnectionExists(resourceName), + testAccVPNConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "client_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "virtual_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "connection_type"), @@ -53,9 +53,9 @@ func TestAccOutscaleVPNConnection_basic(t *testing.T) { ), }, { - Config: testAccOutscaleVPNConnectionConfig(publicIP, false), + Config: testAccVPNConnectionConfig(publicIP, false), Check: resource.ComposeTestCheckFunc( - testAccOutscaleVPNConnectionExists(resourceName), + testAccVPNConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "client_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "virtual_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "connection_type"), @@ -70,7 +70,7 @@ func TestAccOutscaleVPNConnection_basic(t *testing.T) { }) } -func TestAccOutscaleVPNConnection_withoutStaticRoutes(t *testing.T) { +func TestAccVPNConnection_withoutStaticRoutes(t *testing.T) { t.Parallel() resourceName := "outscale_vpn_connection.foo" publicIP := fmt.Sprintf("172.0.0.%d", acctest.RandIntRange(0, 255)) @@ -79,12 +79,12 @@ func TestAccOutscaleVPNConnection_withoutStaticRoutes(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_vpn_connection.foo", Providers: testAccProviders, - CheckDestroy: testAccOutscaleVPNConnectionDestroy, + CheckDestroy: testAccVPNConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionConfigWithoutStaticRoutes(publicIP), + Config: testAccVPNConnectionConfigWithoutStaticRoutes(publicIP), Check: resource.ComposeTestCheckFunc( - testAccOutscaleVPNConnectionExists(resourceName), + testAccVPNConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "client_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "virtual_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "connection_type"), @@ -96,7 +96,7 @@ func TestAccOutscaleVPNConnection_withoutStaticRoutes(t *testing.T) { }) } -func TestAccOutscaleVPNConnection_withTags(t *testing.T) { +func TestAccVPNConnection_withTags(t *testing.T) { t.Parallel() resourceName := "outscale_vpn_connection.foo" @@ -107,12 +107,12 @@ func TestAccOutscaleVPNConnection_withTags(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: resourceName, Providers: testAccProviders, - CheckDestroy: testAccOutscaleVPNConnectionDestroy, + CheckDestroy: testAccVPNConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionConfigWithTags(publicIP, value), + Config: testAccVPNConnectionConfigWithTags(publicIP, value), Check: resource.ComposeTestCheckFunc( - testAccOutscaleVPNConnectionExists(resourceName), + testAccVPNConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "client_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "virtual_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "connection_type"), @@ -128,7 +128,7 @@ func TestAccOutscaleVPNConnection_withTags(t *testing.T) { }) } -func TestAccOutscaleVPNConnection_importBasic(t *testing.T) { +func TestAccVPNConnection_importBasic(t *testing.T) { t.Parallel() resourceName := "outscale_vpn_connection.foo" @@ -138,12 +138,12 @@ func TestAccOutscaleVPNConnection_importBasic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: resourceName, Providers: testAccProviders, - CheckDestroy: testAccOutscaleVPNConnectionDestroy, + CheckDestroy: testAccVPNConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleVPNConnectionConfig(publicIP, true), + Config: testAccVPNConnectionConfig(publicIP, true), Check: resource.ComposeTestCheckFunc( - testAccOutscaleVPNConnectionExists(resourceName), + testAccVPNConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "client_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "virtual_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "connection_type"), @@ -162,14 +162,14 @@ func TestAccOutscaleVPNConnection_importBasic(t *testing.T) { }) } -func testAccOutscaleVPNConnectionExists(resourceName string) resource.TestCheckFunc { +func testAccVPNConnectionExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("Not found: %s", resourceName) } - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI + conn := testAccProvider.Meta().(*Client).OSCAPI if rs.Primary.ID == "" { return fmt.Errorf("No VPN Connection ID is set") @@ -199,8 +199,8 @@ func testAccOutscaleVPNConnectionExists(resourceName string) resource.TestCheckF } } -func testAccOutscaleVPNConnectionDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI +func testAccVPNConnectionDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*Client).OSCAPI for _, rs := range s.RootModule().Resources { if rs.Type != "outscale_vpn_connection" { continue @@ -230,7 +230,7 @@ func testAccOutscaleVPNConnectionDestroy(s *terraform.State) error { return nil } -func testAccOutscaleVPNConnectionConfig(publicIP string, staticRoutesOnly bool) string { +func testAccVPNConnectionConfig(publicIP string, staticRoutesOnly bool) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "virtual_gateway" { connection_type = "ipsec.1" @@ -251,7 +251,7 @@ func testAccOutscaleVPNConnectionConfig(publicIP string, staticRoutesOnly bool) `, publicIP, staticRoutesOnly) } -func testAccOutscaleVPNConnectionConfigWithoutStaticRoutes(publicIP string) string { +func testAccVPNConnectionConfigWithoutStaticRoutes(publicIP string) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "virtual_gateway" { connection_type = "ipsec.1" @@ -271,7 +271,7 @@ func testAccOutscaleVPNConnectionConfigWithoutStaticRoutes(publicIP string) stri `, publicIP) } -func testAccOutscaleVPNConnectionConfigWithTags(publicIP, value string) string { +func testAccVPNConnectionConfigWithTags(publicIP, value string) string { return fmt.Sprintf(` resource "outscale_virtual_gateway" "virtual_gateway" { connection_type = "ipsec.1" From ffdce7aed0af403720089d38b14afe5e03b5ceb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20B=C3=A9rot-Armand?= Date: Wed, 23 Nov 2022 15:14:39 +0000 Subject: [PATCH 2/2] Move some function to utils --- outscale/data_source_outscale_access_keys.go | 4 +- outscale/data_source_outscale_accounts.go | 2 +- .../data_source_outscale_client_gateways.go | 2 +- outscale/data_source_outscale_dhcp_options.go | 2 +- outscale/data_source_outscale_image.go | 2 +- outscale/data_source_outscale_images.go | 18 +--- .../data_source_outscale_load_balancer.go | 10 +-- ...ce_outscale_load_balancer_listener_rule.go | 2 +- ...e_outscale_load_balancer_listener_rules.go | 2 +- ...data_source_outscale_load_balancer_tags.go | 2 +- .../data_source_outscale_load_balancer_vms.go | 3 +- .../data_source_outscale_load_balancers.go | 7 +- .../data_source_outscale_net_access_point.go | 2 +- .../data_source_outscale_net_access_points.go | 2 +- outscale/data_source_outscale_snapshot.go | 14 +--- outscale/data_source_outscale_snapshots.go | 6 +- outscale/data_source_outscale_vm_states.go | 2 +- outscale/data_source_outscale_volumes.go | 2 +- .../data_source_outscale_vpn_connections.go | 2 +- outscale/resource_outscale_api_access_rule.go | 12 +-- outscale/resource_outscale_dhcp_option.go | 6 +- outscale/resource_outscale_load_balancer.go | 84 +++++-------------- ...ource_outscale_load_balancer_attributes.go | 8 +- ...ce_outscale_load_balancer_listener_rule.go | 4 +- .../resource_outscale_load_balancer_policy.go | 8 +- .../resource_outscale_net_access_point.go | 8 +- outscale/resource_outscale_nic.go | 4 +- outscale/resource_outscale_nic_private_ip.go | 4 +- .../resource_outscale_security_group_rule.go | 8 +- outscale/resource_outscale_vm.go | 12 +-- utils/utils.go | 45 ++++++++++ 31 files changed, 133 insertions(+), 156 deletions(-) diff --git a/outscale/data_source_outscale_access_keys.go b/outscale/data_source_outscale_access_keys.go index 79ffcf200..f938b993b 100644 --- a/outscale/data_source_outscale_access_keys.go +++ b/outscale/data_source_outscale_access_keys.go @@ -83,10 +83,10 @@ func dataSourceAccessKeysRead(d *schema.ResourceData, meta interface{}) error { filterReq = buildDataSourceAccessKeyFilters(filters.(*schema.Set)) } if accessKeyOk { - filterReq.SetAccessKeyIds(expandStringValueList(accessKeyID.([]interface{}))) + filterReq.SetAccessKeyIds(utils.InterfaceSliceToStringSlice(accessKeyID.([]interface{}))) } if stateOk { - filterReq.SetStates(expandStringValueList(state.([]interface{}))) + filterReq.SetStates(utils.InterfaceSliceToStringSlice(state.([]interface{}))) } var resp oscgo.ReadAccessKeysResponse diff --git a/outscale/data_source_outscale_accounts.go b/outscale/data_source_outscale_accounts.go index 4cc421809..aecf2a43e 100644 --- a/outscale/data_source_outscale_accounts.go +++ b/outscale/data_source_outscale_accounts.go @@ -132,7 +132,7 @@ func flattenAccounts(accounts []oscgo.Account) []map[string]interface{} { for i, account := range accounts { accountsMap[i] = map[string]interface{}{ "account_id": account.GetAccountId(), - "additional_emails": flattenStringList(account.AdditionalEmails), + "additional_emails": utils.StringSlicePtrToInterfaceSlice(account.AdditionalEmails), "city": account.GetCity(), "company_name": account.GetCompanyName(), "country": account.GetCountry(), diff --git a/outscale/data_source_outscale_client_gateways.go b/outscale/data_source_outscale_client_gateways.go index d2418fc0a..af523513a 100644 --- a/outscale/data_source_outscale_client_gateways.go +++ b/outscale/data_source_outscale_client_gateways.go @@ -75,7 +75,7 @@ func dataSourceClientGatewaysRead(d *schema.ResourceData, meta interface{}) erro if clientGatewayOk { params.Filters = &oscgo.FiltersClientGateway{ - ClientGatewayIds: expandStringValueListPointer(clientGatewayIDs.([]interface{})), + ClientGatewayIds: utils.InterfaceSliceToStringList(clientGatewayIDs.([]interface{})), } } diff --git a/outscale/data_source_outscale_dhcp_options.go b/outscale/data_source_outscale_dhcp_options.go index 37cd944f2..73e3e7d8e 100644 --- a/outscale/data_source_outscale_dhcp_options.go +++ b/outscale/data_source_outscale_dhcp_options.go @@ -87,7 +87,7 @@ func dataSourceDHCPOptionsRead(d *schema.ResourceData, meta interface{}) error { params := oscgo.ReadDhcpOptionsRequest{} if dhcpIDOk { params.Filters = &oscgo.FiltersDhcpOptions{ - DhcpOptionsSetIds: expandStringValueListPointer(dhcpIDs.([]interface{})), + DhcpOptionsSetIds: utils.InterfaceSliceToStringList(dhcpIDs.([]interface{})), } } if filtersOk { diff --git a/outscale/data_source_outscale_image.go b/outscale/data_source_outscale_image.go index 22c679dea..aa41f4b4a 100644 --- a/outscale/data_source_outscale_image.go +++ b/outscale/data_source_outscale_image.go @@ -216,7 +216,7 @@ func dataSourceImageRead(d *schema.ResourceData, meta interface{}) error { filtersReq.SetAccountIds([]string{ai.(string)}) } if executableUsersOk { - filtersReq.SetPermissionsToLaunchAccountIds(expandStringValueList(executableUsers.([]interface{}))) + filtersReq.SetPermissionsToLaunchAccountIds(utils.InterfaceSliceToStringSlice(executableUsers.([]interface{}))) } req := oscgo.ReadImagesRequest{Filters: filtersReq} diff --git a/outscale/data_source_outscale_images.go b/outscale/data_source_outscale_images.go index f290fb7da..c0ebb12c2 100644 --- a/outscale/data_source_outscale_images.go +++ b/outscale/data_source_outscale_images.go @@ -229,7 +229,7 @@ func dataSourceImagesRead(d *schema.ResourceData, meta interface{}) error { filtersReq.SetAccountIds([]string{aids.(string)}) } if executableUsersOk { - filtersReq.SetPermissionsToLaunchAccountIds(expandStringValueList(executableUsers.([]interface{}))) + filtersReq.SetPermissionsToLaunchAccountIds(utils.InterfaceSliceToStringSlice(executableUsers.([]interface{}))) } req := oscgo.ReadImagesRequest{Filters: filtersReq} @@ -344,19 +344,3 @@ func buildDataSourceImagesFilters(set *schema.Set) *oscgo.FiltersImage { } return filters } - -func expandStringValueList(configured []interface{}) []string { - vs := make([]string, 0, len(configured)) - for _, v := range configured { - val, ok := v.(string) - if ok && val != "" { - vs = append(vs, v.(string)) - } - } - return vs -} - -func expandStringValueListPointer(configured []interface{}) *[]string { - res := expandStringValueList(configured) - return &res -} diff --git a/outscale/data_source_outscale_load_balancer.go b/outscale/data_source_outscale_load_balancer.go index 87fbc25fb..4e2de3098 100644 --- a/outscale/data_source_outscale_load_balancer.go +++ b/outscale/data_source_outscale_load_balancer.go @@ -229,7 +229,7 @@ func readLbs_(conn *oscgo.APIClient, d *schema.ResourceData, t schema.ValueType) } } else { /* assuming typelist */ filter = &oscgo.FiltersLoadBalancer{ - LoadBalancerNames: expandStringList(ename.([]interface{})), + LoadBalancerNames: utils.InterfaceSliceToStringSlicePtr(ename.([]interface{})), } } @@ -286,12 +286,12 @@ func dataSourceLoadBalancerRead(d *schema.ResourceData, meta interface{}) error return err } - d.Set("subregion_names", flattenStringList(lb.SubregionNames)) + d.Set("subregion_names", utils.StringSlicePtrToInterfaceSlice(lb.SubregionNames)) d.Set("dns_name", lb.DnsName) d.Set("health_check", flattenHealthCheck(lb.HealthCheck)) d.Set("access_log", flattenAccessLog(lb.AccessLog)) - d.Set("backend_vm_ids", flattenStringList(lb.BackendVmIds)) + d.Set("backend_vm_ids", utils.StringSlicePtrToInterfaceSlice(lb.BackendVmIds)) if err := d.Set("listeners", flattenListeners(lb.Listeners)); err != nil { return err } @@ -337,7 +337,7 @@ func dataSourceLoadBalancerRead(d *schema.ResourceData, meta interface{}) error } d.Set("load_balancer_type", lb.LoadBalancerType) if lb.SecurityGroups != nil { - d.Set("security_groups", flattenStringList(lb.SecurityGroups)) + d.Set("security_groups", utils.StringSlicePtrToInterfaceSlice(lb.SecurityGroups)) } else { d.Set("security_groups", make([]map[string]interface{}, 0)) } @@ -351,7 +351,7 @@ func dataSourceLoadBalancerRead(d *schema.ResourceData, meta interface{}) error d.Set("secured_cookies", lb.SecuredCookies) d.Set("net_id", lb.NetId) d.Set("source_security_group", ssg) - d.Set("subnets", flattenStringList(lb.Subnets)) + d.Set("subnets", utils.StringSlicePtrToInterfaceSlice(lb.Subnets)) d.SetId(*lb.LoadBalancerName) return nil diff --git a/outscale/data_source_outscale_load_balancer_listener_rule.go b/outscale/data_source_outscale_load_balancer_listener_rule.go index 3d3162a8e..e687b1c18 100644 --- a/outscale/data_source_outscale_load_balancer_listener_rule.go +++ b/outscale/data_source_outscale_load_balancer_listener_rule.go @@ -153,7 +153,7 @@ func dataSourceLoadBalancerLDRuleRead(d *schema.ResourceData, meta interface{}) } if lr.VmIds != nil { - d.Set("vm_ids", flattenStringList(lr.VmIds)) + d.Set("vm_ids", utils.StringSlicePtrToInterfaceSlice(lr.VmIds)) } else { fmt.Errorf("Malformated listener rule") } diff --git a/outscale/data_source_outscale_load_balancer_listener_rules.go b/outscale/data_source_outscale_load_balancer_listener_rules.go index 59499721b..7f9527baa 100644 --- a/outscale/data_source_outscale_load_balancer_listener_rules.go +++ b/outscale/data_source_outscale_load_balancer_listener_rules.go @@ -166,7 +166,7 @@ func dataSourceLoadBalancerLDRulesRead(d *schema.ResourceData, meta interface{}) } if lr.VmIds != nil { - l["vm_ids"] = flattenStringList(lr.VmIds) + l["vm_ids"] = utils.StringSlicePtrToInterfaceSlice(lr.VmIds) } else { fmt.Errorf("Malformated listener rule") } diff --git a/outscale/data_source_outscale_load_balancer_tags.go b/outscale/data_source_outscale_load_balancer_tags.go index 109c1bb0f..75264e27a 100644 --- a/outscale/data_source_outscale_load_balancer_tags.go +++ b/outscale/data_source_outscale_load_balancer_tags.go @@ -31,7 +31,7 @@ func dataSourceLBUTagsRead(d *schema.ResourceData, meta interface{}) error { names := ename.([]interface{}) req := oscgo.ReadLoadBalancerTagsRequest{ - LoadBalancerNames: *expandStringList(names), + LoadBalancerNames: utils.InterfaceSliceToStringSlice(names), } var resp oscgo.ReadLoadBalancerTagsResponse diff --git a/outscale/data_source_outscale_load_balancer_vms.go b/outscale/data_source_outscale_load_balancer_vms.go index 296469566..f3f092d4b 100644 --- a/outscale/data_source_outscale_load_balancer_vms.go +++ b/outscale/data_source_outscale_load_balancer_vms.go @@ -2,6 +2,7 @@ package outscale import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func dataSourceLoadBalancerVms() *schema.Resource { @@ -37,6 +38,6 @@ func dataSourceLoadBalancerVmsRead(d *schema.ResourceData, return err } - d.Set("backend_vm_ids", flattenStringList(lb.BackendVmIds)) + d.Set("backend_vm_ids", utils.StringSlicePtrToInterfaceSlice(lb.BackendVmIds)) return nil } diff --git a/outscale/data_source_outscale_load_balancers.go b/outscale/data_source_outscale_load_balancers.go index 7bc14d7e3..585113447 100644 --- a/outscale/data_source_outscale_load_balancers.go +++ b/outscale/data_source_outscale_load_balancers.go @@ -3,6 +3,7 @@ package outscale import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func attrLBSchema() map[string]*schema.Schema { @@ -218,7 +219,7 @@ func dataSourceLoadBalancersRead(d *schema.ResourceData, meta interface{}) error l["dns_name"] = *v.DnsName l["access_log"] = flattenAccessLog(v.AccessLog) l["health_check"] = flattenHealthCheck(v.HealthCheck) - l["backend_vm_ids"] = flattenStringList(v.BackendVmIds) + l["backend_vm_ids"] = utils.StringSlicePtrToInterfaceSlice(v.BackendVmIds) if v.Listeners != nil { l["listeners"] = flattenListeners(v.Listeners) } else { @@ -265,7 +266,7 @@ func dataSourceLoadBalancersRead(d *schema.ResourceData, meta interface{}) error } l["load_balancer_type"] = v.LoadBalancerType - l["security_groups"] = flattenStringList(v.SecurityGroups) + l["security_groups"] = utils.StringSlicePtrToInterfaceSlice(v.SecurityGroups) ssg := make(map[string]string) if v.SourceSecurityGroup != nil { @@ -273,7 +274,7 @@ func dataSourceLoadBalancersRead(d *schema.ResourceData, meta interface{}) error ssg["security_group_name"] = *v.SourceSecurityGroup.SecurityGroupName } l["source_security_group"] = ssg - l["subnet_id"] = flattenStringList(v.Subnets) + l["subnet_id"] = utils.StringSlicePtrToInterfaceSlice(v.Subnets) l["public_ip"] = v.PublicIp l["secured_cookies"] = v.SecuredCookies l["net_id"] = v.NetId diff --git a/outscale/data_source_outscale_net_access_point.go b/outscale/data_source_outscale_net_access_point.go index 14171ad5a..12d7400f5 100644 --- a/outscale/data_source_outscale_net_access_point.go +++ b/outscale/data_source_outscale_net_access_point.go @@ -112,7 +112,7 @@ func dataSourceNetAccessPointRead(d *schema.ResourceData, meta interface{}) erro nap := resp.GetNetAccessPoints()[0] d.Set("net_access_point_id", nap.NetAccessPointId) - d.Set("route_table_ids", flattenStringList(nap.RouteTableIds)) + d.Set("route_table_ids", utils.StringSlicePtrToInterfaceSlice(nap.RouteTableIds)) d.Set("net_id", nap.NetId) d.Set("service_name", nap.ServiceName) d.Set("state", nap.State) diff --git a/outscale/data_source_outscale_net_access_points.go b/outscale/data_source_outscale_net_access_points.go index bbf74e24c..6c2b638ef 100644 --- a/outscale/data_source_outscale_net_access_points.go +++ b/outscale/data_source_outscale_net_access_points.go @@ -177,7 +177,7 @@ func dataSourceNetAccessPointsRead(d *schema.ResourceData, meta interface{}) err n := make(map[string]interface{}) n["net_access_point_id"] = v.NetAccessPointId - n["route_table_ids"] = flattenStringList(v.RouteTableIds) + n["route_table_ids"] = utils.StringSlicePtrToInterfaceSlice(v.RouteTableIds) n["net_id"] = v.NetId n["service_name"] = v.ServiceName n["state"] = v.State diff --git a/outscale/data_source_outscale_snapshot.go b/outscale/data_source_outscale_snapshot.go index d2f9c2019..9ccadb5e0 100644 --- a/outscale/data_source_outscale_snapshot.go +++ b/outscale/data_source_outscale_snapshot.go @@ -104,7 +104,7 @@ func dataSourceSnapshotRead(d *schema.ResourceData, meta interface{}) error { filter := oscgo.FiltersSnapshot{} if restorableUsersOk { - filter.SetPermissionsToCreateVolumeAccountIds(ExpandStringList(restorableUsers.([]interface{}))) + filter.SetPermissionsToCreateVolumeAccountIds(utils.InterfaceSliceToStringSlice(restorableUsers.([]interface{}))) params.SetFilters(filter) } if filtersOk { @@ -245,15 +245,3 @@ func buildSnapshotDataSourceFilters(set *schema.Set, filter *oscgo.FiltersSnapsh } return filter } - -// TODO MOVE To utils -func ExpandStringList(configured []interface{}) []string { - vs := make([]string, 0, len(configured)) - for _, v := range configured { - val, ok := v.(string) - if ok && val != "" { - vs = append(vs, v.(string)) - } - } - return vs -} diff --git a/outscale/data_source_outscale_snapshots.go b/outscale/data_source_outscale_snapshots.go index 279414c3b..844b7a931 100644 --- a/outscale/data_source_outscale_snapshots.go +++ b/outscale/data_source_outscale_snapshots.go @@ -122,18 +122,18 @@ func dataSourceSnapshotsRead(d *schema.ResourceData, meta interface{}) error { } filter := oscgo.FiltersSnapshot{} if restorableUsersOk { - filter.SetPermissionsToCreateVolumeAccountIds(ExpandStringList(restorableUsers.([]interface{}))) + filter.SetPermissionsToCreateVolumeAccountIds(utils.InterfaceSliceToStringSlice(restorableUsers.([]interface{}))) params.SetFilters(filter) } if filtersOk { buildSnapshotDataSourceFilters(filters.(*schema.Set), params.Filters) } if ownersOk { - filter.SetAccountIds(ExpandStringList(owners.([]interface{}))) + filter.SetAccountIds(utils.InterfaceSliceToStringSlice(owners.([]interface{}))) params.SetFilters(filter) } if snapshotIdsOk { - filter.SetSnapshotIds(ExpandStringList(snapshotIds.([]interface{}))) + filter.SetSnapshotIds(utils.InterfaceSliceToStringSlice(snapshotIds.([]interface{}))) params.SetFilters(filter) } diff --git a/outscale/data_source_outscale_vm_states.go b/outscale/data_source_outscale_vm_states.go index 9e62faa5b..d7dd08c06 100644 --- a/outscale/data_source_outscale_vm_states.go +++ b/outscale/data_source_outscale_vm_states.go @@ -60,7 +60,7 @@ func dataSourceVMStatesRead(d *schema.ResourceData, meta interface{}) error { } if instanceIdsOk { filter := oscgo.FiltersVmsState{} - filter.SetVmIds(ExpandStringList(instanceIds.([]interface{}))) + filter.SetVmIds(utils.InterfaceSliceToStringSlice(instanceIds.([]interface{}))) params.SetFilters(filter) } diff --git a/outscale/data_source_outscale_volumes.go b/outscale/data_source_outscale_volumes.go index 4c129ce2e..c2c7b6cd0 100644 --- a/outscale/data_source_outscale_volumes.go +++ b/outscale/data_source_outscale_volumes.go @@ -111,7 +111,7 @@ func datasourceVolumesRead(d *schema.ResourceData, meta interface{}) error { } if volumeIdsOk { - volIDs := expandStringValueList(volumeIds.([]interface{})) + volIDs := utils.InterfaceSliceToStringSlice(volumeIds.([]interface{})) filter := oscgo.FiltersVolume{} filter.SetVolumeIds(volIDs) params.SetFilters(filter) diff --git a/outscale/data_source_outscale_vpn_connections.go b/outscale/data_source_outscale_vpn_connections.go index f6d889409..8212c4b65 100644 --- a/outscale/data_source_outscale_vpn_connections.go +++ b/outscale/data_source_outscale_vpn_connections.go @@ -131,7 +131,7 @@ func dataSourceVPNConnectionsRead(d *schema.ResourceData, meta interface{}) erro if vpnConnectionOk { params.Filters = &oscgo.FiltersVpnConnection{ - VpnConnectionIds: expandStringValueListPointer(vpnConnectionIDs.([]interface{})), + VpnConnectionIds: utils.InterfaceSliceToStringSlicePtr(vpnConnectionIDs.([]interface{})), } } diff --git a/outscale/resource_outscale_api_access_rule.go b/outscale/resource_outscale_api_access_rule.go index 48d95446f..a93aea34d 100644 --- a/outscale/resource_outscale_api_access_rule.go +++ b/outscale/resource_outscale_api_access_rule.go @@ -60,18 +60,18 @@ func resourceApiAccessRuleCreate(d *schema.ResourceData, meta interface{}) error if val, ok := d.GetOk("ca_ids"); ok { checkParam = true - req.CaIds = expandSetStringList(val.(*schema.Set)) + req.CaIds = utils.SetToStringSlicePtr(val.(*schema.Set)) } if val, ok := d.GetOk("ip_ranges"); ok { checkParam = true - req.IpRanges = expandSetStringList(val.(*schema.Set)) + req.IpRanges = utils.SetToStringSlicePtr(val.(*schema.Set)) } if !checkParam { return fmt.Errorf("[DEBUG] Error 'ca_ids' or 'ip_ranges' field is require for API Access Rules creation") } if val, ok := d.GetOk("cns"); ok { - req.Cns = expandSetStringList(val.(*schema.Set)) + req.Cns = utils.SetToStringSlicePtr(val.(*schema.Set)) } if v, ok := d.GetOk("description"); ok { req.SetDescription(v.(string)) @@ -169,11 +169,11 @@ func resourceApiAccessRuleUpdate(d *schema.ResourceData, meta interface{}) error if val, ok := d.GetOk("ca_ids"); ok { checkParam = true - req.CaIds = expandSetStringList(val.(*schema.Set)) + req.CaIds = utils.SetToStringSlicePtr(val.(*schema.Set)) } if val, ok := d.GetOk("ip_ranges"); ok { checkParam = true - req.IpRanges = expandSetStringList(val.(*schema.Set)) + req.IpRanges = utils.SetToStringSlicePtr(val.(*schema.Set)) } if !checkParam { @@ -181,7 +181,7 @@ func resourceApiAccessRuleUpdate(d *schema.ResourceData, meta interface{}) error } if val, ok := d.GetOk("cns"); ok { - req.Cns = expandSetStringList(val.(*schema.Set)) + req.Cns = utils.SetToStringSlicePtr(val.(*schema.Set)) } if v, ok := d.GetOk("description"); ok { req.SetDescription(v.(string)) diff --git a/outscale/resource_outscale_dhcp_option.go b/outscale/resource_outscale_dhcp_option.go index 70fc6789e..102e00757 100644 --- a/outscale/resource_outscale_dhcp_option.go +++ b/outscale/resource_outscale_dhcp_option.go @@ -89,13 +89,13 @@ func resourceDHCPOptionCreate(d *schema.ResourceData, meta interface{}) error { createOpts.SetDomainName(domainName.(string)) } if okDomainNameServers { - createOpts.SetDomainNameServers(expandStringValueList(domainNameServers.([]interface{}))) + createOpts.SetDomainNameServers(utils.InterfaceSliceToStringSlice(domainNameServers.([]interface{}))) } if okLogServers { - createOpts.SetLogServers(expandStringValueList(logServers.([]interface{}))) + createOpts.SetLogServers(utils.InterfaceSliceToStringSlice(logServers.([]interface{}))) } if okNTPServers { - createOpts.SetNtpServers(expandStringValueList(ntpServers.([]interface{}))) + createOpts.SetNtpServers(utils.InterfaceSliceToStringSlice(ntpServers.([]interface{}))) } dhcp, _, err := createDhcpOption(conn, createOpts) diff --git a/outscale/resource_outscale_load_balancer.go b/outscale/resource_outscale_load_balancer.go index c7c42759d..652a37766 100644 --- a/outscale/resource_outscale_load_balancer.go +++ b/outscale/resource_outscale_load_balancer.go @@ -209,24 +209,6 @@ func resourceLoadBalancer() *schema.Resource { } } -func expandStringList(ifs []interface{}) *[]string { - r := make([]string, len(ifs)) - - for k, v := range ifs { - r[k] = v.(string) - } - return &r -} - -func expandSetStringList(ifs *schema.Set) *[]string { - r := make([]string, ifs.Len()) - - for k, v := range ifs.List() { - r[k] = v.(string) - } - return &r -} - // Flattens an array of Listeners into a []map[string]interface{} func flattenListeners(list *[]oscgo.Listener) []map[string]interface{} { if list == nil { @@ -246,7 +228,7 @@ func flattenListeners(list *[]oscgo.Listener) []map[string]interface{} { listener["server_certificate_id"] = *i.ServerCertificateId } - listener["policy_names"] = flattenStringList(i.PolicyNames) + listener["policy_names"] = utils.StringSlicePtrToInterfaceSlice(i.PolicyNames) result = append(result, listener) } return result @@ -418,12 +400,12 @@ func resourceLoadBalancerCreate_(d *schema.ResourceData, meta interface{}, isUpd } if v, ok := d.GetOk("security_groups"); ok { - req.SecurityGroups = expandSetStringList(v.(*schema.Set)) + req.SecurityGroups = utils.SetToStringSlicePtr(v.(*schema.Set)) } v_sb, sb_ok := d.GetOk("subnets") if sb_ok { - req.Subnets = expandStringList(v_sb.([]interface{})) + req.Subnets = utils.InterfaceSliceToStringList(v_sb.([]interface{})) } v_srn, srn_ok := d.GetOk("subregion_names") @@ -432,7 +414,7 @@ func resourceLoadBalancerCreate_(d *schema.ResourceData, meta interface{}, isUpd } if srn_ok && sb_ok == false { - req.SubregionNames = expandStringList(v_srn.([]interface{})) + req.SubregionNames = utils.InterfaceSliceToStringList(v_srn.([]interface{})) } log.Printf("[DEBUG] Load Balancer request configuration: %#v", *req) @@ -482,17 +464,6 @@ func resourceLoadBalancerCreate_(d *schema.ResourceData, meta interface{}, isUpd return resourceLoadBalancerRead(d, meta) } -func flattenStringList(list *[]string) []interface{} { - if list == nil { - return make([]interface{}, 0) - } - vs := make([]interface{}, 0, len(*list)) - for _, v := range *list { - vs = append(vs, v) - } - return vs -} - func readResourceLb(conn *oscgo.APIClient, elbName string) (*oscgo.LoadBalancer, *oscgo.ReadLoadBalancersResponse, error) { filter := &oscgo.FiltersLoadBalancer{ LoadBalancerNames: &[]string{elbName}, @@ -536,12 +507,12 @@ func resourceLoadBalancerRead(d *schema.ResourceData, meta interface{}) error { return err } - d.Set("subregion_names", flattenStringList(lb.SubregionNames)) + d.Set("subregion_names", utils.StringSlicePtrToInterfaceSlice(lb.SubregionNames)) d.Set("dns_name", lb.DnsName) d.Set("health_check", flattenHealthCheck(lb.HealthCheck)) d.Set("access_log", flattenAccessLog(lb.AccessLog)) - d.Set("backend_vm_ids", flattenStringList(lb.BackendVmIds)) + d.Set("backend_vm_ids", utils.StringSlicePtrToInterfaceSlice(lb.BackendVmIds)) if err := d.Set("listeners", flattenListeners(lb.Listeners)); err != nil { log.Printf("[DEBUG] out err %v", err) return err @@ -587,7 +558,7 @@ func resourceLoadBalancerRead(d *schema.ResourceData, meta interface{}) error { d.Set("load_balancer_type", lb.LoadBalancerType) if lb.SecurityGroups != nil { - d.Set("security_groups", flattenStringList(lb.SecurityGroups)) + d.Set("security_groups", utils.StringSlicePtrToInterfaceSlice(lb.SecurityGroups)) } else { d.Set("security_groups", make([]map[string]interface{}, 0)) } @@ -597,7 +568,7 @@ func resourceLoadBalancerRead(d *schema.ResourceData, meta interface{}) error { ssg["security_group_account_id"] = *lb.SourceSecurityGroup.SecurityGroupAccountId } d.Set("source_security_group", ssg) - d.Set("subnets", flattenStringList(lb.Subnets)) + d.Set("subnets", utils.StringSlicePtrToInterfaceSlice(lb.Subnets)) d.Set("public_ip", lb.PublicIp) d.Set("secured_cookies", lb.SecuredCookies) @@ -617,7 +588,7 @@ func resourceLoadBalancerUpdate(d *schema.ResourceData, meta interface{}) error LoadBalancerName: d.Id(), } nSg, _ := d.GetOk("security_groups") - req.SecurityGroups = expandSetStringList(nSg.(*schema.Set)) + req.SecurityGroups = utils.SetToStringSlicePtr(nSg.(*schema.Set)) var err error err = resource.Retry(1*time.Minute, func() *resource.RetryError { @@ -774,8 +745,8 @@ func resourceLoadBalancerUpdate(d *schema.ResourceData, meta interface{}) error o, n := d.GetChange("backend_vm_ids") os := o.(*schema.Set) ns := n.(*schema.Set) - remove := expandInstanceString(os.Difference(ns).List()) - add := expandInstanceString(ns.Difference(os).List()) + remove := utils.SetToStringSlice(os.Difference(ns)) + add := utils.SetToStringSlice(ns.Difference(os)) if len(add) > 0 { @@ -833,12 +804,12 @@ func resourceLoadBalancerUpdate(d *schema.ResourceData, meta interface{}) error req := oscgo.UpdateLoadBalancerRequest{ LoadBalancerName: d.Id(), HealthCheck: &oscgo.HealthCheck{ - HealthyThreshold: int32(check["healthy_threshold"].(int)), - UnhealthyThreshold: int32(check["unhealthy_threshold"].(int)), - CheckInterval: int32(check["check_interval"].(int)), + HealthyThreshold: check["healthy_threshold"].(int32), + UnhealthyThreshold: check["unhealthy_threshold"].(int32), + CheckInterval: check["check_interval"].(int32), Protocol: check["protocol"].(string), - Port: int32(check["port"].(int)), - Timeout: int32(check["timeout"].(int)), + Port: check["port"].(int32), + Timeout: check["timeout"].(int32), }, } if check["path"] != nil { @@ -996,30 +967,17 @@ func resourceLoadBalancerDelete(d *schema.ResourceData, meta interface{}) error return nil } -// Expands an array of String Instance IDs into a []Instances -func expandInstanceString(list []interface{}) []string { - result := make([]string, 0, len(list)) - for _, i := range list { - result = append(result, i.(string)) - } - return result -} - -func formatInt32(n int32) string { - return strconv.FormatInt(int64(n), 10) -} - func flattenHealthCheck(check *oscgo.HealthCheck) map[string]interface{} { chk := make(map[string]interface{}) if check != nil { - h := formatInt32(check.HealthyThreshold) - i := formatInt32(check.CheckInterval) + h := utils.I32toa(check.HealthyThreshold) + i := utils.I32toa(check.CheckInterval) pa := check.Path - po := formatInt32(check.Port) + po := utils.I32toa(check.Port) pr := check.Protocol - ti := formatInt32(check.Timeout) - u := formatInt32(check.UnhealthyThreshold) + ti := utils.I32toa(check.Timeout) + u := utils.I32toa(check.UnhealthyThreshold) chk["healthy_threshold"] = h chk["check_interval"] = i diff --git a/outscale/resource_outscale_load_balancer_attributes.go b/outscale/resource_outscale_load_balancer_attributes.go index d1bdb63c9..c784d68c9 100644 --- a/outscale/resource_outscale_load_balancer_attributes.go +++ b/outscale/resource_outscale_load_balancer_attributes.go @@ -422,7 +422,7 @@ func resourceLoadBalancerAttributesRead(d *schema.ResourceData, meta interface{} d.Set("source_security_group", sgr) if lb.SecurityGroups != nil { - d.Set("security_groups", flattenStringList(lb.SecurityGroups)) + d.Set("security_groups", utils.StringSlicePtrToInterfaceSlice(lb.SecurityGroups)) } else { d.Set("security_groups", make([]map[string]interface{}, 0)) } @@ -441,11 +441,11 @@ func resourceLoadBalancerAttributesRead(d *schema.ResourceData, meta interface{} d.Set("tags", make([]map[string]interface{}, 0)) } - d.Set("backend_vm_ids", flattenStringList(lb.BackendVmIds)) + d.Set("backend_vm_ids", utils.StringSlicePtrToInterfaceSlice(lb.BackendVmIds)) - d.Set("subnets", flattenStringList(lb.Subnets)) + d.Set("subnets", utils.StringSlicePtrToInterfaceSlice(lb.Subnets)) - d.Set("subregion_names", flattenStringList(lb.SubregionNames)) + d.Set("subregion_names", utils.StringSlicePtrToInterfaceSlice(lb.SubregionNames)) if lb.ApplicationStickyCookiePolicies != nil { app := make([]map[string]interface{}, diff --git a/outscale/resource_outscale_load_balancer_listener_rule.go b/outscale/resource_outscale_load_balancer_listener_rule.go index b08437c58..c6fe8178b 100644 --- a/outscale/resource_outscale_load_balancer_listener_rule.go +++ b/outscale/resource_outscale_load_balancer_listener_rule.go @@ -102,7 +102,7 @@ func resourceLoadBalancerListenerRuleCreate(d *schema.ResourceData, meta interfa req := &oscgo.CreateListenerRuleRequest{} if vids, ok := d.GetOk("vm_ids"); ok { - req.VmIds = *expandSetStringList(vids.(*schema.Set)) + req.SetVmIds(utils.SetToStringSlice(vids.(*schema.Set))) } else { return fmt.Errorf("expect vm_ids") } @@ -234,7 +234,7 @@ func resourceLoadBalancerListenerRuleRead(d *schema.ResourceData, meta interface return err } if lr.VmIds != nil { - d.Set("vm_ids", flattenStringList(lr.VmIds)) + d.Set("vm_ids", utils.StringSlicePtrToInterfaceSlice(lr.VmIds)) } return nil } diff --git a/outscale/resource_outscale_load_balancer_policy.go b/outscale/resource_outscale_load_balancer_policy.go index 897c34af2..38e777822 100644 --- a/outscale/resource_outscale_load_balancer_policy.go +++ b/outscale/resource_outscale_load_balancer_policy.go @@ -290,17 +290,17 @@ func resourceAppCookieStickinessPolicyCreate(d *schema.ResourceData, meta interf lb := resp.LoadBalancer d.Set("access_log", flattenAccessLog(lb.AccessLog)) d.Set("listeners", flattenListeners(lb.Listeners)) - d.Set("subregion_names", flattenStringList(lb.SubregionNames)) + d.Set("subregion_names", utils.StringSlicePtrToInterfaceSlice(lb.SubregionNames)) d.Set("load_balancer_type", lb.LoadBalancerType) if lb.SecurityGroups != nil { - d.Set("security_groups", flattenStringList(lb.SecurityGroups)) + d.Set("security_groups", utils.StringSlicePtrToInterfaceSlice(lb.SecurityGroups)) } else { d.Set("security_groups", make([]map[string]interface{}, 0)) } d.Set("dns_name", lb.DnsName) - d.Set("subnets", flattenStringList(lb.Subnets)) + d.Set("subnets", utils.StringSlicePtrToInterfaceSlice(lb.Subnets)) d.Set("health_check", flattenHealthCheck(lb.HealthCheck)) - d.Set("backend_vm_ids", flattenStringList(lb.BackendVmIds)) + d.Set("backend_vm_ids", utils.StringSlicePtrToInterfaceSlice(lb.BackendVmIds)) if lb.Tags != nil { ta := make([]map[string]interface{}, len(*lb.Tags)) for k1, v1 := range *lb.Tags { diff --git a/outscale/resource_outscale_net_access_point.go b/outscale/resource_outscale_net_access_point.go index e2e344795..c0f15affa 100644 --- a/outscale/resource_outscale_net_access_point.go +++ b/outscale/resource_outscale_net_access_point.go @@ -63,8 +63,8 @@ func resourceNetAccessPointUpdate(d *schema.ResourceData, meta interface{}) erro o, n := d.GetChange("route_table_ids") log.Printf("[DEBUG] it change !: %v %v", o, n) - oo := expandSetStringList(o.(*schema.Set)) - nn := expandSetStringList(n.(*schema.Set)) + oo := utils.SetToStringSlicePtr(o.(*schema.Set)) + nn := utils.SetToStringSlicePtr(n.(*schema.Set)) destroy := make([]string, 0) add := make([]string, 0) @@ -170,7 +170,7 @@ func resourceNetAccessPointCreate(d *schema.ResourceData, meta interface{}) erro req := &oscgo.CreateNetAccessPointRequest{} if v, ok := d.GetOk("route_table_ids"); ok { - req.RouteTableIds = expandSetStringList(v.(*schema.Set)) + req.RouteTableIds = utils.SetToStringSlicePtr(v.(*schema.Set)) } nid := d.Get("net_id") @@ -262,7 +262,7 @@ func resourceNetAccessPointRead(d *schema.ResourceData, meta interface{}) error nap := (*resp.NetAccessPoints)[0] - d.Set("route_table_ids", flattenStringList(nap.RouteTableIds)) + d.Set("route_table_ids", utils.StringSlicePtrToInterfaceSlice(nap.RouteTableIds)) d.Set("net_id", nap.NetId) d.Set("service_name", nap.ServiceName) d.Set("state", nap.State) diff --git a/outscale/resource_outscale_nic.go b/outscale/resource_outscale_nic.go index cc2f10e91..4b1799f55 100644 --- a/outscale/resource_outscale_nic.go +++ b/outscale/resource_outscale_nic.go @@ -646,7 +646,7 @@ func resourceNicUpdate(d *schema.ResourceData, meta interface{}) error { if diff < 0 { input := oscgo.UnlinkPrivateIpsRequest{ NicId: d.Id(), - PrivateIps: expandStringValueList(prips[0:int(math.Abs(float64(diff)))]), + PrivateIps: utils.InterfaceSliceToStringSlice(prips[0:int(math.Abs(float64(diff)))]), } err := resource.Retry(5*time.Minute, func() *resource.RetryError { @@ -665,7 +665,7 @@ func resourceNicUpdate(d *schema.ResourceData, meta interface{}) error { } if d.HasChange("security_group_ids") { - stringValueList := expandStringValueList(d.Get("security_group_ids").([]interface{})) + stringValueList := utils.InterfaceSliceToStringSlice(d.Get("security_group_ids").([]interface{})) request := oscgo.UpdateNicRequest{ NicId: d.Id(), SecurityGroupIds: &stringValueList, diff --git a/outscale/resource_outscale_nic_private_ip.go b/outscale/resource_outscale_nic_private_ip.go index d9c1cb32a..d6957d621 100644 --- a/outscale/resource_outscale_nic_private_ip.go +++ b/outscale/resource_outscale_nic_private_ip.go @@ -72,7 +72,7 @@ func resourceNetworkInterfacePrivateIPCreate(d *schema.ResourceData, meta interf } if v, ok := d.GetOk("private_ips"); ok { - input.SetPrivateIps(expandStringValueList(v.([]interface{}))) + input.SetPrivateIps(utils.InterfaceSliceToStringSlice(v.([]interface{}))) } var err error @@ -178,7 +178,7 @@ func resourceNetworkInterfacePrivateIPDelete(d *schema.ResourceData, meta interf } if v, ok := d.GetOk("private_ips"); ok { - input.SetPrivateIps(expandStringValueList(v.([]interface{}))) + input.SetPrivateIps(utils.InterfaceSliceToStringSlice(v.([]interface{}))) } var err error diff --git a/outscale/resource_outscale_security_group_rule.go b/outscale/resource_outscale_security_group_rule.go index 3115fd8e5..0bcab79bf 100644 --- a/outscale/resource_outscale_security_group_rule.go +++ b/outscale/resource_outscale_security_group_rule.go @@ -210,11 +210,11 @@ func expandRules(d *schema.ResourceData) *[]oscgo.SecurityGroupRule { SecurityGroupsMembers: expandSecurityGroupsMembers(r["security_groups_members"].([]interface{})), } - if ipRanges := expandStringValueListPointer(r["ip_ranges"].([]interface{})); len(*ipRanges) > 0 { - rules[i].IpRanges = expandStringValueListPointer(r["ip_ranges"].([]interface{})) + if ipRanges := utils.InterfaceSliceToStringSlicePtr(r["ip_ranges"].([]interface{})); len(*ipRanges) > 0 { + rules[i].IpRanges = utils.InterfaceSliceToStringSlicePtr(r["ip_ranges"].([]interface{})) } - if serviceIDs := expandStringValueListPointer(r["service_ids"].([]interface{})); len(*serviceIDs) > 0 { - rules[i].ServiceIds = expandStringValueListPointer(r["service_ids"].([]interface{})) + if serviceIDs := utils.InterfaceSliceToStringSlicePtr(r["service_ids"].([]interface{})); len(*serviceIDs) > 0 { + rules[i].ServiceIds = utils.InterfaceSliceToStringSlicePtr(r["service_ids"].([]interface{})) } if v, ok := r["from_port_range"]; ok { rules[i].FromPortRange = pointy.Int32(cast.ToInt32(v)) diff --git a/outscale/resource_outscale_vm.go b/outscale/resource_outscale_vm.go index eefddb474..9d07c5e1e 100644 --- a/outscale/resource_outscale_vm.go +++ b/outscale/resource_outscale_vm.go @@ -804,7 +804,7 @@ func resourceVMUpdate(d *schema.ResourceData, meta interface{}) error { if d.HasChange("security_group_ids") && !d.IsNewResource() { opts := oscgo.UpdateVmRequest{VmId: id} - opts.SetSecurityGroupIds(expandStringValueList(d.Get("security_group_ids").([]interface{}))) + opts.SetSecurityGroupIds(utils.InterfaceSliceToStringSlice(d.Get("security_group_ids").([]interface{}))) if err := updateVmAttr(conn, opts); err != nil { return err } @@ -812,7 +812,7 @@ func resourceVMUpdate(d *schema.ResourceData, meta interface{}) error { if d.HasChange("security_group_names") && !d.IsNewResource() { opts := oscgo.UpdateVmRequest{VmId: id} - opts.SetSecurityGroupIds(expandStringValueList(d.Get("security_group_names").([]interface{}))) + opts.SetSecurityGroupIds(utils.InterfaceSliceToStringSlice(d.Get("security_group_names").([]interface{}))) if err := updateVmAttr(conn, opts); err != nil { return err } @@ -996,15 +996,15 @@ func buildCreateVmsRequest(d *schema.ResourceData, meta interface{}) (oscgo.Crea request.SetNics(nics) } - if privateIPs := expandStringValueList(d.Get("private_ips").([]interface{})); len(privateIPs) > 0 { + if privateIPs := utils.InterfaceSliceToStringSlice(d.Get("private_ips").([]interface{})); len(privateIPs) > 0 { request.SetPrivateIps(privateIPs) } - if sgIDs := expandStringValueList(d.Get("security_group_ids").([]interface{})); len(sgIDs) > 0 { + if sgIDs := utils.InterfaceSliceToStringSlice(d.Get("security_group_ids").([]interface{})); len(sgIDs) > 0 { request.SetSecurityGroupIds(sgIDs) } - if sgNames := expandStringValueList(d.Get("security_group_names").([]interface{})); len(sgNames) > 0 { + if sgNames := utils.InterfaceSliceToStringSlice(d.Get("security_group_names").([]interface{})); len(sgNames) > 0 { request.SetSecurityGroups(sgNames) } @@ -1133,7 +1133,7 @@ func buildNetworkInterfaceOpts(d *schema.ResourceData) []oscgo.NicForVmCreation ni.SetPrivateIps(expandPrivatePublicIps(nic["private_ips"].(*schema.Set))) ni.SetSubnetId(nic["subnet_id"].(string)) - if sg := expandStringValueList(nic["security_group_ids"].([]interface{})); len(sg) > 0 { + if sg := utils.InterfaceSliceToStringSlice(nic["security_group_ids"].([]interface{})); len(sg) > 0 { ni.SetSecurityGroupIds(sg) } diff --git a/utils/utils.go b/utils/utils.go index 6e9860cba..1ec16b8f7 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -12,6 +12,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) // PrintToJSON method helper to debug responses @@ -146,3 +147,47 @@ func CheckThrottling(errCode int, err error) *resource.RetryError { } return resource.NonRetryableError(err) } + +func InterfaceSliceToStringSlicePtr(slice []interface{}) *[]string { + result := InterfaceSliceToStringSlice(slice) + return &result +} + +func SetToStringSlice(set *schema.Set) []string { + return InterfaceSliceToStringSlice(set.List()) +} + +func SetToStringSlicePtr(set *schema.Set) *[]string { + return InterfaceSliceToStringSlicePtr(set.List()) +} + +func InterfaceSliceToStringSlice(slice []interface{}) []string { + result := make([]string, 0, len(slice)) + for _, v := range slice { + val, ok := v.(string) + if ok && val != "" { + result = append(result, v.(string)) + } + } + return result +} + +func InterfaceSliceToStringList(slice []interface{}) *[]string { + res := InterfaceSliceToStringSlice(slice) + return &res +} + +func StringSlicePtrToInterfaceSlice(list *[]string) []interface{} { + if list == nil { + return make([]interface{}, 0) + } + vs := make([]interface{}, 0, len(*list)) + for _, v := range *list { + vs = append(vs, v) + } + return vs +} + +func I32toa(i int32) string { + return strconv.FormatInt(int64(i), 10) +}