provider/openstack: Detect Region for Importing Resources (#10509)

* provider/openstack: Detect Region for Importing Resources

This commit changes the way the OpenStack region is detected and set.
Any time a region is required, the region attribute will first be
checked. Next, the OS_REGION_NAME environment variable will be checked.
While schema.EnvDefaultFunc handles this same situation, it is not
applicable when importing resources.

* provider/openstack: No longer ignore region in importing tests

* provider/openstack: Network and Subnet Import Fixes

This commit fixes the OpenStack Network and Subnet resources so that
importing of those resources is successful.
This commit is contained in:
Joe Topjian 2016-12-04 09:24:07 -05:00 committed by Paul Stack
parent 5f7bc12941
commit b2f9a3a6fd
54 changed files with 270 additions and 255 deletions

View File

@ -22,7 +22,6 @@ func TestAccBlockStorageVolumeAttachV2_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackBlockStorageV1Volume_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackBlockStorageV2Volume_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccComputeV2FloatingIP_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackComputeV2Keypair_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccComputeV2SecGroup_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccComputeV2ServerGroup_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccComputeV2VolumeAttach_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackFWFirewallV1_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackFWPolicyV1_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackFWRuleV1_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackLBMemberV1_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackLBMonitorV1_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackLBPoolV1_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackLBVIPV1_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackNetworkingFloatingIPV2_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackNetworkingNetworkV2_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackNetworkingPortV2_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackNetworkingSecGroupRuleV2_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackNetworkingSecGroupV2_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -22,7 +22,6 @@ func TestAccOpenStackNetworkingSubnetV2_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})

View File

@ -74,7 +74,7 @@ func resourceBlockStorageVolumeAttachV2() *schema.Resource {
func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
client, err := config.blockStorageV2Client(d.Get("region").(string))
client, err := config.blockStorageV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -153,7 +153,7 @@ func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta inter
func resourceBlockStorageVolumeAttachV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
client, err := config.blockStorageV2Client(d.Get("region").(string))
client, err := config.blockStorageV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -184,13 +184,14 @@ func resourceBlockStorageVolumeAttachV2Read(d *schema.ResourceData, meta interfa
d.Set("device", attachment.Device)
d.Set("instance_id", attachment.ServerID)
d.Set("host_name", attachment.HostName)
d.Set("region", GetRegion(d))
return nil
}
func resourceBlockStorageVolumeAttachV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
client, err := config.blockStorageV2Client(d.Get("region").(string))
client, err := config.blockStorageV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}

View File

