Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/remote-state/azure/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func New() backend.Backend {
DefaultFunc: schema.EnvDefaultFunc("ARM_SAS_TOKEN", ""),
},

"versioning": {
Comment thread
evenh marked this conversation as resolved.
Outdated
Type: schema.TypeBool,
Optional: true,
Description: "Enable/Disable automatic blob snapshotting",
DefaultFunc: schema.EnvDefaultFunc("ARM_VERSIONING", false),
Comment thread
evenh marked this conversation as resolved.
Outdated
},

"resource_group_name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -150,6 +157,7 @@ type Backend struct {
containerName string
keyName string
accountName string
versioning bool
Comment thread
evenh marked this conversation as resolved.
Outdated
}

type BackendConfig struct {
Expand Down Expand Up @@ -180,6 +188,7 @@ func (b *Backend) configure(ctx context.Context) error {
b.containerName = data.Get("container_name").(string)
b.accountName = data.Get("storage_account_name").(string)
b.keyName = data.Get("key").(string)
b.versioning = data.Get("versioning").(bool)
Comment thread
evenh marked this conversation as resolved.
Outdated

// support for previously deprecated fields
clientId := valueFromDeprecatedField(data, "client_id", "arm_client_id")
Expand Down
1 change: 1 addition & 0 deletions backend/remote-state/azure/backend_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (b *Backend) StateMgr(name string) (state.State, error) {
containerName: b.containerName,
keyName: b.path(name),
accountName: b.accountName,
versioning: b.versioning,
Comment thread
evenh marked this conversation as resolved.
Outdated
}

stateMgr := &remote.State{Client: client}
Expand Down
4 changes: 4 additions & 0 deletions backend/remote-state/azure/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestBackendConfig(t *testing.T) {
"storage_account_name": "tfaccount",
"container_name": "tfcontainer",
"key": "state",
"versioning": false,
Comment thread
evenh marked this conversation as resolved.
Outdated
// Access Key must be Base64
"access_key": "QUNDRVNTX0tFWQ0K",
}
Expand All @@ -33,6 +34,9 @@ func TestBackendConfig(t *testing.T) {
if b.keyName != "state" {
t.Fatalf("Incorrect keyName was populated")
}
if b.versioning != false {
Comment thread
evenh marked this conversation as resolved.
Outdated
t.Fatalf("Incorrect versioning was populated")
Comment thread
evenh marked this conversation as resolved.
Outdated
}
}

func TestBackendAccessKeyBasic(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions backend/remote-state/azure/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"log"

"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform/state"
Expand All @@ -24,6 +26,7 @@ type RemoteClient struct {
containerName string
keyName string
leaseID string
versioning bool
Comment thread
evenh marked this conversation as resolved.
Outdated
}

func (c *RemoteClient) Get() (*remote.Payload, error) {
Expand Down Expand Up @@ -67,6 +70,17 @@ func (c *RemoteClient) Put(data []byte) error {
}

ctx := context.TODO()

if c.versioning {
Comment thread
evenh marked this conversation as resolved.
Outdated
snapshotInput := blobs.SnapshotInput{LeaseID: options.LeaseID}
Comment thread
evenh marked this conversation as resolved.

if _, err := c.giovanniBlobClient.Snapshot(ctx, c.accountName, c.containerName, c.keyName, snapshotInput); err != nil {
Comment thread
evenh marked this conversation as resolved.
return err
Comment thread
evenh marked this conversation as resolved.
Outdated
}

log.Print("[DEBUG] Created blob snapshot")
}

blob, err := c.giovanniBlobClient.GetProperties(ctx, c.accountName, c.containerName, c.keyName, getOptions)
if err != nil {
if blob.StatusCode != 404 {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/backends/types/azurerm.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ The following configuration options are supported:

* `environment` - (Optional) The Azure Environment which should be used. This can also be sourced from the `ARM_ENVIRONMENT` environment variable. Possible values are `public`, `china`, `german`, `stack` and `usgovernment`. Defaults to `public`.

* `versioning` - (Optional) Should versioning for state file be used - default `false`. This value can also be sourced from the `ARM_VERSIONING` environment variable.
Comment thread
evenh marked this conversation as resolved.
Outdated

* `endpoint` - (Optional) The Custom Endpoint for Azure Resource Manager. This can also be sourced from the `ARM_ENDPOINT` environment variable.

~> **NOTE:** An `endpoint` should only be configured when using Azure Stack.
Expand Down