forked from KyMidd/AzureDevOps_TerraformPipeline_YML
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 12e69e5
Showing
3 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## | ||
# Terraform repo .gitignore | ||
# Source: https://github.com/github/gitignore/blob/master/Terraform.gitignore | ||
## | ||
|
||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
|
||
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most | ||
# .tfvars files are managed as part of configuration and so should be included in | ||
# version control. | ||
# | ||
# example.tfvars | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Terraform release pipeline | ||
variables: | ||
tf_directory: '$(System.DefaultWorkingDirectory)/terraform/envA' | ||
secure_file_name: 'terraform-secure-file.auto.tfvars' | ||
terraform_version: '0.12.18' | ||
pool: 'AWS-Pool' | ||
|
||
# Release instructions | ||
stages: | ||
- stage: Terraform_Plan | ||
jobs: | ||
- deployment: Terraform_Plan | ||
displayName: Terraform Plan | ||
pool: $(pool) | ||
continueOnError: 'false' | ||
environment: 'TerraformPlan_Environment' | ||
strategy: | ||
runOnce: | ||
deploy: | ||
steps: | ||
- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-installer.TerraformInstaller@0 | ||
displayName: 'Install Terraform' | ||
inputs: | ||
terraformVersion: $(terraform_version) | ||
|
||
- task: DownloadSecureFile@1 | ||
displayName: 'Download secure file' | ||
inputs: | ||
secureFile: $(secure_file_name) | ||
|
||
- task: CopyFiles@2 | ||
displayName: 'Stage secure files' | ||
inputs: | ||
SourceFolder: '$(Agent.TempDirectory)' | ||
Contents: '*.tfvars' | ||
TargetFolder: $(tf_directory) | ||
|
||
- task: Bash@3 | ||
displayName: 'Terraform Init' | ||
inputs: | ||
targetType: 'inline' | ||
script: 'terraform init -input=false' | ||
workingDirectory: $(tf_directory) | ||
failOnStderr: true | ||
|
||
- task: Bash@3 | ||
displayName: 'Terraform Validation' | ||
inputs: | ||
targetType: 'inline' | ||
script: 'terraform validate' | ||
workingDirectory: $(tf_directory) | ||
failOnStderr: true | ||
|
||
- task: Bash@3 | ||
displayName: 'Terraform Plan' | ||
inputs: | ||
targetType: 'inline' | ||
script: 'terraform plan -lock=false -input=false' | ||
workingDirectory: $(tf_directory) | ||
failOnStderr: true | ||
|
||
- stage: Terraform_Apply | ||
jobs: | ||
- deployment: Terraform_Apply | ||
displayName: Terraform Apply | ||
pool: $(pool) | ||
continueOnError: 'false' | ||
# Run this stage if previous stage(s) succeeded and build reason ISN'T a pull request | ||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) | ||
environment: 'YamlTerraformApplyEnvironment' | ||
strategy: | ||
runOnce: | ||
deploy: | ||
steps: | ||
- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-installer.TerraformInstaller@0 | ||
displayName: 'Install Terraform' | ||
inputs: | ||
terraformVersion: $(terraform_version) | ||
|
||
- task: DownloadSecureFile@1 | ||
displayName: 'Download secure file' | ||
inputs: | ||
secureFile: $(secure_file_name) | ||
|
||
- task: CopyFiles@2 | ||
displayName: 'Stage secure files' | ||
inputs: | ||
SourceFolder: '$(Agent.TempDirectory)' | ||
Contents: '*.tfvars' | ||
TargetFolder: $(tf_directory) | ||
|
||
- task: Bash@3 | ||
displayName: 'Terraform Init' | ||
inputs: | ||
targetType: 'inline' | ||
script: 'terraform init -input=false' | ||
workingDirectory: $(tf_directory) | ||
failOnStderr: true | ||
|
||
- task: Bash@3 | ||
displayName: 'Terraform Apply' | ||
inputs: | ||
targetType: 'inline' | ||
script: 'terraform apply -auto-approve -input=false' | ||
workingDirectory: $(tf_directory) | ||
failOnStderr: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Require TF version to most recent | ||
terraform { | ||
required_version = "~> 0.12.18" | ||
} | ||
|
||
# Download any stable version in AWS provider of 2.27.0 or higher | ||
provider "aws" { | ||
version = "~> 2.27.0" | ||
region = "us-east-1" | ||
} | ||
|
||
# Build the VPC | ||
resource "aws_vpc" "vpc" { | ||
cidr_block = "10.1.0.0/16" | ||
instance_tenancy = "default" | ||
|
||
tags = { | ||
Name = "Vpc" | ||
Terraform = "true" | ||
} | ||
} | ||
|
||
# Build route table 1 | ||
resource "aws_route_table" "route_table1" { | ||
vpc_id = aws_vpc.vpc.id | ||
|
||
tags = { | ||
Name = "RouteTable1" | ||
Terraform = "true" | ||
} | ||
} | ||
|
||
# Build route table 2 | ||
resource "aws_route_table" "route_table2" { | ||
vpc_id = aws_vpc.vpc.id | ||
|
||
tags = { | ||
Name = "RouteTable2" | ||
Terraform = "true" | ||
} | ||
} |