Commit 244cc491 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat!: support environment auto-stop

BREAKING CHANGE: now review environments will auto stop after 4 hours
by default. Configurable (see doc).
parent 2044b700
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -342,6 +342,7 @@ Here are variables supported to configure review environments:
| `TF_REVIEW_PLAN_OPTS`    | Terraform extra [plan options](https://developer.hashicorp.com/terraform/cli/commands/plan) for `review` env | _none_ |
| `TF_REVIEW_APPLY_OPTS`   | Terraform extra [apply options](https://developer.hashicorp.com/terraform/cli/commands/apply) for `review` env | `$TF_APPLY_OPTS` |
| `TF_REVIEW_DESTROY_OPTS` | Terraform extra [destroy options](https://developer.hashicorp.com/terraform/cli/commands/destroy) for `review` env | `$TF_DESTROY_OPTS` |
| `TF_REVIEW_AUTOSTOP_DURATION`| The amount of time before GitLab will automatically stop `review` environments | `4 hours` |

#### Enabling auto-cleanup

@@ -376,6 +377,7 @@ Here are variables supported to configure the integration environment:
| `TF_INTEG_PLAN_OPTS`    | Terraform extra [plan options](https://developer.hashicorp.com/terraform/cli/commands/plan) for `integration` env | _none_ |
| `TF_INTEG_APPLY_OPTS`   | Terraform extra [apply options](https://developer.hashicorp.com/terraform/cli/commands/apply) for `integration` env | `$TF_APPLY_OPTS` |
| `TF_INTEG_DESTROY_OPTS` | Terraform extra [destroy options](https://developer.hashicorp.com/terraform/cli/commands/destroy) for `integration` env | `$TF_DESTROY_OPTS` |
| `TF_INTEG_AUTOSTOP_DURATION`| The amount of time before GitLab will automatically stop the `integration` env | `never` |

### Staging environment configuration

@@ -396,6 +398,7 @@ Here are variables supported to configure the staging environment:
| `TF_STAGING_PLAN_OPTS`    | Terraform extra [plan options](https://developer.hashicorp.com/terraform/cli/commands/plan) for `staging` env | _none_ |
| `TF_STAGING_APPLY_OPTS`   | Terraform extra [apply options](https://developer.hashicorp.com/terraform/cli/commands/apply) for `staging` env | `$TF_APPLY_OPTS` |
| `TF_STAGING_DESTROY_OPTS` | Terraform extra [destroy options](https://developer.hashicorp.com/terraform/cli/commands/destroy) for `staging` env | `$TF_DESTROY_OPTS` |
| `TF_STAGING_AUTOSTOP_DURATION`| The amount of time before GitLab will automatically stop the `staging` env | `never` |

### Production environment configuration

+15 −0
Original line number Diff line number Diff line
@@ -286,6 +286,11 @@
          "description": "Terraform extra [destroy options](https://developer.hashicorp.com/terraform/cli/commands/destroy) for `review` env",
          "default": "$TF_DESTROY_OPTS",
          "advanced": true
        },
        {
          "name": "TF_REVIEW_AUTOSTOP_DURATION",
          "description": "The amount of time before GitLab will automatically stop `review` environments",
          "default": "4 hours"
        }
      ]
    },
@@ -336,6 +341,11 @@
          "description": "Terraform extra [destroy options](https://developer.hashicorp.com/terraform/cli/commands/destroy) for `integration` env",
          "default": "$TF_DESTROY_OPTS",
          "advanced": true
        },
        {
          "name": "TF_INTEG_AUTOSTOP_DURATION",
          "description": "The amount of time before GitLab will automatically stop the `integration` env",
          "default": "never"
        }
      ]
    },
@@ -386,6 +396,11 @@
          "description": "Terraform extra [destroy options](https://developer.hashicorp.com/terraform/cli/commands/destroy) for `staging` env",
          "default": "$TF_DESTROY_OPTS",
          "advanced": true
        },
        {
          "name": "TF_STAGING_AUTOSTOP_DURATION",
          "description": "The amount of time before GitLab will automatically stop the `staging` env",
          "default": "never"
        }
      ]
    },
+8 −0
Original line number Diff line number Diff line
@@ -86,6 +86,11 @@ variables:
  TF_SCRIPTS_DIR: "."
  TF_OUTPUT_DIR: "tf-output"

  # auto-stop environments
  TF_REVIEW_AUTOSTOP_DURATION: "4 hours"
  TF_INTEG_AUTOSTOP_DURATION: "never"
  TF_STAGING_AUTOSTOP_DURATION: "never"

  # separated tf plan is enabled for production by default
  TF_PROD_PLAN_ENABLED: "true"

@@ -988,6 +993,7 @@ tf-destroy-review:
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop
    auto_stop_in: "$TF_REVIEW_AUTOSTOP_DURATION"
  resource_group: tf-review/$CI_COMMIT_REF_NAME
  rules:
    # exclude tags
@@ -1063,6 +1069,7 @@ tf-destroy-integration:
  environment:
    name: integration
    action: stop
    auto_stop_in: "$TF_INTEG_AUTOSTOP_DURATION"
  resource_group: tf-integration
  rules:
    # only on integration branch(es), with $TF_INTEG_ENABLED set
@@ -1135,6 +1142,7 @@ tf-destroy-staging:
  environment:
    name: staging
    action: stop
    auto_stop_in: "$TF_STAGING_AUTOSTOP_DURATION"
  resource_group: tf-staging
  rules:
    # only on production branch(es), with $TF_STAGING_ENABLED set