opentofu/builtin/providers/scaleway/provider.go
Raphael Randschau d9a2e0dbb3 provider/scaleway: fix scaleway_volume_attachment with count > 1 (#9493)
* provider/scaleway: fix scaleway_volume_attachment with count > 1

since scaleway requires servers to be powered off to attach volumes to, we need
to make sure that we don't power down a server twice, or power up a server while
it's supposed to be modified.

sadly terraform doesn't seem to sport serialization primitives for usecases like
this, but putting the code in question behind a `sync.Mutex` does the trick, too

fixes #9417

* provider/scaleway: use mutexkv to lock per-resource

following  @dcharbonnier  suggestion. thanks!

* provider/scaleway: cleanup waitForServerState signature

* provider/scaleway: store serverID in var

* provider/scaleway: correct imports

* provider/scaleway: increase timeouts
2016-10-27 16:51:34 +01:00

62 lines
1.9 KiB
Go

package scaleway
import (
"github.com/hashicorp/terraform/helper/mutexkv"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"access_key": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ACCESS_KEY", nil),
Description: "The API key for Scaleway API operations.",
},
"organization": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ORGANIZATION", nil),
Description: "The Organization ID for Scaleway API operations.",
},
"region": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_REGION", "par1"),
Description: "The Scaleway API region to use.",
},
},
ResourcesMap: map[string]*schema.Resource{
"scaleway_server": resourceScalewayServer(),
"scaleway_ip": resourceScalewayIP(),
"scaleway_security_group": resourceScalewaySecurityGroup(),
"scaleway_security_group_rule": resourceScalewaySecurityGroupRule(),
"scaleway_volume": resourceScalewayVolume(),
"scaleway_volume_attachment": resourceScalewayVolumeAttachment(),
},
DataSourcesMap: map[string]*schema.Resource{
"scaleway_bootscript": dataSourceScalewayBootscript(),
"scaleway_image": dataSourceScalewayImage(),
},
ConfigureFunc: providerConfigure,
}
}
var scalewayMutexKV = mutexkv.NewMutexKV()
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
Organization: d.Get("organization").(string),
APIKey: d.Get("access_key").(string),
Region: d.Get("region").(string),
}
return config.Client()
}