Skip to content

Commit

Permalink
feat(tfstate): support "remote" for tfstate backend (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
carnei-ro authored Apr 5, 2022
1 parent 3d5dfd5 commit fa5ca8b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,27 @@ which is equivalent to the following input for `vals`:
```
$ echo 'foo: ref+tfstateazurerm://my_rg/my_storage_account/terraform-backend/unique.terraform.tfstate/output.virtual_network.name' | vals eval -f -
```

### Terraform in Terraform Cloud / Terraform Enterprise (tfstateremote)

- `ref+tfstateremote://app.terraform.io/{org}/{myworkspace}/RESOURCE_NAME`

Examples:

- `ref+tfstateremote://app.terraform.io/myorg/myworkspace/output.virtual_network.name`

It allows to use Terraform state stored in Terraform Cloud / Terraform Enterprise given the resource group, the organization and the workspace. You can try to read the state with command (with exported variable `TFE_TOKEN`):

```
$ tfstate-lookup -s remote://app.terraform.io/myorg/myworkspace output.virtual_network.name
```

which is equivalent to the following input for `vals`:

```
$ echo 'foo: ref+tfstateremote://app.terraform.io/myorg/myworkspace/output.virtual_network.name' | vals eval -f -
```

### SOPS

- The whole content of a SOPS-encrypted file: `ref+sops://base64_data_or_path_to_file?key_type=[filepath|base64]&format=[binary|dotenv|yaml]`
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/Azure/go-autorest/autorest v0.11.19
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8
github.com/aws/aws-sdk-go v1.40.28
github.com/fujiwara/tfstate-lookup v0.4.0
github.com/fujiwara/tfstate-lookup v0.4.2
github.com/google/go-cmp v0.5.5
github.com/hashicorp/golang-lru v0.5.4
github.com/hashicorp/vault/api v1.0.4
Expand All @@ -22,4 +22,4 @@ require (
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107172259-749611fa9fcc
)
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fujiwara/tfstate-lookup v0.4.0 h1:AaubXvolethCndWpZ+c/Sibm6J4SCIlSxcxvn6cYon4=
github.com/fujiwara/tfstate-lookup v0.4.0/go.mod h1:F56Bz3W497ZJA0ijFLVgcYeAVuhtbzvV6/hMtu6f2Ek=
github.com/fujiwara/tfstate-lookup v0.4.2 h1:RmhlHIMLVqNWHxaBasap+L5LO7pKorAbpIVQrktYCzY=
github.com/fujiwara/tfstate-lookup v0.4.2/go.mod h1:F56Bz3W497ZJA0ijFLVgcYeAVuhtbzvV6/hMtu6f2Ek=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-asn1-ber/asn1-ber v1.3.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
Expand Down
2 changes: 2 additions & 0 deletions pkg/stringprovider/stringprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func New(provider api.StaticConfig) (api.LazyLoadedStringProvider, error) {
return tfstate.New(provider, "s3"), nil
case "tfstateazurerm":
return tfstate.New(provider, "azurerm"), nil
case "tfstateremote":
return tfstate.New(provider, "remote"), nil
case "azurekeyvault":
return azurekeyvault.New(provider), nil
}
Expand Down
4 changes: 4 additions & 0 deletions vals.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const (
ProviderTFStateGS = "tfstategs"
ProviderTFStateS3 = "tfstates3"
ProviderTFStateAzureRM = "tfstateazurerm"
ProviderTFStateRemote = "tfstateremote"
ProviderAzureKeyVault = "azurekeyvault"
)

Expand Down Expand Up @@ -180,6 +181,9 @@ func (r *Runtime) Eval(template map[string]interface{}) (map[string]interface{},
case ProviderTFStateAzureRM:
p := tfstate.New(conf, "azurerm")
return p, nil
case ProviderTFStateRemote:
p := tfstate.New(conf, "remote")
return p, nil
case ProviderAzureKeyVault:
p := azurekeyvault.New(conf)
return p, nil
Expand Down

0 comments on commit fa5ca8b

Please sign in to comment.