forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 7
/
resource_azure_storage_queue.go
103 lines (89 loc) · 2.91 KB
/
resource_azure_storage_queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package azure
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
)
// resourceAzureStorageQueue returns the *schema.Resource associated
// to a storage queue on Azure.
func resourceAzureStorageQueue() *schema.Resource {
return &schema.Resource{
Create: resourceAzureStorageQueueCreate,
Read: resourceAzureStorageQueueRead,
Delete: resourceAzureStorageQueueDelete,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: parameterDescriptions["name"],
},
"storage_service_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: parameterDescriptions["storage_service_name"],
},
},
}
}
// resourceAzureStorageQueueCreate does all the necessary API calls to
// create a storage queue on Azure.
func resourceAzureStorageQueueCreate(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client)
storServName := d.Get("storage_service_name").(string)
queueClient, err := azureClient.getStorageServiceQueueClient(storServName)
if err != nil {
return err
}
// create the queue:
log.Println("Sending Storage Queue creation request to Azure.")
name := d.Get("name").(string)
err = queueClient.CreateQueue(name)
if err != nil {
return fmt.Errorf("Error creation Storage Queue on Azure: %s", err)
}
d.SetId(name)
return nil
}
// resourceAzureStorageQueueRead does all the necessary API calls to
// read the state of the storage queue off Azure.
func resourceAzureStorageQueueRead(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client)
storServName := d.Get("storage_service_name").(string)
queueClient, err := azureClient.getStorageServiceQueueClient(storServName)
if err != nil {
return err
}
// check for queue's existence:
log.Println("[INFO] Sending Storage Queue existence query to Azure.")
name := d.Get("name").(string)
exists, err := queueClient.QueueExists(name)
if err != nil {
return fmt.Errorf("Error checking for Storage Queue existence: %s", err)
}
// If the queue has been deleted in the meantime;
// untrack the resource from the schema.
if !exists {
d.SetId("")
}
return nil
}
// resourceAzureStorageQueueDelete does all the necessary API calls to
// delete the storage queue off Azure.
func resourceAzureStorageQueueDelete(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client)
storServName := d.Get("storage_service_name").(string)
queueClient, err := azureClient.getStorageServiceQueueClient(storServName)
if err != nil {
return err
}
// issue the deletion of the storage queue:
log.Println("[INFO] Sending Storage Queue deletion request to Azure.")
name := d.Get("name").(string)
err = queueClient.DeleteQueue(name)
if err != nil {
return fmt.Errorf("Error deleting Storage queue off Azure: %s", err)
}
return nil
}