From 2e74fe1180a1e0ae288e1c4f5748dd40ed04aa9e Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Tue, 9 Feb 2016 13:27:12 -0600 Subject: [PATCH] Add ability to inject internal CA Cert --- DOCS.md | 6 ++++++ main.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/DOCS.md b/DOCS.md index 8c353d6..22ab106 100644 --- a/DOCS.md +++ b/DOCS.md @@ -4,6 +4,7 @@ Use the Terraform plugin to apply the infrastructure configuration contained wit * `remote` - contains the configuration for the Terraform remote state tracking. * `backend` - the Terraform remote state backend to use. * `config` - a map of configuration parameters for the remote state backend. Each value is passed as a `-backend-config==` option. + * `ca_cert` - ca cert to add to your environment to allow terraform to use internal/private resources * `vars` - a map of variables to pass to the Terraform `plan` and `apply` commands. Each value is passed as a `-var =` option. The following is a sample Terraform configuration in your .drone.yml file: @@ -14,6 +15,11 @@ deploy: plan: false remote: backend: S3 + ca_cert: | + -----BEGIN CERTIFICATE----- + asdfsadf + asdfsadf + -----END CERTIFICATE----- config: bucket: my-terraform-config-bucket key: tf-states/my-project diff --git a/main.go b/main.go index 3626ad9..1bc4e0d 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" "strings" + "io/ioutil" "github.com/drone/drone-plugin-go/plugin" ) @@ -18,6 +19,7 @@ type terraform struct { type remote struct { Backend string `json:"backend"` Config map[string]string `json:"config"` + Cacert string `json:"ca_cert"` } func main() { @@ -31,6 +33,9 @@ func main() { var commands []*exec.Cmd remote := vargs.Remote + if remote.Cacert != "" { + commands = append(commands, installCaCert(remote.Cacert)) + } if remote.Backend != "" { commands = append(commands, remoteConfigCommand(remote)) } @@ -57,6 +62,13 @@ func main() { } +func installCaCert(cacert string) *exec.Cmd { + ioutil.WriteFile("/usr/local/share/ca-certificates/ca_cert.crt", []byte(cacert), 0644) + return exec.Command( + "update-ca-certificates", + ) +} + func remoteConfigCommand(config remote) *exec.Cmd { args := []string{ "remote",