func resourceFWFirewallV1Update(d *schema.ResourceData, meta interface{}) error {

	config := meta.(*Config)
	networkingClient, err := config.networkingV2Client(d.Get("region").(string))
	if err != nil {
		return fmt.Errorf("Error creating OpenStack networking client: %s", err)
	}

	opts := firewalls.UpdateOpts{}

	if d.HasChange("name") {
		opts.Name = d.Get("name").(string)
	}

	if d.HasChange("description") {
		opts.Description = d.Get("description").(string)
	}

	if d.HasChange("policy_id") {
		opts.PolicyID = d.Get("policy_id").(string)
	}

	if d.HasChange("admin_state_up") {
		adminStateUp := d.Get("admin_state_up").(bool)
		opts.AdminStateUp = &adminStateUp
	}

	log.Printf("[DEBUG] Updating firewall with id %s: %#v", d.Id(), opts)

	stateConf := &resource.StateChangeConf{
		Pending:    []string{"PENDING_CREATE", "PENDING_UPDATE"},
		Target:     "ACTIVE",
		Refresh:    waitForFirewallActive(networkingClient, d.Id()),
		Timeout:    30 * time.Second,
		Delay:      0,
		MinTimeout: 2 * time.Second,
	}

	_, err = stateConf.WaitForState()

	err = firewalls.Update(networkingClient, d.Id(), opts).Err
	if err != nil {
		return err
	}

	return resourceFWFirewallV1Read(d, meta)
}
Ejemplo n.º 2
0
func updateFirewall(t *testing.T, firewallID string, opts *firewalls.UpdateOpts) {
	f, err := firewalls.Update(base.Client, firewallID, *opts).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Updated firewall ID [%s]", f.ID)
}