mirror of
https://github.com/thegeeklab/wp-opentofu.git
synced 2024-11-24 23:30:39 +00:00
Implement exportSecrets
Allows us to set environment variables that could be the named the same between multiple steps, but have different values due to enivronmental differences. This is a redo of #28 because I'm bad at git. The secrets are exported so that they can be used in any other flag in this plugin.
This commit is contained in:
parent
877e7415ef
commit
c0e63defcd
23
DOCS.md
23
DOCS.md
@ -187,3 +187,26 @@ pipeline:
|
|||||||
app_version: 1.0.0
|
app_version: 1.0.0
|
||||||
parallelism: 2
|
parallelism: 2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Remote configuration
|
||||||
|
|
||||||
|
If you are configuring an s3 remote state and require S3 environment secrets you add the secrets "FOO" and "BAR" to your drone environment and reference the secrets as follows. These will not be outputted to stdout.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
pipeline:
|
||||||
|
terraform:
|
||||||
|
image: jmccann/drone-terraform:0.5
|
||||||
|
plan: false
|
||||||
|
remote:
|
||||||
|
backend: S3
|
||||||
|
config:
|
||||||
|
bucket: my-terraform-config-bucket
|
||||||
|
key: tf-states/my-project
|
||||||
|
region: us-east-1
|
||||||
|
vars:
|
||||||
|
app_name: my-project
|
||||||
|
app_version: 1.0.0
|
||||||
|
secrets:
|
||||||
|
AWS_ACCESS_KEY_ID: FOO
|
||||||
|
AWS_SECRET_ACCESS_KEY: BAR
|
||||||
|
```
|
||||||
|
11
plugin.go
11
plugin.go
@ -44,6 +44,11 @@ func (p Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var commands []*exec.Cmd
|
var commands []*exec.Cmd
|
||||||
|
|
||||||
|
if len(p.Config.Secrets) != 0 {
|
||||||
|
exportSecrets(p.Config.Secrets)
|
||||||
|
}
|
||||||
|
|
||||||
remote := p.Config.Remote
|
remote := p.Config.Remote
|
||||||
if p.Config.Cacert != "" {
|
if p.Config.Cacert != "" {
|
||||||
commands = append(commands, installCaCert(p.Config.Cacert))
|
commands = append(commands, installCaCert(p.Config.Cacert))
|
||||||
@ -94,6 +99,12 @@ func installCaCert(cacert string) *exec.Cmd {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func exportSecrets(secrets map[string]string) {
|
||||||
|
for k, v := range secrets {
|
||||||
|
os.Setenv(fmt.Sprintf("%s", k), fmt.Sprintf("%s", os.Getenv(v)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func deleteCache() *exec.Cmd {
|
func deleteCache() *exec.Cmd {
|
||||||
return exec.Command(
|
return exec.Command(
|
||||||
"rm",
|
"rm",
|
||||||
|
Loading…
Reference in New Issue
Block a user