From 902b76e6ad028e148b4702839431f5a1f8406b84 Mon Sep 17 00:00:00 2001 From: Sylvain Gibier Date: Fri, 16 Jun 2023 18:49:56 +0200 Subject: [PATCH] VSDSCP-212 - refactoring and enabling int/ all prelive stages. --- environments/aws/ca-north-1/live/Jenkinsfile | 113 ++++++++++++++++++ environments/aws/ca-north-1/live/provider.tf | 21 ++++ .../aws/ca-north-1/live/terraform.tfvars | 3 + environments/aws/ca-north-1/live/variables.tf | 11 ++ .../aws/ca-north-1/prelive/Jenkinsfile | 113 ++++++++++++++++++ .../aws/ca-north-1/prelive/provider.tf | 21 ++++ .../aws/ca-north-1/prelive/terraform.tfvars | 3 + .../aws/ca-north-1/prelive/variables.tf | 11 ++ environments/aws/eu-west-1/int/Jenkinsfile | 7 +- environments/aws/eu-west-1/live/Jenkinsfile | 113 ++++++++++++++++++ environments/aws/eu-west-1/live/provider.tf | 21 ++++ .../aws/eu-west-1/live/terraform.tfvars | 3 + environments/aws/eu-west-1/live/variables.tf | 11 ++ .../aws/eu-west-1/prelive/Jenkinsfile | 113 ++++++++++++++++++ environments/aws/eu-west-1/prelive/module.tf | 3 - .../aws/eu-west-1/prelive/provider.tf | 9 +- .../aws/eu-west-1/prelive/terraform.tfvars | 12 +- .../aws/eu-west-1/prelive/variables.tf | 27 +---- environments/aws/us-east-1/live/Jenkinsfile | 113 ++++++++++++++++++ environments/aws/us-east-1/live/provider.tf | 21 ++++ .../aws/us-east-1/live/terraform.tfvars | 3 + environments/aws/us-east-1/live/variables.tf | 11 ++ .../aws/us-east-1/prelive/Jenkinsfile | 113 ++++++++++++++++++ environments/aws/us-east-1/prelive/module.tf | 3 - .../aws/us-east-1/prelive/provider.tf | 9 +- .../aws/us-east-1/prelive/terraform.tfvars | 12 +- .../aws/us-east-1/prelive/variables.tf | 27 +---- 27 files changed, 844 insertions(+), 83 deletions(-) create mode 100644 environments/aws/ca-north-1/live/Jenkinsfile create mode 100644 environments/aws/ca-north-1/live/provider.tf create mode 100644 environments/aws/ca-north-1/live/variables.tf create mode 100644 environments/aws/ca-north-1/prelive/Jenkinsfile create mode 100644 environments/aws/ca-north-1/prelive/provider.tf create mode 100644 environments/aws/ca-north-1/prelive/variables.tf create mode 100644 environments/aws/eu-west-1/live/Jenkinsfile create mode 100644 environments/aws/eu-west-1/live/provider.tf create mode 100644 environments/aws/eu-west-1/live/variables.tf create mode 100644 environments/aws/eu-west-1/prelive/Jenkinsfile delete mode 100644 environments/aws/eu-west-1/prelive/module.tf create mode 100644 environments/aws/us-east-1/live/Jenkinsfile create mode 100644 environments/aws/us-east-1/live/provider.tf create mode 100644 environments/aws/us-east-1/live/variables.tf create mode 100644 environments/aws/us-east-1/prelive/Jenkinsfile delete mode 100644 environments/aws/us-east-1/prelive/module.tf diff --git a/environments/aws/ca-north-1/live/Jenkinsfile b/environments/aws/ca-north-1/live/Jenkinsfile new file mode 100644 index 0000000..2608a44 --- /dev/null +++ b/environments/aws/ca-north-1/live/Jenkinsfile @@ -0,0 +1,113 @@ +String cloud_provider = "aws" +String aws_region = "ca-north-1" +String default_stage = "live" +String aws_access_credentials = "vsds_${aws_region}_${default_stage}_infrastructure.automation.user" +String dynatrace_api_token_credentials = "api_token_dynatrace_${aws_region}_${default_stage}" + + +pipeline { + agent { + node { + label 'vsds-terraform' + } + } + + environment { + GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + + AWS_ID = credentials("${aws_access_credentials}") + AWS_ACCESS_KEY_ID = "${env.AWS_ID_USR}" + AWS_SECRET_ACCESS_KEY = "${env.AWS_ID_PSW}" + + AWS_REGION = "${aws_region}" + STAGE = "${default_stage}" + CLOUD_PROVIDER = "${cloud_provider}" + + API_TOKEN = credentials("${dynatrace_api_token_credentials}") + TF_VAR_dt_api_token = "${env.API_TOKEN}" + } + + options { + timestamps() + ansiColor('xterm') + disableConcurrentBuilds(abortPrevious: true) + timeout(time: 1, unit: 'HOURS') + } + + stages { + stage('terraform init') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + sh """ + set -e + cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} + terraform init + """ + } + } + } + } + + stage('Terraform plan') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + script { + env.PLAN_STATUS = sh(script: "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} && terraform plan -out=.terraform/plan.out -input=false -detailed-exitcode", returnStatus: true) + if (env.PLAN_STATUS == "1") { + currentBuild.result = "FAILURE" + error('Aborting the build.') + return + } + + } + } + } + } + } + + stage('Interactive') { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + timeout(time: 15, unit: "MINUTES") { + input "Is this plan acceptable?" + milestone 1 + } + } + } + + stage("terraform apply") { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + container('terraform') { + sshagent(credentials: ['sofa-user-automation']) { + script { + sh "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} " + sh("terraform apply -input=false .terraform/plan.out") + } + } + } + } + } + } + + post { + always { + cleanWs() + + script { + currentBuild.result = currentBuild.result ?: 'SUCCESS' + notifyBitbucket() + } + } + } +} diff --git a/environments/aws/ca-north-1/live/provider.tf b/environments/aws/ca-north-1/live/provider.tf new file mode 100644 index 0000000..b3fecc3 --- /dev/null +++ b/environments/aws/ca-north-1/live/provider.tf @@ -0,0 +1,21 @@ +terraform { + required_providers { + dynatrace = { + version = "1.33.0" + source = "dynatrace-oss/dynatrace" + } + aws = { + source = "hashicorp/aws" + version = "5.1.0" + } + } +} + +provider "aws" { + region = var.aws_region +} + +provider "dynatrace" { + dt_env_url = var.dt_env_url + dt_api_token = var.dt_api_token +} diff --git a/environments/aws/ca-north-1/live/terraform.tfvars b/environments/aws/ca-north-1/live/terraform.tfvars index e69de29..3c328c8 100644 --- a/environments/aws/ca-north-1/live/terraform.tfvars +++ b/environments/aws/ca-north-1/live/terraform.tfvars @@ -0,0 +1,3 @@ +aws_region = "ca-north-1" + +dt_env_url = "https://console.eu.mon.vsds.swarm.audi/e/ /api" diff --git a/environments/aws/ca-north-1/live/variables.tf b/environments/aws/ca-north-1/live/variables.tf new file mode 100644 index 0000000..ebe6d48 --- /dev/null +++ b/environments/aws/ca-north-1/live/variables.tf @@ -0,0 +1,11 @@ +variable "aws_region" { + description = "The aws region to deploy in" +} + +variable "dt_env_url" { + description = "Dynatrace Environment URL" +} + +variable "dt_api_token" { + description = "Dynatrace API Token" +} diff --git a/environments/aws/ca-north-1/prelive/Jenkinsfile b/environments/aws/ca-north-1/prelive/Jenkinsfile new file mode 100644 index 0000000..0fb3732 --- /dev/null +++ b/environments/aws/ca-north-1/prelive/Jenkinsfile @@ -0,0 +1,113 @@ +String cloud_provider = "aws" +String aws_region = "ca-north-1" +String default_stage = "prelive" +String aws_access_credentials = "vsds_${aws_region}_${default_stage}_infrastructure.automation.user" +String dynatrace_api_token_credentials = "api_token_dynatrace_${aws_region}_${default_stage}" + + +pipeline { + agent { + node { + label 'vsds-terraform' + } + } + + environment { + GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + + AWS_ID = credentials("${aws_access_credentials}") + AWS_ACCESS_KEY_ID = "${env.AWS_ID_USR}" + AWS_SECRET_ACCESS_KEY = "${env.AWS_ID_PSW}" + + AWS_REGION = "${aws_region}" + STAGE = "${default_stage}" + CLOUD_PROVIDER = "${cloud_provider}" + + API_TOKEN = credentials("${dynatrace_api_token_credentials}") + TF_VAR_dt_api_token = "${env.API_TOKEN}" + } + + options { + timestamps() + ansiColor('xterm') + disableConcurrentBuilds(abortPrevious: true) + timeout(time: 1, unit: 'HOURS') + } + + stages { + stage('terraform init') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + sh """ + set -e + cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} + terraform init + """ + } + } + } + } + + stage('Terraform plan') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + script { + env.PLAN_STATUS = sh(script: "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} && terraform plan -out=.terraform/plan.out -input=false -detailed-exitcode", returnStatus: true) + if (env.PLAN_STATUS == "1") { + currentBuild.result = "FAILURE" + error('Aborting the build.') + return + } + + } + } + } + } + } + + stage('Interactive') { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + timeout(time: 15, unit: "MINUTES") { + input "Is this plan acceptable?" + milestone 1 + } + } + } + + stage("terraform apply") { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + container('terraform') { + sshagent(credentials: ['sofa-user-automation']) { + script { + sh "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} " + sh("terraform apply -input=false .terraform/plan.out") + } + } + } + } + } + } + + post { + always { + cleanWs() + + script { + currentBuild.result = currentBuild.result ?: 'SUCCESS' + notifyBitbucket() + } + } + } +} diff --git a/environments/aws/ca-north-1/prelive/provider.tf b/environments/aws/ca-north-1/prelive/provider.tf new file mode 100644 index 0000000..b3fecc3 --- /dev/null +++ b/environments/aws/ca-north-1/prelive/provider.tf @@ -0,0 +1,21 @@ +terraform { + required_providers { + dynatrace = { + version = "1.33.0" + source = "dynatrace-oss/dynatrace" + } + aws = { + source = "hashicorp/aws" + version = "5.1.0" + } + } +} + +provider "aws" { + region = var.aws_region +} + +provider "dynatrace" { + dt_env_url = var.dt_env_url + dt_api_token = var.dt_api_token +} diff --git a/environments/aws/ca-north-1/prelive/terraform.tfvars b/environments/aws/ca-north-1/prelive/terraform.tfvars index e69de29..d9055a3 100644 --- a/environments/aws/ca-north-1/prelive/terraform.tfvars +++ b/environments/aws/ca-north-1/prelive/terraform.tfvars @@ -0,0 +1,3 @@ +aws_region = "ca-north-1" + +dt_env_url = "https://console.prelive.eu.mon.vsds.swarm.audi/e/307daede-db0a-4f56-90db-8953368c3d29/api" diff --git a/environments/aws/ca-north-1/prelive/variables.tf b/environments/aws/ca-north-1/prelive/variables.tf new file mode 100644 index 0000000..ebe6d48 --- /dev/null +++ b/environments/aws/ca-north-1/prelive/variables.tf @@ -0,0 +1,11 @@ +variable "aws_region" { + description = "The aws region to deploy in" +} + +variable "dt_env_url" { + description = "Dynatrace Environment URL" +} + +variable "dt_api_token" { + description = "Dynatrace API Token" +} diff --git a/environments/aws/eu-west-1/int/Jenkinsfile b/environments/aws/eu-west-1/int/Jenkinsfile index d7f9609..1f71a41 100644 --- a/environments/aws/eu-west-1/int/Jenkinsfile +++ b/environments/aws/eu-west-1/int/Jenkinsfile @@ -43,7 +43,6 @@ pipeline { set -e cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} terraform init - terraform fmt """ } } @@ -55,9 +54,7 @@ pipeline { sshagent(credentials: ['sofa-user-automation']) { container('terraform') { script { - - sh "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} " - env.PLAN_STATUS = sh(script: "terraform plan -out=.terraform/plan.out -input=false -detailed-exitcode", returnStatus: true) + env.PLAN_STATUS = sh(script: "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} && terraform plan -out=.terraform/plan.out -input=false -detailed-exitcode", returnStatus: true) if (env.PLAN_STATUS == "1") { currentBuild.result = "FAILURE" error('Aborting the build.') @@ -100,7 +97,7 @@ pipeline { } } } - } + } } post { diff --git a/environments/aws/eu-west-1/live/Jenkinsfile b/environments/aws/eu-west-1/live/Jenkinsfile new file mode 100644 index 0000000..bddc08e --- /dev/null +++ b/environments/aws/eu-west-1/live/Jenkinsfile @@ -0,0 +1,113 @@ +String cloud_provider = "aws" +String aws_region = "eu-west-1" +String default_stage = "live" +String aws_access_credentials = "fdc_${aws_region}_${default_stage}_infrastructure.automation.user" +String dynatrace_api_token_credentials = "api_token_dynatrace_${aws_region}_${default_stage}" + + +pipeline { + agent { + node { + label 'vsds-terraform' + } + } + + environment { + GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + + AWS_ID = credentials("${aws_access_credentials}") + AWS_ACCESS_KEY_ID = "${env.AWS_ID_USR}" + AWS_SECRET_ACCESS_KEY = "${env.AWS_ID_PSW}" + + AWS_REGION = "${aws_region}" + STAGE = "${default_stage}" + CLOUD_PROVIDER = "${cloud_provider}" + + API_TOKEN = credentials("${dynatrace_api_token_credentials}") + TF_VAR_dt_api_token = "${env.API_TOKEN}" + } + + options { + timestamps() + ansiColor('xterm') + disableConcurrentBuilds(abortPrevious: true) + timeout(time: 1, unit: 'HOURS') + } + + stages { + stage('terraform init') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + sh """ + set -e + cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} + terraform init + """ + } + } + } + } + + stage('Terraform plan') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + script { + env.PLAN_STATUS = sh(script: "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} && terraform plan -out=.terraform/plan.out -input=false -detailed-exitcode", returnStatus: true) + if (env.PLAN_STATUS == "1") { + currentBuild.result = "FAILURE" + error('Aborting the build.') + return + } + + } + } + } + } + } + + stage('Interactive') { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + timeout(time: 15, unit: "MINUTES") { + input "Is this plan acceptable?" + milestone 1 + } + } + } + + stage("terraform apply") { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + container('terraform') { + sshagent(credentials: ['sofa-user-automation']) { + script { + sh "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} " + sh("terraform apply -input=false .terraform/plan.out") + } + } + } + } + } + } + + post { + always { + cleanWs() + + script { + currentBuild.result = currentBuild.result ?: 'SUCCESS' + notifyBitbucket() + } + } + } +} diff --git a/environments/aws/eu-west-1/live/provider.tf b/environments/aws/eu-west-1/live/provider.tf new file mode 100644 index 0000000..b3fecc3 --- /dev/null +++ b/environments/aws/eu-west-1/live/provider.tf @@ -0,0 +1,21 @@ +terraform { + required_providers { + dynatrace = { + version = "1.33.0" + source = "dynatrace-oss/dynatrace" + } + aws = { + source = "hashicorp/aws" + version = "5.1.0" + } + } +} + +provider "aws" { + region = var.aws_region +} + +provider "dynatrace" { + dt_env_url = var.dt_env_url + dt_api_token = var.dt_api_token +} diff --git a/environments/aws/eu-west-1/live/terraform.tfvars b/environments/aws/eu-west-1/live/terraform.tfvars index e69de29..39d9645 100644 --- a/environments/aws/eu-west-1/live/terraform.tfvars +++ b/environments/aws/eu-west-1/live/terraform.tfvars @@ -0,0 +1,3 @@ +aws_region = "eu-west-1" + +dt_env_url = "https://console.eu.mon.vsds.swarm.audi/e/ /api" diff --git a/environments/aws/eu-west-1/live/variables.tf b/environments/aws/eu-west-1/live/variables.tf new file mode 100644 index 0000000..ebe6d48 --- /dev/null +++ b/environments/aws/eu-west-1/live/variables.tf @@ -0,0 +1,11 @@ +variable "aws_region" { + description = "The aws region to deploy in" +} + +variable "dt_env_url" { + description = "Dynatrace Environment URL" +} + +variable "dt_api_token" { + description = "Dynatrace API Token" +} diff --git a/environments/aws/eu-west-1/prelive/Jenkinsfile b/environments/aws/eu-west-1/prelive/Jenkinsfile new file mode 100644 index 0000000..640fe72 --- /dev/null +++ b/environments/aws/eu-west-1/prelive/Jenkinsfile @@ -0,0 +1,113 @@ +String cloud_provider = "aws" +String aws_region = "eu-west-1" +String default_stage = "prelive" +String aws_access_credentials = "fdc_${aws_region}_${default_stage}_infrastructure.automation.user" +String dynatrace_api_token_credentials = "api_token_dynatrace_${aws_region}_${default_stage}" + + +pipeline { + agent { + node { + label 'vsds-terraform' + } + } + + environment { + GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + + AWS_ID = credentials("${aws_access_credentials}") + AWS_ACCESS_KEY_ID = "${env.AWS_ID_USR}" + AWS_SECRET_ACCESS_KEY = "${env.AWS_ID_PSW}" + + AWS_REGION = "${aws_region}" + STAGE = "${default_stage}" + CLOUD_PROVIDER = "${cloud_provider}" + + API_TOKEN = credentials("${dynatrace_api_token_credentials}") + TF_VAR_dt_api_token = "${env.API_TOKEN}" + } + + options { + timestamps() + ansiColor('xterm') + disableConcurrentBuilds(abortPrevious: true) + timeout(time: 1, unit: 'HOURS') + } + + stages { + stage('terraform init') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + sh """ + set -e + cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} + terraform init + """ + } + } + } + } + + stage('Terraform plan') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + script { + env.PLAN_STATUS = sh(script: "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} && terraform plan -out=.terraform/plan.out -input=false -detailed-exitcode", returnStatus: true) + if (env.PLAN_STATUS == "1") { + currentBuild.result = "FAILURE" + error('Aborting the build.') + return + } + + } + } + } + } + } + + stage('Interactive') { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + timeout(time: 15, unit: "MINUTES") { + input "Is this plan acceptable?" + milestone 1 + } + } + } + + stage("terraform apply") { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + container('terraform') { + sshagent(credentials: ['sofa-user-automation']) { + script { + sh "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} " + sh("terraform apply -input=false .terraform/plan.out") + } + } + } + } + } + } + + post { + always { + cleanWs() + + script { + currentBuild.result = currentBuild.result ?: 'SUCCESS' + notifyBitbucket() + } + } + } +} diff --git a/environments/aws/eu-west-1/prelive/module.tf b/environments/aws/eu-west-1/prelive/module.tf deleted file mode 100644 index 1cd621c..0000000 --- a/environments/aws/eu-west-1/prelive/module.tf +++ /dev/null @@ -1,3 +0,0 @@ -resource "dynatrace_audit_log" "test" { - enabled = false -} \ No newline at end of file diff --git a/environments/aws/eu-west-1/prelive/provider.tf b/environments/aws/eu-west-1/prelive/provider.tf index 7024448..b3fecc3 100644 --- a/environments/aws/eu-west-1/prelive/provider.tf +++ b/environments/aws/eu-west-1/prelive/provider.tf @@ -1,7 +1,7 @@ terraform { required_providers { dynatrace = { - version = "1.31.0" + version = "1.33.0" source = "dynatrace-oss/dynatrace" } aws = { @@ -13,4 +13,9 @@ terraform { provider "aws" { region = var.aws_region -} \ No newline at end of file +} + +provider "dynatrace" { + dt_env_url = var.dt_env_url + dt_api_token = var.dt_api_token +} diff --git a/environments/aws/eu-west-1/prelive/terraform.tfvars b/environments/aws/eu-west-1/prelive/terraform.tfvars index 34b5a09..a46d57a 100644 --- a/environments/aws/eu-west-1/prelive/terraform.tfvars +++ b/environments/aws/eu-west-1/prelive/terraform.tfvars @@ -1,13 +1,3 @@ -stack = "acdc" -stage = "prelive" -name = "dynatrace-prelive" - aws_region = "eu-west-1" -tags = { - "Managed_By" : "NTT_team" -} - -kms = { - "s3" = "arn:aws:kms:eu-west-1:248567303878:key/8d860956-4033-4782-ab30-6cb84b31964e" -} \ No newline at end of file +dt_env_url = "https://console.prelive.eu.mon.vsds.swarm.audi/e/dfe67e08-75f1-4c0f-9433-16af192faf88/api" diff --git a/environments/aws/eu-west-1/prelive/variables.tf b/environments/aws/eu-west-1/prelive/variables.tf index f7a3863..ebe6d48 100644 --- a/environments/aws/eu-west-1/prelive/variables.tf +++ b/environments/aws/eu-west-1/prelive/variables.tf @@ -2,29 +2,10 @@ variable "aws_region" { description = "The aws region to deploy in" } -variable "name" { - description = "Name to be used on all the resources as identifier" - type = string - default = "" +variable "dt_env_url" { + description = "Dynatrace Environment URL" } -variable "stack" { - description = "Environment stack" - default = "vsds" +variable "dt_api_token" { + description = "Dynatrace API Token" } - -variable "stage" { - description = "Environment stage" -} - -variable "tags" { - description = "A map of tags to add to all resources" - type = map(string) - default = {} -} - -variable "kms" { - description = "A map of kms keys to be used for any resources." - type = map(string) - default = {} -} \ No newline at end of file diff --git a/environments/aws/us-east-1/live/Jenkinsfile b/environments/aws/us-east-1/live/Jenkinsfile new file mode 100644 index 0000000..e504e0f --- /dev/null +++ b/environments/aws/us-east-1/live/Jenkinsfile @@ -0,0 +1,113 @@ +String cloud_provider = "aws" +String aws_region = "us-east-1" +String default_stage = "live" +String aws_access_credentials = "fdc_${aws_region}_${default_stage}_infrastructure.automation.user" +String dynatrace_api_token_credentials = "api_token_dynatrace_${aws_region}_${default_stage}" + + +pipeline { + agent { + node { + label 'vsds-terraform' + } + } + + environment { + GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + + AWS_ID = credentials("${aws_access_credentials}") + AWS_ACCESS_KEY_ID = "${env.AWS_ID_USR}" + AWS_SECRET_ACCESS_KEY = "${env.AWS_ID_PSW}" + + AWS_REGION = "${aws_region}" + STAGE = "${default_stage}" + CLOUD_PROVIDER = "${cloud_provider}" + + API_TOKEN = credentials("${dynatrace_api_token_credentials}") + TF_VAR_dt_api_token = "${env.API_TOKEN}" + } + + options { + timestamps() + ansiColor('xterm') + disableConcurrentBuilds(abortPrevious: true) + timeout(time: 1, unit: 'HOURS') + } + + stages { + stage('terraform init') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + sh """ + set -e + cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} + terraform init + """ + } + } + } + } + + stage('Terraform plan') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + script { + env.PLAN_STATUS = sh(script: "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} && terraform plan -out=.terraform/plan.out -input=false -detailed-exitcode", returnStatus: true) + if (env.PLAN_STATUS == "1") { + currentBuild.result = "FAILURE" + error('Aborting the build.') + return + } + + } + } + } + } + } + + stage('Interactive') { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + timeout(time: 15, unit: "MINUTES") { + input "Is this plan acceptable?" + milestone 1 + } + } + } + + stage("terraform apply") { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + container('terraform') { + sshagent(credentials: ['sofa-user-automation']) { + script { + sh "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} " + sh("terraform apply -input=false .terraform/plan.out") + } + } + } + } + } + } + + post { + always { + cleanWs() + + script { + currentBuild.result = currentBuild.result ?: 'SUCCESS' + notifyBitbucket() + } + } + } +} diff --git a/environments/aws/us-east-1/live/provider.tf b/environments/aws/us-east-1/live/provider.tf new file mode 100644 index 0000000..b3fecc3 --- /dev/null +++ b/environments/aws/us-east-1/live/provider.tf @@ -0,0 +1,21 @@ +terraform { + required_providers { + dynatrace = { + version = "1.33.0" + source = "dynatrace-oss/dynatrace" + } + aws = { + source = "hashicorp/aws" + version = "5.1.0" + } + } +} + +provider "aws" { + region = var.aws_region +} + +provider "dynatrace" { + dt_env_url = var.dt_env_url + dt_api_token = var.dt_api_token +} diff --git a/environments/aws/us-east-1/live/terraform.tfvars b/environments/aws/us-east-1/live/terraform.tfvars index e69de29..4a87a27 100644 --- a/environments/aws/us-east-1/live/terraform.tfvars +++ b/environments/aws/us-east-1/live/terraform.tfvars @@ -0,0 +1,3 @@ +aws_region = "us-east-1" + +dt_env_url = "" diff --git a/environments/aws/us-east-1/live/variables.tf b/environments/aws/us-east-1/live/variables.tf new file mode 100644 index 0000000..ebe6d48 --- /dev/null +++ b/environments/aws/us-east-1/live/variables.tf @@ -0,0 +1,11 @@ +variable "aws_region" { + description = "The aws region to deploy in" +} + +variable "dt_env_url" { + description = "Dynatrace Environment URL" +} + +variable "dt_api_token" { + description = "Dynatrace API Token" +} diff --git a/environments/aws/us-east-1/prelive/Jenkinsfile b/environments/aws/us-east-1/prelive/Jenkinsfile new file mode 100644 index 0000000..b4913f6 --- /dev/null +++ b/environments/aws/us-east-1/prelive/Jenkinsfile @@ -0,0 +1,113 @@ +String cloud_provider = "aws" +String aws_region = "us-east-1" +String default_stage = "prelive" +String aws_access_credentials = "fdc_${aws_region}_${default_stage}_infrastructure.automation.user" +String dynatrace_api_token_credentials = "api_token_dynatrace_${aws_region}_${default_stage}" + + +pipeline { + agent { + node { + label 'vsds-terraform' + } + } + + environment { + GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + + AWS_ID = credentials("${aws_access_credentials}") + AWS_ACCESS_KEY_ID = "${env.AWS_ID_USR}" + AWS_SECRET_ACCESS_KEY = "${env.AWS_ID_PSW}" + + AWS_REGION = "${aws_region}" + STAGE = "${default_stage}" + CLOUD_PROVIDER = "${cloud_provider}" + + API_TOKEN = credentials("${dynatrace_api_token_credentials}") + TF_VAR_dt_api_token = "${env.API_TOKEN}" + } + + options { + timestamps() + ansiColor('xterm') + disableConcurrentBuilds(abortPrevious: true) + timeout(time: 1, unit: 'HOURS') + } + + stages { + stage('terraform init') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + sh """ + set -e + cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} + terraform init + """ + } + } + } + } + + stage('Terraform plan') { + steps { + sshagent(credentials: ['sofa-user-automation']) { + container('terraform') { + script { + env.PLAN_STATUS = sh(script: "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} && terraform plan -out=.terraform/plan.out -input=false -detailed-exitcode", returnStatus: true) + if (env.PLAN_STATUS == "1") { + currentBuild.result = "FAILURE" + error('Aborting the build.') + return + } + + } + } + } + } + } + + stage('Interactive') { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + timeout(time: 15, unit: "MINUTES") { + input "Is this plan acceptable?" + milestone 1 + } + } + } + + stage("terraform apply") { + when { + allOf { + expression { env.PLAN_STATUS == "2" } + } + } + steps { + container('terraform') { + sshagent(credentials: ['sofa-user-automation']) { + script { + sh "cd environments/${CLOUD_PROVIDER}/${AWS_REGION}/${STAGE} " + sh("terraform apply -input=false .terraform/plan.out") + } + } + } + } + } + } + + post { + always { + cleanWs() + + script { + currentBuild.result = currentBuild.result ?: 'SUCCESS' + notifyBitbucket() + } + } + } +} diff --git a/environments/aws/us-east-1/prelive/module.tf b/environments/aws/us-east-1/prelive/module.tf deleted file mode 100644 index 1cd621c..0000000 --- a/environments/aws/us-east-1/prelive/module.tf +++ /dev/null @@ -1,3 +0,0 @@ -resource "dynatrace_audit_log" "test" { - enabled = false -} \ No newline at end of file diff --git a/environments/aws/us-east-1/prelive/provider.tf b/environments/aws/us-east-1/prelive/provider.tf index 7024448..b3fecc3 100644 --- a/environments/aws/us-east-1/prelive/provider.tf +++ b/environments/aws/us-east-1/prelive/provider.tf @@ -1,7 +1,7 @@ terraform { required_providers { dynatrace = { - version = "1.31.0" + version = "1.33.0" source = "dynatrace-oss/dynatrace" } aws = { @@ -13,4 +13,9 @@ terraform { provider "aws" { region = var.aws_region -} \ No newline at end of file +} + +provider "dynatrace" { + dt_env_url = var.dt_env_url + dt_api_token = var.dt_api_token +} diff --git a/environments/aws/us-east-1/prelive/terraform.tfvars b/environments/aws/us-east-1/prelive/terraform.tfvars index 42bd232..5d6da33 100644 --- a/environments/aws/us-east-1/prelive/terraform.tfvars +++ b/environments/aws/us-east-1/prelive/terraform.tfvars @@ -1,13 +1,3 @@ -stack = "acdc" -stage = "prelive" -name = "dynatrace-prelive" - aws_region = "us-east-1" -tags = { - "Managed_By" : "NTT_team" -} - -kms = { - "s3" = "arn:aws:kms:eu-west-1:248567303878:key/8d860956-4033-4782-ab30-6cb84b31964e" -} \ No newline at end of file +dt_env_url = "https://console.prelive.eu.mon.vsds.swarm.audi/e/e7acd689-2169-4b83-aace-8c4e75c67446/api" diff --git a/environments/aws/us-east-1/prelive/variables.tf b/environments/aws/us-east-1/prelive/variables.tf index f7a3863..ebe6d48 100644 --- a/environments/aws/us-east-1/prelive/variables.tf +++ b/environments/aws/us-east-1/prelive/variables.tf @@ -2,29 +2,10 @@ variable "aws_region" { description = "The aws region to deploy in" } -variable "name" { - description = "Name to be used on all the resources as identifier" - type = string - default = "" +variable "dt_env_url" { + description = "Dynatrace Environment URL" } -variable "stack" { - description = "Environment stack" - default = "vsds" +variable "dt_api_token" { + description = "Dynatrace API Token" } - -variable "stage" { - description = "Environment stage" -} - -variable "tags" { - description = "A map of tags to add to all resources" - type = map(string) - default = {} -} - -variable "kms" { - description = "A map of kms keys to be used for any resources." - type = map(string) - default = {} -} \ No newline at end of file