object storage container v1 ops
This commit is contained in:
parent
08672e697e
commit
43564d1c5c
|
@ -53,3 +53,9 @@ func (c *Config) networkingV2Client(region string) (*gophercloud.ServiceClient,
|
|||
Region: region,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Config) objectStorageV1Client(region string) (*gophercloud.ServiceClient, error) {
|
||||
return openstack.NewObjectStorageV1(c.osClient, gophercloud.EndpointOpts{
|
||||
Region: region,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -59,14 +59,15 @@ func Provider() terraform.ResourceProvider {
|
|||
},
|
||||
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
"openstack_compute_instance_v2": resourceComputeInstanceV2(),
|
||||
"openstack_compute_keypair_v2": resourceComputeKeypairV2(),
|
||||
"openstack_compute_secgroup_v2": resourceComputeSecGroupV2(),
|
||||
"openstack_lb_monitor_v1": resourceLBMonitorV1(),
|
||||
"openstack_lb_pool_v1": resourceLBPoolV1(),
|
||||
"openstack_lb_vip_v1": resourceLBVipV1(),
|
||||
"openstack_networking_network_v2": resourceNetworkingNetworkV2(),
|
||||
"openstack_networking_subnet_v2": resourceNetworkingSubnetV2(),
|
||||
"openstack_compute_instance_v2": resourceComputeInstanceV2(),
|
||||
"openstack_compute_keypair_v2": resourceComputeKeypairV2(),
|
||||
"openstack_compute_secgroup_v2": resourceComputeSecGroupV2(),
|
||||
"openstack_lb_monitor_v1": resourceLBMonitorV1(),
|
||||
"openstack_lb_pool_v1": resourceLBPoolV1(),
|
||||
"openstack_lb_vip_v1": resourceLBVipV1(),
|
||||
"openstack_networking_network_v2": resourceNetworkingNetworkV2(),
|
||||
"openstack_networking_subnet_v2": resourceNetworkingSubnetV2(),
|
||||
"openstack_objectstorage_container_v1": resourceObjectStorageContainerV1(),
|
||||
},
|
||||
|
||||
ConfigureFunc: configureProvider,
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
package openstack
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers"
|
||||
)
|
||||
|
||||
func resourceObjectStorageContainerV1() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceObjectStorageContainerV1Create,
|
||||
Read: resourceObjectStorageContainerV1Read,
|
||||
Update: resourceObjectStorageContainerV1Update,
|
||||
Delete: resourceObjectStorageContainerV1Delete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
"container_read": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
"container_sync_to": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
"container_sync_key": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
"container_write": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
"content_type": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
"metadata": &schema.Schema{
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceObjectStorageContainerV1Create(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
objectStorgeClient, err := config.objectStorageV1Client(d.Get("region").(string))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack object storage client: %s", err)
|
||||
}
|
||||
|
||||
cn := d.Get("name").(string)
|
||||
|
||||
createOpts := &containers.CreateOpts{
|
||||
ContainerRead: d.Get("container_read").(string),
|
||||
ContainerSyncTo: d.Get("container_sync_to").(string),
|
||||
ContainerSyncKey: d.Get("container_sync_key").(string),
|
||||
ContainerWrite: d.Get("container_write").(string),
|
||||
ContentType: d.Get("content_type").(string),
|
||||
Metadata: resourceContainerMetadataV2(d),
|
||||
}
|
||||
|
||||
log.Printf("[INFO] Requesting container creation")
|
||||
_, err = containers.Create(objectStorgeClient, cn, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack container: %s", err)
|
||||
}
|
||||
log.Printf("[INFO] Container ID: %s", cn)
|
||||
|
||||
// Store the ID now
|
||||
d.SetId(cn)
|
||||
|
||||
return resourceObjectStorageContainerV1Read(d, meta)
|
||||
}
|
||||
|
||||
func resourceObjectStorageContainerV1Read(d *schema.ResourceData, meta interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceObjectStorageContainerV1Update(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
objectStorgeClient, err := config.objectStorageV1Client(d.Get("region").(string))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack object storage client: %s", err)
|
||||
}
|
||||
|
||||
updateOpts := containers.UpdateOpts{
|
||||
ContainerRead: d.Get("container_read").(string),
|
||||
ContainerSyncTo: d.Get("container_sync_to").(string),
|
||||
ContainerSyncKey: d.Get("container_sync_key").(string),
|
||||
ContainerWrite: d.Get("container_write").(string),
|
||||
ContentType: d.Get("content_type").(string),
|
||||
}
|
||||
|
||||
_, err = containers.Update(objectStorgeClient, d.Id(), updateOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack container: %s", err)
|
||||
}
|
||||
|
||||
if d.HasChange("metadata") {
|
||||
updateOpts.Metadata = resourceContainerMetadataV2(d)
|
||||
}
|
||||
|
||||
return resourceObjectStorageContainerV1Read(d, meta)
|
||||
}
|
||||
|
||||
func resourceObjectStorageContainerV1Delete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
objectStorgeClient, err := config.objectStorageV1Client(d.Get("region").(string))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack object storage client: %s", err)
|
||||
}
|
||||
|
||||
_, err = containers.Delete(objectStorgeClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack container: %s", err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceContainerMetadataV2(d *schema.ResourceData) map[string]string {
|
||||
m := make(map[string]string)
|
||||
for key, val := range d.Get("metadata").(map[string]interface{}) {
|
||||
m[key] = val.(string)
|
||||
}
|
||||
return m
|
||||
}
|
Loading…
Reference in New Issue