From 77b9fad7f06e5569568e494915aa67eaea6f0771 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Wed, 29 Aug 2018 20:20:32 +0200 Subject: [PATCH] backend/manta: deprecate camelcase attribute name This change is needed (next to making it consistent as its the only attribute name that uses camelcase) because passing that attribute objectName in the update `terraform_remote_state` resource, ended up giving me this error: https://github.com/hashicorp/terraform/blob/master/helper/schema/schema.go#L736 --- backend/remote-state/manta/backend.go | 17 +++++++++++++++-- backend/remote-state/manta/backend_test.go | 13 ++++++------- backend/remote-state/manta/client_test.go | 12 ++++++------ website/docs/backends/types/manta.html.md | 11 ++++++----- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/backend/remote-state/manta/backend.go b/backend/remote-state/manta/backend.go index f30bbcc87..d651e6bd6 100644 --- a/backend/remote-state/manta/backend.go +++ b/backend/remote-state/manta/backend.go @@ -62,9 +62,17 @@ func New() backend.Backend { }, "objectName": { + Type: schema.TypeString, + Optional: true, + Default: "terraform.tfstate", + Deprecated: "please use the object_name attribute", + }, + + "object_name": { Type: schema.TypeString, Optional: true, - Default: "terraform.tfstate", + // Set this default once the objectName attribute is removed! + // Default: "terraform.tfstate", }, }, } @@ -116,7 +124,12 @@ func (b *Backend) configure(ctx context.Context) error { } b.path = data.Get("path").(string) - b.objectName = data.Get("objectName").(string) + b.objectName = data.Get("object_name").(string) + + // If object_name is not set, try the deprecated objectName. + if b.objectName == "" { + b.objectName = data.Get("objectName").(string) + } var validationError *multierror.Error diff --git a/backend/remote-state/manta/backend_test.go b/backend/remote-state/manta/backend_test.go index 9b243b7fc..76f2b7377 100644 --- a/backend/remote-state/manta/backend_test.go +++ b/backend/remote-state/manta/backend_test.go @@ -31,8 +31,8 @@ func TestBackend(t *testing.T) { keyName := "testState" b := backend.TestBackendConfig(t, New(), map[string]interface{}{ - "path": directory, - "objectName": keyName, + "path": directory, + "object_name": keyName, }).(*Backend) createMantaFolder(t, b.storageClient, directory) @@ -48,13 +48,13 @@ func TestBackendLocked(t *testing.T) { keyName := "testState" b1 := backend.TestBackendConfig(t, New(), map[string]interface{}{ - "path": directory, - "objectName": keyName, + "path": directory, + "object_name": keyName, }).(*Backend) b2 := backend.TestBackendConfig(t, New(), map[string]interface{}{ - "path": directory, - "objectName": keyName, + "path": directory, + "object_name": keyName, }).(*Backend) createMantaFolder(t, b1.storageClient, directory) @@ -88,7 +88,6 @@ func deleteMantaFolder(t *testing.T, mantaClient *storage.StorageClient, directo } for _, obj := range objs.Entries { - if obj.Type == "directory" { ojs, err := mantaClient.Dir().List(context.Background(), &storage.ListDirectoryInput{ DirectoryName: path.Join(mantaDefaultRootStore, directoryName, obj.Name), diff --git a/backend/remote-state/manta/client_test.go b/backend/remote-state/manta/client_test.go index 110654c77..18847972f 100644 --- a/backend/remote-state/manta/client_test.go +++ b/backend/remote-state/manta/client_test.go @@ -21,8 +21,8 @@ func TestRemoteClient(t *testing.T) { keyName := "testState" b := backend.TestBackendConfig(t, New(), map[string]interface{}{ - "path": directory, - "objectName": keyName, + "path": directory, + "object_name": keyName, }).(*Backend) createMantaFolder(t, b.storageClient, directory) @@ -42,13 +42,13 @@ func TestRemoteClientLocks(t *testing.T) { keyName := "testState" b1 := backend.TestBackendConfig(t, New(), map[string]interface{}{ - "path": directory, - "objectName": keyName, + "path": directory, + "object_name": keyName, }).(*Backend) b2 := backend.TestBackendConfig(t, New(), map[string]interface{}{ - "path": directory, - "objectName": keyName, + "path": directory, + "object_name": keyName, }).(*Backend) createMantaFolder(t, b1.storageClient, directory) diff --git a/website/docs/backends/types/manta.html.md b/website/docs/backends/types/manta.html.md index 61914d3e0..386f08af7 100644 --- a/website/docs/backends/types/manta.html.md +++ b/website/docs/backends/types/manta.html.md @@ -17,8 +17,8 @@ Stores the state as an artifact in [Manta](https://www.joyent.com/manta). ```hcl terraform { backend "manta" { - path = "random/path" - objectName = "terraform.tfstate" + path = "random/path" + object_name = "terraform.tfstate" } } ``` @@ -32,8 +32,8 @@ Note that for the access credentials we recommend using a data "terraform_remote_state" "foo" { backend = "manta" config { - path = "random/path" - objectName = "terraform.tfstate" + path = "random/path" + object_name = "terraform.tfstate" } } ``` @@ -49,4 +49,5 @@ The following configuration options are supported: * `key_id` - (Required) This is the fingerprint of the public key matching the key specified in key_path. It can be obtained via the command ssh-keygen -l -E md5 -f /path/to/key. Can be set via the `SDC_KEY_ID` or `TRITON_KEY_ID` environment variables. * `insecure_skip_tls_verify` - (Optional) This allows skipping TLS verification of the Triton endpoint. It is useful when connecting to a temporary Triton installation such as Cloud-On-A-Laptop which does not generally use a certificate signed by a trusted root CA. Defaults to `false`. * `path` - (Required) The path relative to your private storage directory (`/$MANTA_USER/stor`) where the state file will be stored. **Please Note:** If this path does not exist, then the backend will create this folder location as part of backend creation. - * `objectName` - (Optional) The name of the state file (defaults to `terraform.tfstate`) \ No newline at end of file + * `objectName` - (Optional, Deprecated) Use `object_name` instead. + * `object_name` - (Optional) The name of the state file (defaults to `terraform.tfstate`)