コード例 #1
0
func resourceFWFirewallV1Create(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)
	}

	adminStateUp := d.Get("admin_state_up").(bool)

	firewallConfiguration := firewalls.CreateOpts{
		Name:         d.Get("name").(string),
		Description:  d.Get("description").(string),
		PolicyID:     d.Get("policy_id").(string),
		AdminStateUp: &adminStateUp,
		TenantID:     d.Get("tenant_id").(string),
	}

	log.Printf("[DEBUG] Create firewall: %#v", firewallConfiguration)

	firewall, err := firewalls.Create(networkingClient, firewallConfiguration).Extract()
	if err != nil {
		return err
	}

	log.Printf("[DEBUG] Firewall created: %#v", firewall)

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

	_, err = stateConf.WaitForState()

	d.SetId(firewall.ID)

	return resourceFWFirewallV1Read(d, meta)
}
コード例 #2
0
ファイル: firewall_test.go プロジェクト: RomainVabre/origin
func createFirewall(t *testing.T, opts *firewalls.CreateOpts) string {
	f, err := firewalls.Create(base.Client, *opts).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Created firewall: %#v", opts)
	return f.ID
}