From 89133d1431e75d7292d15007de4afc6f6112483b Mon Sep 17 00:00:00 2001 From: "Karapetyan, Aram" Date: Wed, 6 Sep 2023 12:37:11 +0400 Subject: [PATCH] feat(DMVP-2706): add option to autmatically run apply if plan was successful --- modules/workspace/main.tf | 1 + modules/workspace/variables.tf | 6 +++ tests/basic/1-example.tf | 2 + tests/basic/example-infra/component-1.yaml | 56 ---------------------- tests/basic/example-infra/empty.yaml | 2 + variables.tf | 6 +++ workspaces.tf | 2 + 7 files changed, 19 insertions(+), 56 deletions(-) delete mode 100644 tests/basic/example-infra/component-1.yaml diff --git a/modules/workspace/main.tf b/modules/workspace/main.tf index b3cae0c..da694ed 100644 --- a/modules/workspace/main.tf +++ b/modules/workspace/main.tf @@ -20,6 +20,7 @@ resource "tfe_workspace" "this" { global_remote_state = var.workspace.global_remote_state project_id = local.project_id working_directory = "${var.workspace.directory}${var.name}" + auto_apply = var.auto_apply dynamic "vcs_repo" { for_each = try(var.repo.identifier, null) == null ? [] : [var.repo] diff --git a/modules/workspace/variables.tf b/modules/workspace/variables.tf index 164cda8..22c8878 100644 --- a/modules/workspace/variables.tf +++ b/modules/workspace/variables.tf @@ -95,3 +95,9 @@ variable "output" { default = [] description = "The module output" } + +variable "auto_apply" { + type = bool + default = false + description = "To have workspaces automatically apply after plan is done successfully." +} diff --git a/tests/basic/1-example.tf b/tests/basic/1-example.tf index 13c7b94..2dd41a7 100644 --- a/tests/basic/1-example.tf +++ b/tests/basic/1-example.tf @@ -21,4 +21,6 @@ module "basic" { secret_access_key = "" default_region = "" } + + auto_apply = true } diff --git a/tests/basic/example-infra/component-1.yaml b/tests/basic/example-infra/component-1.yaml deleted file mode 100644 index 8e13e9e..0000000 --- a/tests/basic/example-infra/component-1.yaml +++ /dev/null @@ -1,56 +0,0 @@ -source: dasmeta/account/aws -version: 1.2.2 -variables: - alarm_actions: - enabled: true - slack_webhooks: - - hook_url: ${0-account/secret-reader.secrets.MONITORING_SLACK_HOOK_URL} - channel: test-monitoring - username: reporter - web_endpoints: - - ${0-account/secret-reader.secrets.MONITORING_OPSGENIE_HOOK_URL_HIGH} - alarm_actions_virginia: - enabled: true - slack_webhooks: - - hook_url: ${0-account/secret-reader.secrets.MONITORING_SLACK_HOOK_URL} - channel: test-monitoring - username: reporter2 - web_endpoints: - - ${0-account/secret-reader.secrets.MONITORING_OPSGENIE_HOOK_URL_HIGH} - # cloudtrail: - # enabled: true - # is_organization_trail: false - # enable_cloudwatch_logs: false # TODO: check why we need this and if there is need enable it - # name: "cloud-audit-logs" - # event_selector: [] # TODO: check what about this config and enable/configure if needed - # insight_selector: [] # TODO: check what about this config and enable/configure if needed - # alerts_events: [] # TODO: check what about this config and enable/configure if needed - # enforce_mfa: - # enabled: true - secrets: - enabled: true - values: {} # values will be filled from SM ui in aws web console -providers: - - name: aws - version: ~> 4.0 - module_nested_provider: true - variables: - region: eu-central-1 - default_tags: - tags: - Account: test - ManageLevel: account - - name: aws - alias: virginia - version: ">= 4.0" - module_nested_provider: true - variables: - region: us-east-1 - default_tags: - tags: - Account: test - Environment: stage - Product: test - ManageLevel: product -linked_workspaces: - - 0-account/root/secret-reader diff --git a/tests/basic/example-infra/empty.yaml b/tests/basic/example-infra/empty.yaml index e69de29..3691bba 100644 --- a/tests/basic/example-infra/empty.yaml +++ b/tests/basic/example-infra/empty.yaml @@ -0,0 +1,2 @@ +source: dasmeta/null/empty +version: 1.0.1 diff --git a/variables.tf b/variables.tf index bf9f65b..5154682 100644 --- a/variables.tf +++ b/variables.tf @@ -74,3 +74,9 @@ variable "aws" { # description = "The aws default region" # } } + +variable "auto_apply" { + type = bool + default = false + description = "To have workspaces automatically apply after plan is done successfully." +} diff --git a/workspaces.tf b/workspaces.tf index 637c275..ef01c25 100644 --- a/workspaces.tf +++ b/workspaces.tf @@ -27,6 +27,8 @@ module "workspaces" { module_providers = try(each.value.providers, []) linked_workspaces = try(each.value.linked_workspaces, null) + auto_apply = var.auto_apply + workspace = { org = var.org directory = var.rootdir