-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new resources: azurerm_data_lake_analytics_account & azurerm_data_lake_analytics_firewall_rule #1618
Merged
Merged
new resources: azurerm_data_lake_analytics_account & azurerm_data_lake_analytics_firewall_rule #1618
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package azure | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
) | ||
|
||
//store and analytic account names are the same | ||
func ValidateDataLakeAccountName() schema.SchemaValidateFunc { | ||
return validation.StringMatch( | ||
regexp.MustCompile(`\A([a-z0-9]{3,24})\z`), | ||
"Name can only consist of lowercase letters and numbers and must be between 3 and 24 characters long", | ||
) | ||
} | ||
|
||
func ValidateDataLakeFirewallRuleName() schema.SchemaValidateFunc { | ||
return validation.StringMatch( | ||
regexp.MustCompile(`\A([-_a-zA-Z0-9]{3,50})\z`), | ||
"Name can only consist of letters, numbers, underscores and hyphens and must be between 3 and 50 characters long", | ||
) | ||
} |
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,221 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Azure/azure-sdk-for-go/services/datalake/analytics/mgmt/2016-11-01/account" | ||
"log" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
func resourceArmDataLakeAnalyticsAccount() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmDateLakeAnalyticsAccountCreate, | ||
Read: resourceArmDateLakeAnalyticsAccountRead, | ||
Update: resourceArmDateLakeAnalyticsAccountUpdate, | ||
Delete: resourceArmDateLakeAnalyticsAccountDelete, | ||
|
||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: azure.ValidateDataLakeAccountName(), | ||
}, | ||
|
||
"location": locationSchema(), | ||
|
||
"resource_group_name": resourceGroupNameSchema(), | ||
|
||
"tier": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: string(account.Consumption), | ||
DiffSuppressFunc: suppress.CaseDifference, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(account.Consumption), | ||
string(account.Commitment100000AUHours), | ||
string(account.Commitment10000AUHours), | ||
string(account.Commitment1000AUHours), | ||
string(account.Commitment100AUHours), | ||
string(account.Commitment500000AUHours), | ||
string(account.Commitment50000AUHours), | ||
string(account.Commitment5000AUHours), | ||
string(account.Commitment500AUHours), | ||
}, true), | ||
}, | ||
|
||
"default_store_account_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: azure.ValidateDataLakeAccountName(), | ||
}, | ||
|
||
"tags": tagsSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmDateLakeAnalyticsAccountCreate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).dataLakeAnalyticsAccountClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
log.Printf("[INFO] preparing arguments for Azure ARM Date Lake Store creation.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add the name to this log? |
||
|
||
name := d.Get("name").(string) | ||
location := azureRMNormalizeLocation(d.Get("location").(string)) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
storeAccountName := d.Get("default_store_account_name").(string) | ||
tier := d.Get("tier").(string) | ||
tags := d.Get("tags").(map[string]interface{}) | ||
|
||
dateLakeAnalyticsAccount := account.CreateDataLakeAnalyticsAccountParameters{ | ||
Location: &location, | ||
Tags: expandTags(tags), | ||
CreateDataLakeAnalyticsAccountProperties: &account.CreateDataLakeAnalyticsAccountProperties{ | ||
NewTier: account.TierType(tier), | ||
DefaultDataLakeStoreAccount: &storeAccountName, | ||
DataLakeStoreAccounts: &[]account.AddDataLakeStoreWithAccountParameters{ | ||
{ | ||
Name: &storeAccountName, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
future, err := client.Create(ctx, resourceGroup, name, dateLakeAnalyticsAccount) | ||
if err != nil { | ||
return fmt.Errorf("Error issuing create request for Data Lake Analytics Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
err = future.WaitForCompletion(ctx, client.Client) | ||
if err != nil { | ||
return fmt.Errorf("Error creating Data Lake Analytics Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
read, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving Data Lake Analytics Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
if read.ID == nil { | ||
return fmt.Errorf("Cannot read Data Lake Analytics Account %s (resource group %s) ID", name, resourceGroup) | ||
} | ||
|
||
d.SetId(*read.ID) | ||
|
||
return resourceArmDateLakeAnalyticsAccountRead(d, meta) | ||
} | ||
|
||
func resourceArmDateLakeAnalyticsAccountUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).dataLakeAnalyticsAccountClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
storeAccountName := d.Get("default_store_account_name").(string) | ||
newTier := d.Get("tier").(string) | ||
newTags := d.Get("tags").(map[string]interface{}) | ||
|
||
props := &account.UpdateDataLakeAnalyticsAccountParameters{ | ||
Tags: expandTags(newTags), | ||
UpdateDataLakeAnalyticsAccountProperties: &account.UpdateDataLakeAnalyticsAccountProperties{ | ||
NewTier: account.TierType(newTier), | ||
DataLakeStoreAccounts: &[]account.UpdateDataLakeStoreWithAccountParameters{ | ||
{ | ||
Name: &storeAccountName, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
future, err := client.Update(ctx, resourceGroup, name, props) | ||
if err != nil { | ||
return fmt.Errorf("Error issuing update request for Data Lake Analytics Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
err = future.WaitForCompletion(ctx, client.Client) | ||
if err != nil { | ||
return fmt.Errorf("Error waiting for the update of Data Lake Analytics Account %q (Resource Group %q) to commplete: %+v", name, resourceGroup, err) | ||
} | ||
|
||
return resourceArmDateLakeAnalyticsAccountRead(d, meta) | ||
} | ||
|
||
func resourceArmDateLakeAnalyticsAccountRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).dataLakeAnalyticsAccountClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
name := id.Path["accounts"] | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
log.Printf("[WARN] DataLakeAnalyticsAccountAccount '%s' was not found (resource group '%s')", name, resourceGroup) | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("Error making Read request on Azure Data Lake Analytics Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resourceGroup) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azureRMNormalizeLocation(*location)) | ||
} | ||
|
||
if properties := resp.DataLakeAnalyticsAccountProperties; properties != nil { | ||
d.Set("tier", string(properties.CurrentTier)) | ||
d.Set("default_store_account_name", properties.DefaultDataLakeStoreAccount) | ||
} | ||
|
||
flattenAndSetTags(d, resp.Tags) | ||
|
||
return nil | ||
} | ||
|
||
func resourceArmDateLakeAnalyticsAccountDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).dataLakeAnalyticsAccountClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
name := id.Path["accounts"] | ||
future, err := client.Delete(ctx, resourceGroup, name) | ||
if err != nil { | ||
if response.WasNotFound(future.Response()) { | ||
return nil | ||
} | ||
return fmt.Errorf("Error issuing delete request for Data Lake Analytics Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
err = future.WaitForCompletion(ctx, client.Client) | ||
if err != nil { | ||
if response.WasNotFound(future.Response()) { | ||
return nil | ||
} | ||
return fmt.Errorf("Error deleting Data Lake Analytics Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these imports probably need some minor reordering.