-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/azurerm: add account_kind and access_tier to storage_account #9408
Merged
stack72
merged 1 commit into
hashicorp:master
from
BedeGaming:azurerm-storage-account-tier
Oct 24, 2016
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,15 @@ import ( | |
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/signalwrapper" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
) | ||
|
||
// The KeySource of storage.Encryption appears to require this value | ||
// for Encryption services to work | ||
var storageAccountEncryptionSource = "Microsoft.Storage" | ||
|
||
const blobStorageAccountDefaultAccessTier = "Hot" | ||
|
||
func resourceArmStorageAccount() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmStorageAccountCreate, | ||
|
@@ -50,12 +53,34 @@ func resourceArmStorageAccount() *schema.Resource { | |
StateFunc: azureRMNormalizeLocation, | ||
}, | ||
|
||
"account_kind": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(storage.Storage), | ||
string(storage.BlobStorage), | ||
}, true), | ||
Default: string(storage.Storage), | ||
}, | ||
|
||
"account_type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validateArmStorageAccountType, | ||
}, | ||
|
||
// Only valid for BlobStorage accounts, defaults to "Hot" in create function | ||
"access_tier": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(storage.Cool), | ||
string(storage.Hot), | ||
}, true), | ||
}, | ||
|
||
"enable_blob_encryption": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
|
@@ -128,7 +153,9 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e | |
|
||
resourceGroupName := d.Get("resource_group_name").(string) | ||
storageAccountName := d.Get("name").(string) | ||
accountKind := d.Get("account_kind").(string) | ||
accountType := d.Get("account_type").(string) | ||
|
||
location := d.Get("location").(string) | ||
tags := d.Get("tags").(map[string]interface{}) | ||
enableBlobEncryption := d.Get("enable_blob_encryption").(bool) | ||
|
@@ -141,6 +168,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e | |
Location: &location, | ||
Sku: &sku, | ||
Tags: expandTags(tags), | ||
Kind: storage.Kind(accountKind), | ||
Properties: &storage.AccountPropertiesCreateParameters{ | ||
Encryption: &storage.Encryption{ | ||
Services: &storage.EncryptionServices{ | ||
|
@@ -153,6 +181,17 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e | |
}, | ||
} | ||
|
||
// AccessTier is only valid for BlobStorage accounts | ||
if accountKind == string(storage.BlobStorage) { | ||
accessTier, ok := d.GetOk("access_tier") | ||
if !ok { | ||
// default to "Hot" | ||
accessTier = blobStorageAccountDefaultAccessTier | ||
} | ||
|
||
opts.Properties.AccessTier = storage.AccessTier(accessTier.(string)) | ||
} | ||
|
||
// Create the storage account. We wrap this so that it is cancellable | ||
// with a Ctrl-C since this can take a LONG time. | ||
wrap := signalwrapper.Run(func(cancelCh <-chan struct{}) error { | ||
|
@@ -247,6 +286,22 @@ func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) e | |
d.SetPartial("account_type") | ||
} | ||
|
||
if d.HasChange("access_tier") { | ||
accessTier := d.Get("access_tier").(string) | ||
|
||
opts := storage.AccountUpdateParameters{ | ||
Properties: &storage.AccountPropertiesUpdateParameters{ | ||
AccessTier: storage.AccessTier(accessTier), | ||
}, | ||
} | ||
_, err := client.Update(resourceGroupName, storageAccountName, opts) | ||
if err != nil { | ||
return fmt.Errorf("Error updating Azure Storage Account access_tier %q: %s", storageAccountName, err) | ||
} | ||
|
||
d.SetPartial("access_tier") | ||
} | ||
|
||
if d.HasChange("tags") { | ||
tags := d.Get("tags").(map[string]interface{}) | ||
|
||
|
@@ -317,10 +372,15 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err | |
d.Set("primary_access_key", accessKeys[0].Value) | ||
d.Set("secondary_access_key", accessKeys[1].Value) | ||
d.Set("location", resp.Location) | ||
d.Set("account_kind", resp.Kind) | ||
d.Set("account_type", resp.Sku.Name) | ||
d.Set("primary_location", resp.Properties.PrimaryLocation) | ||
d.Set("secondary_location", resp.Properties.SecondaryLocation) | ||
|
||
if resp.Properties.AccessTier != "" { | ||
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. If access tier is computed: true, is there ever any way this can be nil? |
||
d.Set("access_tier", resp.Properties.AccessTier) | ||
} | ||
|
||
if resp.Properties.PrimaryEndpoints != nil { | ||
d.Set("primary_blob_endpoint", resp.Properties.PrimaryEndpoints.Blob) | ||
d.Set("primary_queue_endpoint", resp.Properties.PrimaryEndpoints.Queue) | ||
|
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
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.
I think we should add the default as part of the scheme declaration rather than defaulting in code
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.
The issue I faced is that accessTier can only be specified on requests for BlobStorage accounts, using the Default parameter meant it would be set for all types