VSDSCP-212 Initial Commit

master
Javier Carrera 2023-06-07 08:56:00 +02:00
commit b882c46a57
11 changed files with 293 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
.terraform
.terraform.lock.hcl
*.tfstate
*.tfstate.backup
id_rsa
id_rsa.pub
.idea
.DS_Store
.iml

0
README.md Normal file
View File

View File

@ -0,0 +1 @@
1.4.5

101
eu/prelive/Jenkinsfile vendored Normal file
View File

@ -0,0 +1,101 @@
String release = "${env.RELEASE_VERSION ?: "SNAPSHOT"}"
String tag = "modules-aws-$release"
def modules_paths = [
"eu/prelive",
]
def terraform_check(paths) {
paths.each { path ->
sh("terraform -chdir=${path} init -backend=false")
sh("terraform -chdir=${path} fmt -recursive --check")
}
}
pipeline {
agent {
node {
label 'vsds-terraform'
}
}
environment {
GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
}
options {
timestamps()
ansiColor('xterm')
disableConcurrentBuilds(abortPrevious: true)
timeout(time: 1, unit: 'HOURS')
}
stages {
stage("Check Tag") {
when { expression { !release.equals("SNAPSHOT") } }
steps {
sshagent(credentials: ['sofa-user-automation']) {
script {
env.PLAN_STATUS = sh(script: """
| if [[ "\$(git ls-remote origin 2>/dev/null | grep 'refs/tags/$tag\$')" ]]; then
| echo "Release $tag exists"
| exit 1
| fi
""".stripMargin('| '), returnStatus: true)
if (env.PLAN_STATUS == "1") {
currentBuild.result = "FAILURE"
error('Aborting the build.')
return
}
}
}
}
}
stage('Terraform validate') {
steps {
container('terraform') {
sshagent(credentials: ['sofa-user-automation']) {
script {
terraform_check(modules_paths)
}
}
}
}
}
stage('Terraform plan') {
steps {
container('terraform') {
sshagent(credentials: ['sofa-user-automation']) {
sh 'terraform plan'
}
}
}
}
stage('Create tag') {
when { expression { !release.equals("SNAPSHOT") } }
steps {
sshagent(credentials: ['sofa-user-automation']) {
sh """
| git tag $tag
| git push origin $tag
""".stripMargin('| ')
}
}
}
}
post {
always {
cleanWs()
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
notifyBitbucket(projectKey: 'modules')
}
}
}
}

10
eu/prelive/backend.tf Normal file
View File

@ -0,0 +1,10 @@
terraform {
backend "s3" {
bucket = "acdc-eu-west-1-prelive-tfstate"
key = "acdc/dynatrace/bootstrap.tfstate"
region = "eu-west-1"
encrypt = true
kms_key_id = "arn:aws:kms:eu-west-1:248567303878:key/8d860956-4033-4782-ab30-6cb84b31964e" #AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, kms-key
# dynamodb_table = "acdc-eu-west-1-prelive-tfstate-lock"
}
}

12
eu/prelive/module.tf Normal file
View File

@ -0,0 +1,12 @@
module "s3-dynatrace" {
source = "git::ssh://git@collaboration.msi.audi.com:4444/vsdsinf/vsds-terraform-modules.git//modules/aws/marketplace/s3?ref=1.4.3"
name = format("%s-%s-%s-dynatrace", var.stack, var.aws_region, var.stage)
kms_key_arn = var.kms["s3"]
tags = merge(
var.tags,
{
Namespace = "platform"
},
)
}

8
eu/prelive/provider.tf Normal file
View File

@ -0,0 +1,8 @@
terraform {
required_providers {
dynatrace = {
version = "1.31.0"
source = "dynatrace-oss/dynatrace"
}
}
}

View File

@ -0,0 +1,15 @@
# AUTO GENERATED, DON'T MODIFY
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"
}

32
eu/prelive/variables.tf Normal file
View File

@ -0,0 +1,32 @@
# AUTO GENERATED, DON'T MODIFY
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 "stack" {
description = "Environment stack"
default = "vsds"
}
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 = {}
}

91
modules/aws/Jenkinsfile vendored Normal file
View File

@ -0,0 +1,91 @@
String release = "${env.RELEASE_VERSION ?: "SNAPSHOT"}"
String tag = "modules-aws-$release"
def modules_paths = [
"modules/aws/dynatrace",
]
def terraform_check(paths) {
paths.each { path ->
sh("terraform -chdir=${path} init -backend=false")
sh("terraform -chdir=${path} fmt -recursive --check")
}
}
pipeline {
agent {
node {
label 'vsds-terraform'
}
}
environment {
GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
}
options {
timestamps()
ansiColor('xterm')
disableConcurrentBuilds(abortPrevious: true)
timeout(time: 1, unit: 'HOURS')
}
stages {
stage("Check Tag") {
when { expression { !release.equals("SNAPSHOT") } }
steps {
sshagent(credentials: ['sofa-user-automation']) {
script {
env.PLAN_STATUS = sh(script: """
| if [[ "\$(git ls-remote origin 2>/dev/null | grep 'refs/tags/$tag\$')" ]]; then
| echo "Release $tag exists"
| exit 1
| fi
""".stripMargin('| '), returnStatus: true)
if (env.PLAN_STATUS == "1") {
currentBuild.result = "FAILURE"
error('Aborting the build.')
return
}
}
}
}
}
stage('Terraform validate') {
steps {
container('terraform') {
sshagent(credentials: ['sofa-user-automation']) {
script {
terraform_check(modules_paths)
}
}
}
}
}
stage('Create tag') {
when { expression { !release.equals("SNAPSHOT") } }
steps {
sshagent(credentials: ['sofa-user-automation']) {
sh """
| git tag $tag
| git push origin $tag
""".stripMargin('| ')
}
}
}
}
post {
always {
cleanWs()
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
notifyBitbucket(projectKey: 'modules')
}
}
}
}

View File

@ -0,0 +1,14 @@
variable "name" {
description = "Name to be used on all the resources as identifier"
type = string
}
variable "stage" {
description = "Environment stage"
type = string
}
variable "region" {
type = string
description = "The aws region to deploy in"
}