@ -106,7 +106,7 @@ func resourceBlockStorageVolumeV1() *schema.Resource {
func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
blockStorageClient, err := config.blockStorageV1Client(d.Get("region").(string))
blockStorageClient, err := config.blockStorageV1Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -159,7 +159,8 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{}
func resourceBlockStorageVolumeV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
blockStorageClient, err := config.blockStorageV1Client(d.Get("region").(string))
blockStorageClient, err := config.blockStorageV1Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -179,6 +180,7 @@ func resourceBlockStorageVolumeV1Read(d *schema.ResourceData, meta interface{})
d.Set("source_vol_id", v.SourceVolID)
d.Set("volume_type", v.VolumeType)
d.Set("metadata", v.Metadata)
d.Set("region", GetRegion(d))
attachments := make([]map[string]interface{}, len(v.Attachments))
for i, attachment := range v.Attachments {
@ -195,7 +197,7 @@ func resourceBlockStorageVolumeV1Read(d *schema.ResourceData, meta interface{})
func resourceBlockStorageVolumeV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
blockStorageClient, err := config.blockStorageV1Client(d.Get("region").(string))
blockStorageClient, err := config.blockStorageV1Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -219,7 +221,7 @@ func resourceBlockStorageVolumeV1Update(d *schema.ResourceData, meta interface{}
func resourceBlockStorageVolumeV1Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
blockStorageClient, err := config.blockStorageV1Client(d.Get("region").(string))
blockStorageClient, err := config.blockStorageV1Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -232,7 +234,7 @@ func resourceBlockStorageVolumeV1Delete(d *schema.ResourceData, meta interface{}
// make sure this volume is detached from all instances before deleting
if len(v.Attachments) > 0 {
log.Printf("[DEBUG] detaching volumes")
if computeClient, err := config.computeV2Client(d.Get("region").(string)); err != nil {
if computeClient, err := config.computeV2Client(GetRegion(d)); err != nil {
return err
} else {
for _, volumeAttachment := range v.Attachments {

View File

@ -116,7 +116,7 @@ func resourceBlockStorageVolumeV2() *schema.Resource {
func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
blockStorageClient, err := config.blockStorageV2Client(d.Get("region").(string))
blockStorageClient, err := config.blockStorageV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -171,7 +171,7 @@ func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{}
func resourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
blockStorageClient, err := config.blockStorageV2Client(d.Get("region").(string))
blockStorageClient, err := config.blockStorageV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -191,6 +191,7 @@ func resourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{})
d.Set("source_vol_id", v.SourceVolID)
d.Set("volume_type", v.VolumeType)
d.Set("metadata", v.Metadata)
d.Set("region", GetRegion(d))
attachments := make([]map[string]interface{}, len(v.Attachments))
for i, attachment := range v.Attachments {
@ -207,7 +208,7 @@ func resourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{})
func resourceBlockStorageVolumeV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
blockStorageClient, err := config.blockStorageV2Client(d.Get("region").(string))
blockStorageClient, err := config.blockStorageV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -231,7 +232,7 @@ func resourceBlockStorageVolumeV2Update(d *schema.ResourceData, meta interface{}
func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
blockStorageClient, err := config.blockStorageV2Client(d.Get("region").(string))
blockStorageClient, err := config.blockStorageV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
}
@ -244,7 +245,7 @@ func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{}
// make sure this volume is detached from all instances before deleting
if len(v.Attachments) > 0 {
log.Printf("[DEBUG] detaching volumes")
if computeClient, err := config.computeV2Client(d.Get("region").(string)); err != nil {
if computeClient, err := config.computeV2Client(GetRegion(d)); err != nil {
return err
} else {
for _, volumeAttachment := range v.Attachments {

View File

@ -53,7 +53,7 @@ func resourceComputeFloatingIPV2() *schema.Resource {
func resourceComputeFloatingIPV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -74,7 +74,7 @@ func resourceComputeFloatingIPV2Create(d *schema.ResourceData, meta interface{})
func resourceComputeFloatingIPV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -90,13 +90,14 @@ func resourceComputeFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e
d.Set("instance_id", fip.InstanceID)
d.Set("address", fip.IP)
d.Set("fixed_ip", fip.FixedIP)
d.Set("region", GetRegion(d))
return nil
}
func resourceComputeFloatingIPV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}

View File

@ -328,7 +328,7 @@ func resourceComputeInstanceV2() *schema.Resource {
func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -475,7 +475,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e
// if volumes were specified, attach them after the instance has launched.
if v, ok := d.GetOk("volume"); ok {
vols := v.(*schema.Set).List()
if blockClient, err := config.blockStorageV1Client(d.Get("region").(string)); err != nil {
if blockClient, err := config.blockStorageV1Client(GetRegion(d)); err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
} else {
if err := attachVolumesToInstance(computeClient, blockClient, d.Id(), vols); err != nil {
@ -489,7 +489,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e
func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -576,7 +576,7 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err
func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -712,7 +712,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
oldAttachmentSet := oldAttachments.(*schema.Set).List()
log.Printf("[DEBUG] Attempting to detach the following volumes: %#v", oldAttachmentSet)
if blockClient, err := config.blockStorageV1Client(d.Get("region").(string)); err != nil {
if blockClient, err := config.blockStorageV1Client(GetRegion(d)); err != nil {
return err
} else {
if err := detachVolumesFromInstance(computeClient, blockClient, d.Id(), oldAttachmentSet); err != nil {
@ -722,7 +722,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
// for each new attachment, attach the volume
newAttachmentSet := newAttachments.(*schema.Set).List()
if blockClient, err := config.blockStorageV1Client(d.Get("region").(string)); err != nil {
if blockClient, err := config.blockStorageV1Client(GetRegion(d)); err != nil {
return err
} else {
if err := attachVolumesToInstance(computeClient, blockClient, d.Id(), newAttachmentSet); err != nil {
@ -799,7 +799,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -810,7 +810,7 @@ func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) e
volumeList := volumeSet.List()
if len(volumeList) > 0 {
log.Printf("[DEBUG] Attempting to detach the following volumes: %#v", volumeList)
if blockClient, err := config.blockStorageV1Client(d.Get("region").(string)); err != nil {
if blockClient, err := config.blockStorageV1Client(GetRegion(d)); err != nil {
return err
} else {
if err := detachVolumesFromInstance(computeClient, blockClient, d.Id(), volumeList); err != nil {

View File

@ -45,7 +45,7 @@ func resourceComputeKeypairV2() *schema.Resource {
func resourceComputeKeypairV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -71,7 +71,7 @@ func resourceComputeKeypairV2Create(d *schema.ResourceData, meta interface{}) er
func resourceComputeKeypairV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -83,13 +83,14 @@ func resourceComputeKeypairV2Read(d *schema.ResourceData, meta interface{}) erro
d.Set("name", kp.Name)
d.Set("public_key", kp.PublicKey)
d.Set("region", GetRegion(d))
return nil
}
func resourceComputeKeypairV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}

View File

@ -95,7 +95,7 @@ func resourceComputeSecGroupV2() *schema.Resource {
func resourceComputeSecGroupV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -133,7 +133,7 @@ func resourceComputeSecGroupV2Create(d *schema.ResourceData, meta interface{}) e
func resourceComputeSecGroupV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -153,12 +153,14 @@ func resourceComputeSecGroupV2Read(d *schema.ResourceData, meta interface{}) err
log.Printf("[DEBUG] rulesToMap(sg.Rules): %+v", rtm)
d.Set("rule", rtm)
d.Set("region", GetRegion(d))
return nil
}
func resourceComputeSecGroupV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -213,7 +215,7 @@ func resourceComputeSecGroupV2Update(d *schema.ResourceData, meta interface{}) e
func resourceComputeSecGroupV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}

View File

@ -47,7 +47,7 @@ func resourceComputeServerGroupV2() *schema.Resource {
func resourceComputeServerGroupV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -69,7 +69,7 @@ func resourceComputeServerGroupV2Create(d *schema.ResourceData, meta interface{}
func resourceComputeServerGroupV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -98,12 +98,14 @@ func resourceComputeServerGroupV2Read(d *schema.ResourceData, meta interface{})
}
d.Set("members", members)
d.Set("region", GetRegion(d))
return nil
}
func resourceComputeServerGroupV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}

View File

@ -53,7 +53,7 @@ func resourceComputeVolumeAttachV2() *schema.Resource {
func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -91,7 +91,7 @@ func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{
func resourceComputeVolumeAttachV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
@ -111,13 +111,14 @@ func resourceComputeVolumeAttachV2Read(d *schema.ResourceData, meta interface{})
d.Set("instance_id", attachment.ServerID)
d.Set("volume_id", attachment.VolumeID)
d.Set("device", attachment.Device)
d.Set("region", GetRegion(d))
return nil
}
func resourceComputeVolumeAttachV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(d.Get("region").(string))
computeClient, err := config.computeV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}

View File

@ -63,7 +63,7 @@ func resourceFWFirewallV1() *schema.Resource {
func resourceFWFirewallV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -110,7 +110,7 @@ func resourceFWFirewallV1Read(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Retrieve information about firewall: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -127,6 +127,7 @@ func resourceFWFirewallV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("policy_id", firewall.PolicyID)
d.Set("admin_state_up", firewall.AdminStateUp)
d.Set("tenant_id", firewall.TenantID)
d.Set("region", GetRegion(d))
return nil
}
@ -134,7 +135,7 @@ func resourceFWFirewallV1Read(d *schema.ResourceData, meta interface{}) error {
func resourceFWFirewallV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -183,7 +184,7 @@ func resourceFWFirewallV1Delete(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Destroy firewall: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -67,7 +67,7 @@ func resourceFWPolicyV1() *schema.Resource {
func resourceFWPolicyV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -118,7 +118,7 @@ func resourceFWPolicyV1Read(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Retrieve information about firewall policy: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -136,12 +136,14 @@ func resourceFWPolicyV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("audited", policy.Audited)
d.Set("tenant_id", policy.TenantID)
d.Set("rules", policy.Rules)
d.Set("region", GetRegion(d))
return nil
}
func resourceFWPolicyV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -183,7 +185,7 @@ func resourceFWPolicyV1Delete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Destroy firewall policy: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -86,7 +86,7 @@ func resourceFWRuleV1() *schema.Resource {
func resourceFWRuleV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -131,7 +131,7 @@ func resourceFWRuleV1Read(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Retrieve information about firewall rule: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -159,12 +159,14 @@ func resourceFWRuleV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("protocol", rule.Protocol)
}
d.Set("region", GetRegion(d))
return nil
}
func resourceFWRuleV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -236,7 +238,7 @@ func resourceFWRuleV1Delete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Destroy firewall rule: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -111,7 +111,7 @@ func resourceListenerV2() *schema.Resource {
func resourceListenerV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -168,7 +168,7 @@ func resourceListenerV2Create(d *schema.ResourceData, meta interface{}) error {
func resourceListenerV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -197,7 +197,7 @@ func resourceListenerV2Read(d *schema.ResourceData, meta interface{}) error {
func resourceListenerV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -243,7 +243,7 @@ func resourceListenerV2Update(d *schema.ResourceData, meta interface{}) error {
func resourceListenerV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -86,7 +86,7 @@ func resourceLoadBalancerV2() *schema.Resource {
func resourceLoadBalancerV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -133,7 +133,7 @@ func resourceLoadBalancerV2Create(d *schema.ResourceData, meta interface{}) erro
func resourceLoadBalancerV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -160,7 +160,7 @@ func resourceLoadBalancerV2Read(d *schema.ResourceData, meta interface{}) error
func resourceLoadBalancerV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -189,7 +189,7 @@ func resourceLoadBalancerV2Update(d *schema.ResourceData, meta interface{}) erro
func resourceLoadBalancerV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -66,7 +66,7 @@ func resourceLBMemberV1() *schema.Resource {
func resourceLBMemberV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -120,7 +120,7 @@ func resourceLBMemberV1Create(d *schema.ResourceData, meta interface{}) error {
func resourceLBMemberV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -137,13 +137,14 @@ func resourceLBMemberV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("port", m.ProtocolPort)
d.Set("weight", m.Weight)
d.Set("admin_state_up", m.AdminStateUp)
d.Set("region", GetRegion(d))
return nil
}
func resourceLBMemberV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -166,7 +167,7 @@ func resourceLBMemberV1Update(d *schema.ResourceData, meta interface{}) error {
func resourceLBMemberV1Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -94,7 +94,7 @@ func resourceMemberV2() *schema.Resource {
func resourceMemberV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -146,7 +146,7 @@ func resourceMemberV2Create(d *schema.ResourceData, meta interface{}) error {
func resourceMemberV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -172,7 +172,7 @@ func resourceMemberV2Read(d *schema.ResourceData, meta interface{}) error {
func resourceMemberV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -201,7 +201,7 @@ func resourceMemberV2Update(d *schema.ResourceData, meta interface{}) error {
func resourceMemberV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -83,7 +83,7 @@ func resourceLBMonitorV1() *schema.Resource {
func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -142,7 +142,7 @@ func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error {
func resourceLBMonitorV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -163,13 +163,14 @@ func resourceLBMonitorV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("http_method", m.HTTPMethod)
d.Set("expected_codes", m.ExpectedCodes)
d.Set("admin_state_up", strconv.FormatBool(m.AdminStateUp))
d.Set("region", GetRegion(d))
return nil
}
func resourceLBMonitorV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -206,7 +207,7 @@ func resourceLBMonitorV1Update(d *schema.ResourceData, meta interface{}) error {
func resourceLBMonitorV1Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -94,7 +94,7 @@ func resourceMonitorV2() *schema.Resource {
func resourceMonitorV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -144,7 +144,7 @@ func resourceMonitorV2Create(d *schema.ResourceData, meta interface{}) error {
func resourceMonitorV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -173,7 +173,7 @@ func resourceMonitorV2Read(d *schema.ResourceData, meta interface{}) error {
func resourceMonitorV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -217,7 +217,7 @@ func resourceMonitorV2Update(d *schema.ResourceData, meta interface{}) error {
func resourceMonitorV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -115,7 +115,7 @@ func resourceLBPoolV1() *schema.Resource {
func resourceLBPoolV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -185,7 +185,7 @@ func resourceLBPoolV1Create(d *schema.ResourceData, meta interface{}) error {
func resourceLBPoolV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -205,13 +205,14 @@ func resourceLBPoolV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("tenant_id", p.TenantID)
d.Set("monitor_ids", p.MonitorIDs)
d.Set("member_ids", p.MemberIDs)
d.Set("region", GetRegion(d))
return nil
}
func resourceLBPoolV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -308,7 +309,7 @@ func resourceLBPoolV1Update(d *schema.ResourceData, meta interface{}) error {
func resourceLBPoolV1Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -131,7 +131,7 @@ func resourcePoolV2() *schema.Resource {
func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -191,7 +191,7 @@ func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error {
func resourcePoolV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -217,7 +217,7 @@ func resourcePoolV2Read(d *schema.ResourceData, meta interface{}) error {
func resourcePoolV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -249,7 +249,7 @@ func resourcePoolV2Update(d *schema.ResourceData, meta interface{}) error {
func resourcePoolV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -105,7 +105,7 @@ func resourceLBVipV1() *schema.Resource {
func resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -161,7 +161,7 @@ func resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error {
func resourceLBVipV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -195,12 +195,14 @@ func resourceLBVipV1Read(d *schema.ResourceData, meta interface{}) error {
}
d.Set("persistence", persistence)
d.Set("region", GetRegion(d))
return nil
}
func resourceLBVipV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -280,7 +282,7 @@ func resourceLBVipV1Update(d *schema.ResourceData, meta interface{}) error {
func resourceLBVipV1Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -68,7 +68,7 @@ func resourceNetworkingFloatingIPV2() *schema.Resource {
func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack network client: %s", err)
}
@ -115,7 +115,7 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{})
func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack network client: %s", err)
}
@ -135,12 +135,14 @@ func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e
d.Set("pool", poolName)
d.Set("tenant_id", floatingIP.TenantID)
d.Set("region", GetRegion(d))
return nil
}
func resourceNetworkFloatingIPV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack network client: %s", err)
}
@ -164,7 +166,7 @@ func resourceNetworkFloatingIPV2Update(d *schema.ResourceData, meta interface{})
func resourceNetworkFloatingIPV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack network client: %s", err)
}
@ -189,7 +191,7 @@ func resourceNetworkFloatingIPV2Delete(d *schema.ResourceData, meta interface{})
func getNetworkID(d *schema.ResourceData, meta interface{}, networkName string) (string, error) {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return "", fmt.Errorf("Error creating OpenStack network client: %s", err)
}
@ -219,7 +221,7 @@ func getNetworkID(d *schema.ResourceData, meta interface{}, networkName string)
func getNetworkName(d *schema.ResourceData, meta interface{}, networkID string) (string, error) {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return "", fmt.Errorf("Error creating OpenStack network client: %s", err)
}

View File

@ -64,7 +64,7 @@ func resourceNetworkingNetworkV2() *schema.Resource {
func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -122,7 +122,7 @@ func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{})
func resourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -138,13 +138,14 @@ func resourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) e
d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp))
d.Set("shared", strconv.FormatBool(n.Shared))
d.Set("tenant_id", n.TenantID)
d.Set("region", GetRegion(d))
return nil
}
func resourceNetworkingNetworkV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -186,7 +187,7 @@ func resourceNetworkingNetworkV2Update(d *schema.ResourceData, meta interface{})
func resourceNetworkingNetworkV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -17,24 +17,8 @@ import (
)
func TestAccNetworkingV2Network_basic(t *testing.T) {
region := os.Getenv(OS_REGION_NAME)
var network networks.Network
var testAccNetworkingV2Network_basic = fmt.Sprintf(`
resource "openstack_networking_network_v2" "foo" {
region = "%s"
name = "network_1"
admin_state_up = "true"
}`, region)
var testAccNetworkingV2Network_update = fmt.Sprintf(`
resource "openstack_networking_network_v2" "foo" {
region = "%s"
name = "network_2"
admin_state_up = "true"
}`, region)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@ -239,16 +223,12 @@ func testAccCheckNetworkingV2NetworkExists(t *testing.T, n string, network *netw
var testAccNetworkingV2Network_basic = fmt.Sprintf(`
resource "openstack_networking_network_v2" "foo" {
region = "%s"
name = "network_1"
admin_state_up = "true"
}`,
OS_REGION_NAME)
}`)
var testAccNetworkingV2Network_update = fmt.Sprintf(`
resource "openstack_networking_network_v2" "foo" {
region = "%s"
name = "network_2"
admin_state_up = "true"
}`,
OS_REGION_NAME)
}`)

View File

@ -126,7 +126,7 @@ func resourceNetworkingPortV2() *schema.Resource {
func resourceNetworkingPortV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -173,7 +173,7 @@ func resourceNetworkingPortV2Create(d *schema.ResourceData, meta interface{}) er
func resourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -214,12 +214,14 @@ func resourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) erro
}
d.Set("allowed_address_pairs", pairs)
d.Set("region", GetRegion(d))
return nil
}
func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -266,7 +268,7 @@ func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) er
func resourceNetworkingPortV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -47,7 +47,7 @@ func resourceNetworkingRouterInterfaceV2() *schema.Resource {
func resourceNetworkingRouterInterfaceV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -84,7 +84,7 @@ func resourceNetworkingRouterInterfaceV2Create(d *schema.ResourceData, meta inte
func resourceNetworkingRouterInterfaceV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -106,7 +106,7 @@ func resourceNetworkingRouterInterfaceV2Read(d *schema.ResourceData, meta interf
func resourceNetworkingRouterInterfaceV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -52,7 +52,7 @@ func resourceNetworkingRouterRouteV2Create(d *schema.ResourceData, meta interfac
var nextHop string = d.Get("next_hop").(string)
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -110,7 +110,7 @@ func resourceNetworkingRouterRouteV2Read(d *schema.ResourceData, meta interface{
routerId := d.Get("router_id").(string)
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -153,7 +153,7 @@ func resourceNetworkingRouterRouteV2Delete(d *schema.ResourceData, meta interfac
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -65,7 +65,7 @@ func resourceNetworkingRouterV2() *schema.Resource {
func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -122,7 +122,7 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{})
func resourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -154,7 +154,7 @@ func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{})
defer osMutexKV.Unlock(routerId)
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -189,7 +189,7 @@ func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{})
func resourceNetworkingRouterV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -90,7 +90,7 @@ func resourceNetworkingSecGroupRuleV2() *schema.Resource {
func resourceNetworkingSecGroupRuleV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -147,7 +147,7 @@ func resourceNetworkingSecGroupRuleV2Read(d *schema.ResourceData, meta interface
log.Printf("[DEBUG] Retrieve information about security group rule: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -167,6 +167,8 @@ func resourceNetworkingSecGroupRuleV2Read(d *schema.ResourceData, meta interface
d.Set("remote_ip_prefix", security_group_rule.RemoteIPPrefix)
d.Set("security_group_id", security_group_rule.SecGroupID)
d.Set("tenant_id", security_group_rule.TenantID)
d.Set("region", GetRegion(d))
return nil
}
@ -174,7 +176,7 @@ func resourceNetworkingSecGroupRuleV2Delete(d *schema.ResourceData, meta interfa
log.Printf("[DEBUG] Destroy security group rule: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -52,7 +52,7 @@ func resourceNetworkingSecGroupV2() *schema.Resource {
func resourceNetworkingSecGroupV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -81,7 +81,7 @@ func resourceNetworkingSecGroupV2Read(d *schema.ResourceData, meta interface{})
log.Printf("[DEBUG] Retrieve information about security group: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -95,6 +95,8 @@ func resourceNetworkingSecGroupV2Read(d *schema.ResourceData, meta interface{})
d.Set("description", security_group.Description)
d.Set("tenant_id", security_group.TenantID)
d.Set("name", security_group.Name)
d.Set("region", GetRegion(d))
return nil
}
@ -102,7 +104,7 @@ func resourceNetworkingSecGroupV2Delete(d *schema.ResourceData, meta interface{}
log.Printf("[DEBUG] Destroy security group: %s", d.Id())
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -125,7 +125,7 @@ func resourceNetworkingSubnetV2() *schema.Resource {
func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -192,7 +192,7 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{})
func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -209,19 +209,31 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
d.Set("ip_version", s.IPVersion)
d.Set("name", s.Name)
d.Set("tenant_id", s.TenantID)
d.Set("allocation_pools", s.AllocationPools)
d.Set("gateway_ip", s.GatewayIP)
d.Set("dns_nameservers", s.DNSNameservers)
d.Set("host_routes", s.HostRoutes)
d.Set("enable_dhcp", s.EnableDHCP)
d.Set("network_id", s.NetworkID)
// Set the allocation_pools
var allocationPools []map[string]interface{}
for _, v := range s.AllocationPools {
pool := make(map[string]interface{})
pool["start"] = v.Start
pool["end"] = v.End
allocationPools = append(allocationPools, pool)
}
d.Set("allocation_pools", allocationPools)
d.Set("region", GetRegion(d))
return nil
}
func resourceNetworkingSubnetV2Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
@ -287,7 +299,7 @@ func resourceNetworkingSubnetV2Update(d *schema.ResourceData, meta interface{})
func resourceNetworkingSubnetV2Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

View File

@ -63,7 +63,7 @@ func resourceObjectStorageContainerV1() *schema.Resource {
func resourceObjectStorageContainerV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
objectStorageClient, err := config.objectStorageV1Client(d.Get("region").(string))
objectStorageClient, err := config.objectStorageV1Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack object storage client: %s", err)
}
@ -98,7 +98,7 @@ func resourceObjectStorageContainerV1Read(d *schema.ResourceData, meta interface
func resourceObjectStorageContainerV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
objectStorageClient, err := config.objectStorageV1Client(d.Get("region").(string))
objectStorageClient, err := config.objectStorageV1Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack object storage client: %s", err)
}
@ -125,7 +125,7 @@ func resourceObjectStorageContainerV1Update(d *schema.ResourceData, meta interfa
func resourceObjectStorageContainerV1Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
objectStorageClient, err := config.objectStorageV1Client(d.Get("region").(string))
objectStorageClient, err := config.objectStorageV1Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack object storage client: %s", err)
}

View File

@ -2,31 +2,12 @@ package openstack
import (
"fmt"
"os"
"github.com/gophercloud/gophercloud"
"github.com/hashicorp/terraform/helper/schema"
)
// CheckDeleted checks the error to see if it's a 404 (Not Found) and, if so,
// sets the resource ID to the empty string instead of throwing an error.
func CheckDeleted(d *schema.ResourceData, err error, msg string) error {
if _, ok := err.(gophercloud.ErrDefault404); ok {
d.SetId("")
return nil
}
return fmt.Errorf("%s: %s", msg, err)
}
// MapValueSpecs converts ResourceData into a map
func MapValueSpecs(d *schema.ResourceData) map[string]string {
m := make(map[string]string)
for key, val := range d.Get("value_specs").(map[string]interface{}) {
m[key] = val.(string)
}
return m
}
// BuildRequest takes an opts struct and builds a request body for
// Gophercloud to execute
func BuildRequest(opts interface{}, parent string) (map[string]interface{}, error) {
@ -44,3 +25,36 @@ func BuildRequest(opts interface{}, parent string) (map[string]interface{}, erro
return map[string]interface{}{parent: b}, nil
}
// CheckDeleted checks the error to see if it's a 404 (Not Found) and, if so,
// sets the resource ID to the empty string instead of throwing an error.
func CheckDeleted(d *schema.ResourceData, err error, msg string) error {
if _, ok := err.(gophercloud.ErrDefault404); ok {
d.SetId("")
return nil
}
return fmt.Errorf("%s: %s", msg, err)
}
// GetRegion returns the region from either d.Get("region") or OS_REGION_NAME
func GetRegion(d *schema.ResourceData) string {
if v, ok := d.GetOk("region"); ok {
return v.(string)
}
if v := os.Getenv("OS_REGION_NAME"); v != "" {
return v
}
return ""
}
// MapValueSpecs converts ResourceData into a map
func MapValueSpecs(d *schema.ResourceData) map[string]string {
m := make(map[string]string)
for key, val := range d.Get("value_specs").(map[string]interface{}) {
m[key] = val.(string)
}
return m
}