Browse Source

Merge pull request #22 from ewbankkit/add-parallelism-option-public

Add terraform '-parallelism=' option
pull/24/head
Thomas Boerger 9 years ago
committed by GitHub
parent
commit
714d496249
  1. 23
      DOCS.md
  2. 4
      Dockerfile
  3. 22
      main.go

23
DOCS.md

@ -8,8 +8,9 @@ Use the Terraform plugin to apply the infrastructure configuration contained wit
<key>=<value>` option.
* `ca_cert` - ca cert to add to your environment to allow terraform to use internal/private resources
* `sensitive` (default: `false`) - Whether or not to suppress terraform commands to stdout.
* `role_arn_to_assume` - A role to assume before running the terraform commands
* `role_arn_to_assume` - A role to assume before running the terraform commands.
* `root_dir` - The root directory where the terraform files live. When unset, the top level directory will be assumed.
* `parallelism` - The number of concurrent operations as Terraform walks its graph.
The following is a sample Terraform configuration in your .drone.yml file:
@ -113,3 +114,23 @@ deploy:
app_version: 1.0.0
root_dir: some/path/here
```
## Parallelism
You may want to limit the number of concurrent operations as Terraform walks its graph.
If you want to change Terraform's default parallelism (currently equal to 10) then set the `parallelism` parameter.
```yaml
deploy:
terraform:
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
parallelism: 2
```

4
Dockerfile

@ -6,10 +6,10 @@
FROM gliderlabs/alpine:3.2
RUN apk-install ca-certificates git
ENV TERRAFORM_VERSION 0.6.14
ENV TERRAFORM_VERSION 0.6.16
RUN apk update && \
wget -q "https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-2.21-r2.apk" && \
wget -q "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.21-r2/glibc-2.21-r2.apk" && \
apk add --allow-untrusted glibc-2.21-r2.apk && \
wget -q -O terraform.zip "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" && \
unzip terraform.zip -d /bin && \

22
main.go

@ -26,6 +26,7 @@ type terraform struct {
Sensitive bool `json:"sensitive"`
RoleARN string `json:"role_arn_to_assume"`
RootDir string `json:"root_dir"`
Parallelism int `json:"parallelism"`
}
type remote struct {
@ -57,9 +58,9 @@ func main() {
commands = append(commands, remoteConfigCommand(remote))
}
commands = append(commands, getModules())
commands = append(commands, planCommand(vargs.Vars))
commands = append(commands, planCommand(vargs.Vars, vargs.Parallelism))
if !vargs.Plan {
commands = append(commands, applyCommand())
commands = append(commands, applyCommand(vargs.Parallelism))
}
commands = append(commands, deleteCache())
@ -129,7 +130,7 @@ func getModules() *exec.Cmd {
)
}
func planCommand(variables map[string]string) *exec.Cmd {
func planCommand(variables map[string]string, parallelism int) *exec.Cmd {
args := []string{
"plan",
"-out=plan.tfout",
@ -138,17 +139,26 @@ func planCommand(variables map[string]string) *exec.Cmd {
args = append(args, "-var")
args = append(args, fmt.Sprintf("%s=%s", k, v))
}
if parallelism > 0 {
args = append(args, fmt.Sprintf("-parallelism=%d", parallelism))
}
return exec.Command(
"terraform",
args...,
)
}
func applyCommand() *exec.Cmd {
func applyCommand(parallelism int) *exec.Cmd {
args := []string{
"apply",
}
if parallelism > 0 {
args = append(args, fmt.Sprintf("-parallelism=%d", parallelism))
}
args = append(args, "plan.tfout")
return exec.Command(
"terraform",
"apply",
"plan.tfout",
args...,
)
}

Loading…
Cancel
Save