0
0
mirror of https://github.com/thegeeklab/wp-opentofu.git synced 2024-11-09 18:00:40 +00:00

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

Add terraform '-parallelism=' option
This commit is contained in:
Thomas Boerger 2016-06-20 10:57:01 +02:00 committed by GitHub
commit 714d496249
3 changed files with 47 additions and 16 deletions

23
DOCS.md
View File

@ -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
```

View File

@ -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 && \

36
main.go
View File

@ -19,13 +19,14 @@ var (
)
type terraform struct {
Remote remote `json:"remote"`
Plan bool `json:"plan"`
Vars map[string]string `json:"vars"`
Cacert string `json:"ca_cert"`
Sensitive bool `json:"sensitive"`
RoleARN string `json:"role_arn_to_assume"`
RootDir string `json:"root_dir"`
Remote remote `json:"remote"`
Plan bool `json:"plan"`
Vars map[string]string `json:"vars"`
Cacert string `json:"ca_cert"`
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...,
)
}