Merge pull request #17465 from Elethiomel/master

Add support for user configured state object names in swift containers
This commit is contained in:
Pam Selle 2019-07-10 13:39:33 -04:00 committed by GitHub
commit 9f9ac1b326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 6 deletions

View File

@ -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 == "" {

View File

@ -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

View File

@ -19,8 +19,6 @@ import (
)
const (
TFSTATE_NAME = "tfstate.tf"
consistencyTimeout = 15
// Suffix that will be appended to state file paths

View File

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