Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update data_sources fliters and Reduce the number of parallel tests #436

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ test-net: fmtcheck

.PHONY: test-vm
test-vm: fmtcheck
TF_ACC=1 go test $(TEST) -run=TestAccVM -count 1 -v -parallel 8 $(TESTARGS) -timeout 240m -cover
TF_ACC=1 go test $(TEST) -run=TestAccVM -count 1 -v -parallel 6 $(TESTARGS) -timeout 240m -cover

.PHONY: test-others
test-others: fmtcheck test-gen-cert
TF_ACC=1 go test $(TEST) -run=TestAccOthers -count 1 -v -parallel 8 $(TESTARGS) -timeout 240m -cover
TF_ACC=1 go test $(TEST) -run=TestAccOthers -count 1 -v -parallel 6 $(TESTARGS) -timeout 240m -cover

.PHONY: fmt
fmt:
Expand Down
2 changes: 2 additions & 0 deletions outscale/data_source_outscale_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ func buildOutscaleOAPIDataSourceImagesFilters(set *schema.Set) *oscgo.FiltersIma
filters.SetPermissionsToLaunchGlobalPermission(cast.ToBool(filterValues[0]))
case "product_codes":
filters.SetProductCodes(filterValues)
case "product_code_names":
filters.SetProductCodeNames(filterValues)
case "root_device_names":
filters.SetRootDeviceNames(filterValues)
case "root_device_types":
Expand Down
18 changes: 14 additions & 4 deletions outscale/data_source_outscale_net_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ func dataSourceOutscaleOAPILinPeeringConnectionRead(d *schema.ResourceData, meta
if !filtersOk {
return fmt.Errorf("filters must be assigned")
}
req.SetFilters(buildOutscaleOAPILinPeeringConnectionFilters(filters.(*schema.Set)))
filtersValues, err := buildOutscaleOAPILinPeeringConnectionFilters(filters.(*schema.Set))
if err != nil {
return err
}
req.SetFilters(filtersValues)

var resp oscgo.ReadNetPeeringsResponse
var err error
var statusCode int
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
rp, httpResp, err := conn.NetPeeringApi.ReadNetPeerings(context.Background()).ReadNetPeeringsRequest(req).Execute()
Expand Down Expand Up @@ -140,7 +143,7 @@ func dataSourceOutscaleOAPILinPeeringConnectionRead(d *schema.ResourceData, meta
return nil
}

func buildOutscaleOAPILinPeeringConnectionFilters(set *schema.Set) oscgo.FiltersNetPeering {
func buildOutscaleOAPILinPeeringConnectionFilters(set *schema.Set) (oscgo.FiltersNetPeering, error) {
var filters oscgo.FiltersNetPeering
for _, v := range set.List() {
m := v.(map[string]interface{})
Expand All @@ -166,6 +169,13 @@ func buildOutscaleOAPILinPeeringConnectionFilters(set *schema.Set) oscgo.Filters
filters.SetSourceNetNetIds(filterValues)
case "state_messages":
filters.SetStateMessages(filterValues)
case "expiration_dates":
expirationDates, err := utils.StringSliceToTimeSlice(
filterValues, "expiration_dates")
if err != nil {
return filters, err
}
filters.SetExpirationDates(expirationDates)
case "state_names":
filters.SetStateNames(filterValues)
case "tag_keys":
Expand All @@ -178,5 +188,5 @@ func buildOutscaleOAPILinPeeringConnectionFilters(set *schema.Set) oscgo.Filters
log.Printf("[Debug] Unknown Filter Name: %s.", name)
}
}
return filters
return filters, nil
}
7 changes: 5 additions & 2 deletions outscale/data_source_outscale_net_peerings.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ func dataSourceOutscaleOAPILinPeeringsConnectionRead(d *schema.ResourceData, met
}

params := oscgo.ReadNetPeeringsRequest{}
params.SetFilters(buildOutscaleOAPILinPeeringConnectionFilters(filters.(*schema.Set)))
filtersValues, err := buildOutscaleOAPILinPeeringConnectionFilters(filters.(*schema.Set))
if err != nil {
return err
}
params.SetFilters(filtersValues)

var resp oscgo.ReadNetPeeringsResponse
var err error
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
rp, httpResp, err := conn.NetPeeringApi.ReadNetPeerings(context.Background()).ReadNetPeeringsRequest(params).Execute()
if err != nil {
Expand Down
14 changes: 2 additions & 12 deletions outscale/data_source_outscale_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strconv"
"time"

"github.com/nav-inc/datetime"
oscgo "github.com/outscale/osc-sdk-go/v2"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -212,14 +211,14 @@ func buildOutscaleOapiSnapshootDataSourceFilters(set *schema.Set, filter *oscgo.
case "descriptions":
filter.SetDescriptions(values)
case "to_creation_date":
valDate, err := parsingfilterDateFormat("to_creation_date", values[0])
valDate, err := utils.ParsingfilterToDateFormat("to_creation_date", values[0])
if err != nil {
return err
}
filter.SetToCreationDate(valDate)

case "from_creation_date":
valDate, err := parsingfilterDateFormat("from_creation_date", values[0])
valDate, err := utils.ParsingfilterToDateFormat("from_creation_date", values[0])
if err != nil {
return err
}
Expand Down Expand Up @@ -265,12 +264,3 @@ func buildOutscaleOapiSnapshootDataSourceFilters(set *schema.Set, filter *oscgo.
}
return nil
}
func parsingfilterDateFormat(filterName, value string) (time.Time, error) {
var err error
var filterDate time.Time

if filterDate, err = datetime.Parse(value, time.UTC); err != nil {
return filterDate, fmt.Errorf("%s value should be 'ISO 8601' format ('2017-06-14' or '2017-06-14T00:00:00Z, ...) %s", filterName, err)
}
return filterDate, nil
}
4 changes: 4 additions & 0 deletions outscale/data_source_outscale_subregions.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func buildOutscaleOAPIDataSourceSubregionsFilters(set *schema.Set) *oscgo.Filter
switch name := m["name"].(string); name {
case "subregion_names":
filters.SetSubregionNames(filterValues)
case "states":
filters.SetStates(filterValues)
case "region_names":
filters.SetRegionNames(filterValues)
default:
log.Printf("[Debug] Unknown Filter Name: %s.", name)
}
Expand Down
6 changes: 5 additions & 1 deletion outscale/data_source_outscale_subregions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func testAccCheckOutscaleOAPISubregionsDataSourceConfig(subregionName string) st
data "outscale_subregions" "test" {
filter {
name = "subregion_names"
values = ["%s"]
values = ["%[1]sa"]
}
filter {
name = "region_names"
values = ["%[1]s"]
}
}
`, subregionName)
Expand Down
158 changes: 149 additions & 9 deletions outscale/data_source_outscale_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
oscgo "github.com/outscale/osc-sdk-go/v2"
"github.com/spf13/cast"
"github.com/terraform-providers/terraform-provider-outscale/utils"
)

Expand All @@ -25,14 +26,17 @@ func dataSourceOutscaleOAPIVMRead(d *schema.ResourceData, meta interface{}) erro

filters, filtersOk := d.GetOk("filter")
instanceID, instanceIDOk := d.GetOk("vm_id")

var err error
if !filtersOk && !instanceIDOk {
return fmt.Errorf("One of filters, or instance_id must be assigned")
}
// Build up search parameters
params := oscgo.ReadVmsRequest{}
if filtersOk {
params.Filters = buildOutscaleOAPIDataSourceVMFilters(filters.(*schema.Set))
params.Filters, err = buildOutscaleOAPIDataSourceVMFilters(filters.(*schema.Set))
if err != nil {
return err
}
}
if instanceIDOk {
params.Filters.VmIds = &[]string{instanceID.(string)}
Expand All @@ -41,7 +45,7 @@ func dataSourceOutscaleOAPIVMRead(d *schema.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] ReadVmsRequest -> %+v\n", params)

var resp oscgo.ReadVmsResponse
err := resource.Retry(30*time.Second, func() *resource.RetryError {
err = resource.Retry(30*time.Second, func() *resource.RetryError {
rp, httpResp, err := client.VmApi.ReadVms(context.Background()).ReadVmsRequest(params).Execute()
if err != nil {
return utils.CheckThrottling(httpResp, err)
Expand Down Expand Up @@ -266,7 +270,7 @@ func getDataSourceOAPIVMSchemas() map[string]*schema.Schema {
return wholeSchema
}

func buildOutscaleOAPIDataSourceVMFilters(set *schema.Set) *oscgo.FiltersVm {
func buildOutscaleOAPIDataSourceVMFilters(set *schema.Set) (*oscgo.FiltersVm, error) {
filters := new(oscgo.FiltersVm)

for _, v := range set.List() {
Expand All @@ -277,19 +281,155 @@ func buildOutscaleOAPIDataSourceVMFilters(set *schema.Set) *oscgo.FiltersVm {
}

switch name := m["name"].(string); name {
case "architectures":
filters.SetArchitectures(filterValues)
case "Block_device_mapping_delete_on_vm_deletion":
filters.SetBlockDeviceMappingDeleteOnVmDeletion(cast.ToBool(filterValues[0]))
case "block_device_mapping_device_names":
filters.SetBlockDeviceMappingDeviceNames(filterValues)
case "block_device_mapping_states":
filters.SetBlockDeviceMappingStates(filterValues)
case "block_device_mapping_link_dates":
linkDates, err := utils.FiltersTimesToStringSlice(
filterValues, "block_device_mapping_link_dates")
if err != nil {
return filters, err
}
filters.SetBlockDeviceMappingLinkDates(linkDates)
case "block_device_mapping_volume_ids":
filters.SetBlockDeviceMappingVolumeIds(filterValues)
case "ClientTokens":
filters.SetClientTokens(filterValues)
case "creation_dates":
creationDates, err := utils.FiltersTimesToStringSlice(
filterValues, "creation_dates")
if err != nil {
return filters, err
}
filters.SetCreationDates(creationDates)
case "image_ids":
filters.SetImageIds(filterValues)
case "is_source_dest_checked":
filters.SetIsSourceDestChecked(cast.ToBool(filterValues[0]))
case "keypair_names":
filters.SetKeypairNames(filterValues)
case "launch_numbers":
filters.SetLaunchNumbers(utils.StringSliceToInt32Slice(filterValues))
case "lifecycles":
filters.SetLifecycles(filterValues)
case "net_ids":
filters.SetNetIds(filterValues)
case "nic_account_ids":
filters.SetNicAccountIds(filterValues)
case "nic_descriptions":
filters.SetNicDescriptions(filterValues)
case "nic_is_source_dest_checked":
filters.SetNicIsSourceDestChecked(cast.ToBool(filterValues[0]))
case "nic_link_nic_delete_on_vm_deletion":
filters.SetNicLinkNicDeleteOnVmDeletion(cast.ToBool(filterValues[0]))
case "nic_link_nic_device_numbers":
filters.SetNicLinkNicDeviceNumbers(
utils.StringSliceToInt32Slice(filterValues))
case "nic_link_nic_link_nic_dates":
linkDates, err := utils.FiltersTimesToStringSlice(
filterValues, "nic_link_nic_link_nic_dates")
if err != nil {
return filters, err
}
filters.SetNicLinkNicLinkNicDates(linkDates)
case "nic_link_nic_link_nic_ids":
filters.SetNicLinkNicLinkNicIds(filterValues)
case "nic_link_nic_states":
filters.SetNicLinkNicStates(filterValues)
case "nic_link_nic_vm_account_ids":
filters.SetNicLinkNicVmAccountIds(filterValues)
case "nic_link_nic_vm_ids":
filters.SetNicLinkNicVmIds(filterValues)
case "nic_link_public_ip_account_ids":
filters.SetNicLinkPublicIpAccountIds(filterValues)
case "nic_link_public_ip_link_public_ip_ids":
filters.SetNicLinkPublicIpLinkPublicIpIds(filterValues)
case "nic_link_public_ip_public_ip_ids":
filters.SetNicLinkPublicIpPublicIpIds(filterValues)
case "nic_link_public_Ip_public_ips":
filters.SetNicLinkPublicIpPublicIps(filterValues)
case "nic_mac_addresses":
filters.SetNicMacAddresses(filterValues)
case "nic_net_ids":
filters.SetNicNetIds(filterValues)
case "nic_nic_ids":
filters.SetNicNicIds(filterValues)
case "nic_private_ips_link_public_ip_account_ids":
filters.SetNicPrivateIpsLinkPublicIpAccountIds(filterValues)
case "nic_private_ips_primary_ip":
filters.SetNicPrivateIpsPrimaryIp(cast.ToBool(filterValues[0]))
case "nic_private_ips_private_ips":
filters.SetNicPrivateIpsPrivateIps(filterValues)
case "nic_security_group_ids":
filters.SetNicSecurityGroupIds(filterValues)
case "nic_security_group_names":
filters.SetNicSecurityGroupNames(filterValues)
case "nic_states":
filters.SetNicStates(filterValues)
case "nic_subnet_ids":
filters.SetNicSubnetIds(filterValues)
case "nic_subregion_names":
filters.SetNicSubregionNames(filterValues)
case "platforms":
filters.SetPlatforms(filterValues)
case "private_ips":
filters.SetPrivateIps(filterValues)
case "product_codes":
filters.SetProductCodes(filterValues)
case "public_ips":
filters.SetPublicIps(filterValues)
case "reservation_ids":
filters.SetReservationIds(filterValues)
case "root_device_names":
filters.SetRootDeviceNames(filterValues)
case "root_tevice_types":
filters.SetRootDeviceTypes(filterValues)
case "security_group_ids":
filters.SetSecurityGroupIds(filterValues)
case "security_group_names":
filters.SetSecurityGroupNames(filterValues)
case "state_reason_codes":
filters.SetStateReasonCodes(
utils.StringSliceToInt32Slice(filterValues))
case "state_reason_messages":
filters.SetStateReasonMessages(filterValues)
case "state_reasons":
filters.SetStateReasons(filterValues)
case "subnet_ids":
filters.SetSubnetIds(filterValues)
case "subregion_names":
filters.SetSubregionNames(filterValues)
case "tag_keys":
filters.TagKeys = &filterValues
filters.SetTagKeys(filterValues)
case "tag_values":
filters.TagValues = &filterValues
filters.SetTagValues(filterValues)
case "tags":
filters.Tags = &filterValues
filters.SetTags(filterValues)
case "vm_ids":
filters.VmIds = &filterValues
filters.SetVmIds(filterValues)
case "tenancies":
filters.SetTenancies(filterValues)
case "vm_security_group_ids":
filters.SetVmSecurityGroupIds(filterValues)
case "vm_security_group_names":
filters.SetVmSecurityGroupNames(filterValues)
case "vm_state_codes":
filters.SetVmStateCodes(
utils.StringSliceToInt32Slice(filterValues))
case "vm_state_names":
filters.SetVmStateNames(filterValues)
case "VmTypes":
filters.SetVmTypes(filterValues)
default:
log.Printf("[Debug] Unknown Filter Name: %s.", name)
}
}
return filters
return filters, nil
}

func getOApiVMAttributesSchema() map[string]*schema.Schema {
Expand Down
6 changes: 6 additions & 0 deletions outscale/data_source_outscale_vm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ func buildOutscaleOAPIDataSourceVMTypesFilters(set *schema.Set) oscgo.FiltersVmT
switch name := m["name"].(string); name {
case "bsu_optimized":
filters.SetBsuOptimized(cast.ToBool(filterValues[0]))
case "ephemerals_types":
filters.SetEphemeralsTypes(filterValues)
case "eths":
filters.SetEths(utils.StringSliceToInt32Slice(filterValues))
case "gpus":
filters.SetGpus(utils.StringSliceToInt32Slice(filterValues))
case "memory_sizes":
filters.SetMemorySizes(utils.StringSliceToFloat32Slice(filterValues))
case "vcore_counts":
Expand Down
9 changes: 6 additions & 3 deletions outscale/data_source_outscale_vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,25 @@ func dataSourceOutscaleOApiVMSRead(d *schema.ResourceData, meta interface{}) err

filters, filtersOk := d.GetOk("filter")
vmID, vmIDOk := d.GetOk("vm_id")

var err error
if !filtersOk && !vmIDOk {
return fmt.Errorf("One of filters, and vm ID must be assigned")
}

// Build up search parameters
params := oscgo.ReadVmsRequest{}
if filtersOk {
params.Filters = buildOutscaleOAPIDataSourceVMFilters(filters.(*schema.Set))
params.Filters, err = buildOutscaleOAPIDataSourceVMFilters(filters.(*schema.Set))
if err != nil {
return err
}
}
if vmIDOk {
params.Filters.VmIds = &[]string{vmID.(string)}
}

var resp oscgo.ReadVmsResponse
err := resource.Retry(30*time.Second, func() *resource.RetryError {
err = resource.Retry(30*time.Second, func() *resource.RetryError {
rp, httpResp, err := client.VmApi.ReadVms(context.Background()).ReadVmsRequest(params).Execute()
if err != nil {
return utils.CheckThrottling(httpResp, err)
Expand Down
Loading
Loading