mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/openstack: Add timeout support for Compute resources (#12794)
This commit adds support for specifying timeout values for the openstack_compute_* family of resources.
This commit is contained in:
parent
f5b3e0c558
commit
f54b0a88a7
@ -34,6 +34,12 @@ func resourceComputeInstanceV2() *schema.Resource {
|
|||||||
Update: resourceComputeInstanceV2Update,
|
Update: resourceComputeInstanceV2Update,
|
||||||
Delete: resourceComputeInstanceV2Delete,
|
Delete: resourceComputeInstanceV2Delete,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Create: schema.DefaultTimeout(30 * time.Minute),
|
||||||
|
Update: schema.DefaultTimeout(30 * time.Minute),
|
||||||
|
Delete: schema.DefaultTimeout(30 * time.Minute),
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@ -457,7 +463,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e
|
|||||||
Pending: []string{"BUILD"},
|
Pending: []string{"BUILD"},
|
||||||
Target: []string{"ACTIVE"},
|
Target: []string{"ACTIVE"},
|
||||||
Refresh: ServerV2StateRefreshFunc(computeClient, server.ID),
|
Refresh: ServerV2StateRefreshFunc(computeClient, server.ID),
|
||||||
Timeout: 30 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutCreate),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
@ -808,7 +814,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
|
|||||||
Pending: []string{"RESIZE"},
|
Pending: []string{"RESIZE"},
|
||||||
Target: []string{"VERIFY_RESIZE"},
|
Target: []string{"VERIFY_RESIZE"},
|
||||||
Refresh: ServerV2StateRefreshFunc(computeClient, d.Id()),
|
Refresh: ServerV2StateRefreshFunc(computeClient, d.Id()),
|
||||||
Timeout: 30 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutUpdate),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
@ -829,7 +835,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
|
|||||||
Pending: []string{"VERIFY_RESIZE"},
|
Pending: []string{"VERIFY_RESIZE"},
|
||||||
Target: []string{"ACTIVE"},
|
Target: []string{"ACTIVE"},
|
||||||
Refresh: ServerV2StateRefreshFunc(computeClient, d.Id()),
|
Refresh: ServerV2StateRefreshFunc(computeClient, d.Id()),
|
||||||
Timeout: 30 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutUpdate),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
@ -908,7 +914,7 @@ func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) e
|
|||||||
Pending: []string{"ACTIVE", "SHUTOFF"},
|
Pending: []string{"ACTIVE", "SHUTOFF"},
|
||||||
Target: []string{"DELETED"},
|
Target: []string{"DELETED"},
|
||||||
Refresh: ServerV2StateRefreshFunc(computeClient, d.Id()),
|
Refresh: ServerV2StateRefreshFunc(computeClient, d.Id()),
|
||||||
Timeout: 30 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutDelete),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
|
@ -639,6 +639,23 @@ func TestAccComputeV2Instance_forceDelete(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeV2Instance_timeout(t *testing.T) {
|
||||||
|
var instance servers.Server
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeV2InstanceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeV2Instance_timeout,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error {
|
func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error {
|
||||||
config := testAccProvider.Meta().(*Config)
|
config := testAccProvider.Meta().(*Config)
|
||||||
computeClient, err := config.computeV2Client(OS_REGION_NAME)
|
computeClient, err := config.computeV2Client(OS_REGION_NAME)
|
||||||
@ -1537,6 +1554,17 @@ const testAccComputeV2Instance_forceDelete = `
|
|||||||
resource "openstack_compute_instance_v2" "instance_1" {
|
resource "openstack_compute_instance_v2" "instance_1" {
|
||||||
name = "instance_1"
|
name = "instance_1"
|
||||||
security_groups = ["default"]
|
security_groups = ["default"]
|
||||||
force_delete = true
|
force_delete = true
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const testAccComputeV2Instance_timeout = `
|
||||||
|
resource "openstack_compute_instance_v2" "instance_1" {
|
||||||
|
name = "instance_1"
|
||||||
|
security_groups = ["default"]
|
||||||
|
|
||||||
|
timeouts {
|
||||||
|
create = "10m"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
@ -24,6 +24,10 @@ func resourceComputeSecGroupV2() *schema.Resource {
|
|||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Delete: schema.DefaultTimeout(10 * time.Minute),
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@ -224,7 +228,7 @@ func resourceComputeSecGroupV2Delete(d *schema.ResourceData, meta interface{}) e
|
|||||||
Pending: []string{"ACTIVE"},
|
Pending: []string{"ACTIVE"},
|
||||||
Target: []string{"DELETED"},
|
Target: []string{"DELETED"},
|
||||||
Refresh: SecGroupV2StateRefreshFunc(computeClient, d),
|
Refresh: SecGroupV2StateRefreshFunc(computeClient, d),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutDelete),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,24 @@ func TestAccComputeV2SecGroup_lowerCaseCIDR(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeV2SecGroup_timeout(t *testing.T) {
|
||||||
|
var secgroup secgroups.SecurityGroup
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeV2SecGroupDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeV2SecGroup_timeout,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.sg_1", &secgroup),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckComputeV2SecGroupDestroy(s *terraform.State) error {
|
func testAccCheckComputeV2SecGroupDestroy(s *terraform.State) error {
|
||||||
config := testAccProvider.Meta().(*Config)
|
config := testAccProvider.Meta().(*Config)
|
||||||
computeClient, err := config.computeV2Client(OS_REGION_NAME)
|
computeClient, err := config.computeV2Client(OS_REGION_NAME)
|
||||||
@ -373,3 +391,20 @@ resource "openstack_compute_secgroup_v2" "sg_1" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccComputeV2SecGroup_timeout = `
|
||||||
|
resource "openstack_compute_secgroup_v2" "sg_1" {
|
||||||
|
name = "sg_1"
|
||||||
|
description = "first test security group"
|
||||||
|
rule {
|
||||||
|
from_port = 0
|
||||||
|
to_port = 0
|
||||||
|
ip_protocol = "icmp"
|
||||||
|
cidr = "0.0.0.0/0"
|
||||||
|
}
|
||||||
|
|
||||||
|
timeouts {
|
||||||
|
delete = "5m"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
@ -22,6 +22,11 @@ func resourceComputeVolumeAttachV2() *schema.Resource {
|
|||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Create: schema.DefaultTimeout(10 * time.Minute),
|
||||||
|
Delete: schema.DefaultTimeout(10 * time.Minute),
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@ -82,7 +87,7 @@ func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{
|
|||||||
Pending: []string{"ATTACHING"},
|
Pending: []string{"ATTACHING"},
|
||||||
Target: []string{"ATTACHED"},
|
Target: []string{"ATTACHED"},
|
||||||
Refresh: resourceComputeVolumeAttachV2AttachFunc(computeClient, instanceId, attachment.ID),
|
Refresh: resourceComputeVolumeAttachV2AttachFunc(computeClient, instanceId, attachment.ID),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutCreate),
|
||||||
Delay: 30 * time.Second,
|
Delay: 30 * time.Second,
|
||||||
MinTimeout: 15 * time.Second,
|
MinTimeout: 15 * time.Second,
|
||||||
}
|
}
|
||||||
@ -145,7 +150,7 @@ func resourceComputeVolumeAttachV2Delete(d *schema.ResourceData, meta interface{
|
|||||||
Pending: []string{""},
|
Pending: []string{""},
|
||||||
Target: []string{"DETACHED"},
|
Target: []string{"DETACHED"},
|
||||||
Refresh: resourceComputeVolumeAttachV2DetachFunc(computeClient, instanceId, attachmentId),
|
Refresh: resourceComputeVolumeAttachV2DetachFunc(computeClient, instanceId, attachmentId),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutDelete),
|
||||||
Delay: 15 * time.Second,
|
Delay: 15 * time.Second,
|
||||||
MinTimeout: 15 * time.Second,
|
MinTimeout: 15 * time.Second,
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,24 @@ func TestAccComputeV2VolumeAttach_device(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeV2VolumeAttach_timeout(t *testing.T) {
|
||||||
|
var va volumeattach.VolumeAttachment
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeV2VolumeAttach_timeout,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeV2VolumeAttachExists("openstack_compute_volume_attach_v2.va_1", &va),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckComputeV2VolumeAttachDestroy(s *terraform.State) error {
|
func testAccCheckComputeV2VolumeAttachDestroy(s *terraform.State) error {
|
||||||
config := testAccProvider.Meta().(*Config)
|
config := testAccProvider.Meta().(*Config)
|
||||||
computeClient, err := config.computeV2Client(OS_REGION_NAME)
|
computeClient, err := config.computeV2Client(OS_REGION_NAME)
|
||||||
@ -156,3 +174,25 @@ resource "openstack_compute_volume_attach_v2" "va_1" {
|
|||||||
device = "/dev/vdc"
|
device = "/dev/vdc"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccComputeV2VolumeAttach_timeout = `
|
||||||
|
resource "openstack_blockstorage_volume_v2" "volume_1" {
|
||||||
|
name = "volume_1"
|
||||||
|
size = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "openstack_compute_instance_v2" "instance_1" {
|
||||||
|
name = "instance_1"
|
||||||
|
security_groups = ["default"]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "openstack_compute_volume_attach_v2" "va_1" {
|
||||||
|
instance_id = "${openstack_compute_instance_v2.instance_1.id}"
|
||||||
|
volume_id = "${openstack_blockstorage_volume_v2.volume_1.id}"
|
||||||
|
|
||||||
|
timeouts {
|
||||||
|
create = "5m"
|
||||||
|
delete = "5m"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user