Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions backend/remote-state/swift/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}

Expand Down Expand Up @@ -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",
}
}

Expand All @@ -321,6 +330,7 @@ type Backend struct {
expireSecs int
container string
lock bool
stateName string
}

func (b *Backend) configure(ctx context.Context) error {
Expand Down Expand Up @@ -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 == "" {
Expand Down
4 changes: 2 additions & 2 deletions backend/remote-state/swift/backend_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions backend/remote-state/swift/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
)

const (
TFSTATE_NAME = "tfstate.tf"

consistencyTimeout = 15

// Suffix that will be appended to state file paths
Expand Down
5 changes: 3 additions & 2 deletions website/docs/backends/types/swift.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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.

Expand Down