-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
resource_arm_logic_app_action_custom.go
127 lines (103 loc) · 3.4 KB
/
resource_arm_logic_app_action_custom.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package logic
import (
"encoding/json"
"fmt"
"log"
"time"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/structure"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)
func resourceArmLogicAppActionCustom() *schema.Resource {
return &schema.Resource{
Create: resourceArmLogicAppActionCustomCreateUpdate,
Read: resourceArmLogicAppActionCustomRead,
Update: resourceArmLogicAppActionCustomCreateUpdate,
Delete: resourceArmLogicAppActionCustomDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"logic_app_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateResourceID,
},
"body": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: structure.SuppressJsonDiff,
},
},
}
}
func resourceArmLogicAppActionCustomCreateUpdate(d *schema.ResourceData, meta interface{}) error {
logicAppId := d.Get("logic_app_id").(string)
name := d.Get("name").(string)
bodyRaw := d.Get("body").(string)
var body map[string]interface{}
if err := json.Unmarshal([]byte(bodyRaw), &body); err != nil {
return fmt.Errorf("Error unmarshalling JSON for Custom Action %q: %+v", name, err)
}
if err := resourceLogicAppActionUpdate(d, meta, logicAppId, name, body, "azurerm_logic_app_action_custom"); err != nil {
return err
}
return resourceArmLogicAppActionCustomRead(d, meta)
}
func resourceArmLogicAppActionCustomRead(d *schema.ResourceData, meta interface{}) error {
id, err := azure.ParseAzureResourceID(d.Id())
if err != nil {
return err
}
resourceGroup := id.ResourceGroup
logicAppName := id.Path["workflows"]
name := id.Path["actions"]
t, app, err := retrieveLogicAppAction(d, meta, resourceGroup, logicAppName, name)
if err != nil {
return err
}
if t == nil {
log.Printf("[DEBUG] Logic App %q (Resource Group %q) does not contain Action %q - removing from state", logicAppName, resourceGroup, name)
d.SetId("")
return nil
}
action := *t
d.Set("name", name)
d.Set("logic_app_id", app.ID)
body, err := json.Marshal(action)
if err != nil {
return fmt.Errorf("Error serializing `body` for Action %q: %+v", name, err)
}
if err := d.Set("body", string(body)); err != nil {
return fmt.Errorf("Error setting `body` for Action %q: %+v", name, err)
}
return nil
}
func resourceArmLogicAppActionCustomDelete(d *schema.ResourceData, meta interface{}) error {
id, err := azure.ParseAzureResourceID(d.Id())
if err != nil {
return err
}
resourceGroup := id.ResourceGroup
logicAppName := id.Path["workflows"]
name := id.Path["actions"]
err = resourceLogicAppActionRemove(d, meta, resourceGroup, logicAppName, name)
if err != nil {
return fmt.Errorf("Error removing Action %q from Logic App %q (Resource Group %q): %+v", name, logicAppName, resourceGroup, err)
}
return nil
}