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

provider/openstack: Adding Timeouts to FWaaS v1 Resources #12863

Merged
merged 1 commit into from
Mar 19, 2017
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
15 changes: 11 additions & 4 deletions builtin/providers/openstack/resource_openstack_fw_firewall_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func resourceFWFirewallV1() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
"region": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -94,7 +100,7 @@ func resourceFWFirewallV1Create(d *schema.ResourceData, meta interface{}) error
Pending: []string{"PENDING_CREATE"},
Target: []string{"ACTIVE"},
Refresh: waitForFirewallActive(networkingClient, firewall.ID),
Timeout: 30 * time.Second,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 0,
MinTimeout: 2 * time.Second,
}
Expand Down Expand Up @@ -165,7 +171,7 @@ func resourceFWFirewallV1Update(d *schema.ResourceData, meta interface{}) error
Pending: []string{"PENDING_CREATE", "PENDING_UPDATE"},
Target: []string{"ACTIVE"},
Refresh: waitForFirewallActive(networkingClient, d.Id()),
Timeout: 30 * time.Second,
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: 0,
MinTimeout: 2 * time.Second,
}
Expand All @@ -189,11 +195,12 @@ func resourceFWFirewallV1Delete(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

// Ensure the firewall was fully created/updated before being deleted.
stateConf := &resource.StateChangeConf{
Pending: []string{"PENDING_CREATE", "PENDING_UPDATE"},
Target: []string{"ACTIVE"},
Refresh: waitForFirewallActive(networkingClient, d.Id()),
Timeout: 30 * time.Second,
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: 0,
MinTimeout: 2 * time.Second,
}
Expand All @@ -210,7 +217,7 @@ func resourceFWFirewallV1Delete(d *schema.ResourceData, meta interface{}) error
Pending: []string{"DELETING"},
Target: []string{"DELETED"},
Refresh: waitForFirewallDeletion(networkingClient, d.Id()),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 0,
MinTimeout: 2 * time.Second,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ func TestAccFWFirewallV1_basic(t *testing.T) {
})
}

func TestAccFWFirewallV1_timeout(t *testing.T) {
var policyID *string

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFWFirewallV1Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccFWFirewallV1_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckFWFirewallV1Exists("openstack_fw_firewall_v1.fw_1", "", "", policyID),
),
},
},
})
}

func testAccCheckFWFirewallV1Destroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -135,3 +153,19 @@ resource "openstack_fw_policy_v1" "policy_2" {
name = "policy_2"
}
`

const testAccFWFirewallV1_timeout = `
resource "openstack_fw_firewall_v1" "fw_1" {
policy_id = "${openstack_fw_policy_v1.policy_1.id}"

timeouts {
create = "5m"
update = "5m"
delete = "5m"
}
}

resource "openstack_fw_policy_v1" "policy_1" {
name = "policy_1"
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func resourceFWPolicyV1() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
"region": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -194,7 +198,7 @@ func resourceFWPolicyV1Delete(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"ACTIVE"},
Target: []string{"DELETED"},
Refresh: waitForFirewallPolicyDeletion(networkingClient, d.Id()),
Timeout: 120 * time.Second,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 0,
MinTimeout: 2 * time.Second,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ func TestAccFWPolicyV1_deleteRules(t *testing.T) {
})
}

func TestAccFWPolicyV1_timeout(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFWPolicyV1Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccFWPolicyV1_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckFWPolicyV1Exists(
"openstack_fw_policy_v1.policy_1", "", "", 0),
),
},
},
})
}

func testAccCheckFWPolicyV1Destroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -172,3 +189,11 @@ resource "openstack_fw_rule_v1" "udp_deny" {
action = "deny"
}
`

const testAccFWPolicyV1_timeout = `
resource "openstack_fw_policy_v1" "policy_1" {
timeouts {
create = "5m"
}
}
`