-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_data_lake_firewall_rule
- Loading branch information
1 parent
9c1edb0
commit fc73946
Showing
9 changed files
with
510 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/datalake/store/mgmt/2016-11-01/account" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"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 resourceArmDataLakeStoreFirewallRule() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmDateLakeStoreAccountFirewallRuleCreateUpdate, | ||
Read: resourceArmDateLakeStoreAccountFirewallRuleRead, | ||
Update: resourceArmDateLakeStoreAccountFirewallRuleCreateUpdate, | ||
Delete: resourceArmDateLakeStoreAccountFirewallRuleDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"account_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameSchema(), | ||
|
||
"start_ip_address": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validate.IPv4OrIPv6Address, | ||
}, | ||
|
||
"end_ip_address": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validate.IPv4OrIPv6Address, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmDateLakeStoreAccountFirewallRuleCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).dataLakeStoreFirewallRulesClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
log.Printf("[INFO] preparing arguments for Date Lake Store Firewall Rule creation.") | ||
|
||
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) | ||
|
||
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 Store %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 Store Firewall Rule %q (Account %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) | ||
} | ||
if read.ID == nil { | ||
return fmt.Errorf("Cannot read Data Lake Store %q (Account %q / Resource Group %q) ID", name, accountName, resourceGroup) | ||
} | ||
|
||
d.SetId(*read.ID) | ||
|
||
return resourceArmDateLakeStoreAccountFirewallRuleRead(d, meta) | ||
} | ||
|
||
func resourceArmDateLakeStoreAccountFirewallRuleRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).dataLakeStoreFirewallRulesClient | ||
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 Store 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 Store 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 resourceArmDateLakeStoreAccountFirewallRuleDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).dataLakeStoreFirewallRulesClient | ||
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 Store Firewall Rule %q (Account %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.