forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_arm_data_lake_analytics_firewall_rule.go
153 lines (123 loc) · 4.93 KB
/
resource_arm_data_lake_analytics_firewall_rule.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package azurerm
import (
"fmt"
"log"
"github.com/Azure/azure-sdk-for-go/services/datalake/analytics/mgmt/2016-11-01/account"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func resourceArmDataLakeAnalyticsFirewallRule() *schema.Resource {
return &schema.Resource{
Create: resourceArmDateLakeAnalyticsFirewallRuleCreateUpdate,
Read: resourceArmDateLakeAnalyticsFirewallRuleRead,
Update: resourceArmDateLakeAnalyticsFirewallRuleCreateUpdate,
Delete: resourceArmDateLakeAnalyticsFirewallRuleDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateDataLakeFirewallRuleName(),
},
"account_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateDataLakeAccountName(),
},
"resource_group_name": resourceGroupNameSchema(),
"start_ip_address": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.IPv4Address,
},
"end_ip_address": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.IPv4Address,
},
},
}
}
func resourceArmDateLakeAnalyticsFirewallRuleCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).dataLakeAnalyticsFirewallRulesClient
ctx := meta.(*ArmClient).StopContext
name := d.Get("name").(string)
accountName := d.Get("account_name").(string)
resourceGroup := d.Get("resource_group_name").(string)
startIPAddress := d.Get("start_ip_address").(string)
endIPAddress := d.Get("end_ip_address").(string)
log.Printf("[INFO] preparing arguments for Date Lake Analytics Firewall Rule creation %q (Resource Group %q)", name, resourceGroup)
dateLakeStore := account.CreateOrUpdateFirewallRuleParameters{
CreateOrUpdateFirewallRuleProperties: &account.CreateOrUpdateFirewallRuleProperties{
StartIPAddress: utils.String(startIPAddress),
EndIPAddress: utils.String(endIPAddress),
},
}
_, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, dateLakeStore)
if err != nil {
return fmt.Errorf("Error issuing create request for Data Lake Analytics %q (Resource Group %q): %+v", name, resourceGroup, err)
}
read, err := client.Get(ctx, resourceGroup, accountName, name)
if err != nil {
return fmt.Errorf("Error retrieving Data Lake Analytics Firewall Rule %q (Account %q / Resource Group %q): %+v", name, accountName, resourceGroup, err)
}
if read.ID == nil {
return fmt.Errorf("Cannot read Data Lake Analytics %q (Account %q / Resource Group %q) ID", name, accountName, resourceGroup)
}
d.SetId(*read.ID)
return resourceArmDateLakeAnalyticsFirewallRuleRead(d, meta)
}
func resourceArmDateLakeAnalyticsFirewallRuleRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).dataLakeAnalyticsFirewallRulesClient
ctx := meta.(*ArmClient).StopContext
id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}
resourceGroup := id.ResourceGroup
accountName := id.Path["accounts"]
name := id.Path["firewallRules"]
resp, err := client.Get(ctx, resourceGroup, accountName, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[WARN] Data Lake Analytics Firewall Rule %q was not found (Account %q / Resource Group %q)", name, accountName, resourceGroup)
d.SetId("")
return nil
}
return fmt.Errorf("Error making Read request on Azure Data Lake Analytics Firewall Rule %q (Account %q / Resource Group %q): %+v", name, accountName, resourceGroup, err)
}
d.Set("name", name)
d.Set("account_name", accountName)
d.Set("resource_group_name", resourceGroup)
if props := resp.FirewallRuleProperties; props != nil {
d.Set("start_ip_address", props.StartIPAddress)
d.Set("end_ip_address", props.EndIPAddress)
}
return nil
}
func resourceArmDateLakeAnalyticsFirewallRuleDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).dataLakeAnalyticsFirewallRulesClient
ctx := meta.(*ArmClient).StopContext
id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}
resourceGroup := id.ResourceGroup
accountName := id.Path["accounts"]
name := id.Path["firewallRules"]
resp, err := client.Delete(ctx, resourceGroup, accountName, name)
if err != nil {
if response.WasNotFound(resp.Response) {
return nil
}
return fmt.Errorf("Error issuing delete request for Data Lake Analytics Firewall Rule %q (Account %q / Resource Group %q): %+v", name, accountName, resourceGroup, err)
}
return nil
}