From cd7bfba1416f1fd2d8b04671735ab7e236d918e8 Mon Sep 17 00:00:00 2001 From: Colin Fowler Date: Wed, 10 Jul 2019 18:05:10 +0100 Subject: [PATCH] rebased to terraform master branch --- backend/remote-state/swift/backend.go | 13 +++++++++++++ backend/remote-state/swift/backend_state.go | 4 ++-- backend/remote-state/swift/client.go | 2 -- website/docs/backends/types/swift.html.md | 5 +++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/backend/remote-state/swift/backend.go b/backend/remote-state/swift/backend.go index d71e9e6a9..b2dd7c21e 100644 --- a/backend/remote-state/swift/backend.go +++ b/backend/remote-state/swift/backend.go @@ -237,6 +237,13 @@ func New() backend.Backend { Description: "Lock state access", Default: true, }, + + "state_name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: descriptions["state_name"], + Default: "tfstate.tf", + }, }, } @@ -308,6 +315,8 @@ func init() { "archive_container": "Swift container to archive state to.", "expire_after": "Archive object expiry duration.", + + "state_name": "Name of state object in container", } } @@ -321,6 +330,7 @@ type Backend struct { expireSecs int container string lock bool + stateName string } func (b *Backend) configure(ctx context.Context) error { @@ -364,6 +374,9 @@ func (b *Backend) configure(ctx context.Context) error { return err } + // Assign state name + b.stateName = data.Get("state_name").(string) + // Assign Container b.container = data.Get("container").(string) if b.container == "" { diff --git a/backend/remote-state/swift/backend_state.go b/backend/remote-state/swift/backend_state.go index cd2863139..13df88385 100644 --- a/backend/remote-state/swift/backend_state.go +++ b/backend/remote-state/swift/backend_state.go @@ -189,9 +189,9 @@ func (b *Backend) StateMgr(name string) (state.State, error) { func (b *Backend) objectName(name string) string { if name != backend.DefaultStateName { - name = fmt.Sprintf("%s%s/%s", objectEnvPrefix, name, TFSTATE_NAME) + name = fmt.Sprintf("%s%s/%s", objectEnvPrefix, name, b.stateName) } else { - name = TFSTATE_NAME + name = b.stateName } return name diff --git a/backend/remote-state/swift/client.go b/backend/remote-state/swift/client.go index e3b944358..b0083d430 100644 --- a/backend/remote-state/swift/client.go +++ b/backend/remote-state/swift/client.go @@ -19,8 +19,6 @@ import ( ) const ( - TFSTATE_NAME = "tfstate.tf" - consistencyTimeout = 15 // Suffix that will be appended to state file paths diff --git a/website/docs/backends/types/swift.html.md b/website/docs/backends/types/swift.html.md index 5cd606b42..80cc9408f 100644 --- a/website/docs/backends/types/swift.html.md +++ b/website/docs/backends/types/swift.html.md @@ -26,8 +26,6 @@ terraform { ``` This will create a container called `terraform-state` and an object within that container called `tfstate.tf`. It will enable versioning using the `terraform-state-archive` container to contain the older version. --> Note: Currently, the object name is statically defined as 'tfstate.tf'. Therefore Swift [pseudo-folders](https://docs.openstack.org/user-guide/cli-swift-pseudo-hierarchical-folders-directories.html) are not currently supported. - For the access credentials we recommend using a [partial configuration](/docs/backends/config.html). @@ -53,6 +51,9 @@ The following configuration options are supported: * `container` - (Required) The name of the container to create for storing the Terraform state file. + * `state_name` - (Optional) The name of the state file in the container. + Defaults to `tfstate.tf`. + * `path` - (Optional) DEPRECATED: Use `container` instead. The name of the container to create in order to store the state file.