backend/remote-state/gcs: Add support for the GOOGLE_PROJECT environment variable.
This copies behavior from the Google Cloud provider.
This commit is contained in:
parent
37dc95158d
commit
9583d0945c
|
@ -23,10 +23,11 @@ type gcsBackend struct {
|
|||
storageClient *storage.Client
|
||||
storageContext context.Context
|
||||
|
||||
projectID string
|
||||
bucketName string
|
||||
prefix string
|
||||
defaultStateFile string
|
||||
|
||||
projectID string
|
||||
}
|
||||
|
||||
func New() backend.Backend {
|
||||
|
@ -85,12 +86,16 @@ func (b *gcsBackend) configure(ctx context.Context) error {
|
|||
|
||||
data := schema.FromContextBackendConfig(b.storageContext)
|
||||
|
||||
b.projectID = data.Get("project").(string)
|
||||
b.bucketName = data.Get("bucket").(string)
|
||||
b.prefix = strings.TrimLeft(data.Get("prefix").(string), "/")
|
||||
|
||||
b.defaultStateFile = strings.TrimLeft(data.Get("path").(string), "/")
|
||||
|
||||
b.projectID = data.Get("project").(string)
|
||||
if id := os.Getenv("GOOGLE_PROJECT"); b.projectID == "" && id != "" {
|
||||
b.projectID = id
|
||||
}
|
||||
|
||||
opts := []option.ClientOption{
|
||||
option.WithScopes(storage.ScopeReadWrite),
|
||||
option.WithUserAgent(terraform.UserAgentString()),
|
||||
|
|
|
@ -55,5 +55,5 @@ The following configuration options are supported:
|
|||
The provided credentials need to have the `devstorage.read_write` scope and `WRITER` permissions on the bucket.
|
||||
* `prefix` - (Optional) GCS prefix inside the bucket. Named states are stored in an object called `<prefix>/<name>.tfstate`.
|
||||
* `path` - (Deprecated) GCS path to the state file of the default state. For backwards compatibility only, use `prefix` instead.
|
||||
* `project` - (Optional) The project ID to which the bucket belongs. This is only used when creating a new bucket during initialization.
|
||||
* `project` / `GOOGLE_PROJECT` - (Optional) The project ID to which the bucket belongs. This is only used when creating a new bucket during initialization.
|
||||
Since buckets have globally unique names, the project ID is not required to access the bucket during normal operation.
|
||||
|
|
Loading…
Reference in New Issue