Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circleci editor/master #12

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
version: 2.1
orbs:
terraform: circleci/[email protected]

jobs:
plan-apply:
working_directory: /tmp/project
docker:
- image: docker.mirror.hashicorp.services/hashicorp/terraform:light
steps:
- checkout
- run:
name: terraform init & plan
command: |
terraform init -input=false
terraform plan
- persist_to_workspace:
root: .
paths:
- .

apply:
docker:
- image: docker.mirror.hashicorp.services/hashicorp/terraform:light
steps:
- attach_workspace:
at: .
- run:
name: terraform
command: |
terraform apply -auto-approve
- persist_to_workspace:
root: .
paths:
- .

plan-destroy:
docker:
- image: docker.mirror.hashicorp.services/hashicorp/terraform:light
steps:
- attach_workspace:
at: .
- run:
name: terraform create destroy plan
command: |
terraform plan -destroy -out tfdestroy -var-file variables.tfvars
- persist_to_workspace:
root: .
paths:
- .

destroy:
docker:
- image: docker.mirror.hashicorp.services/hashicorp/terraform:light
steps:
- attach_workspace:
at: .
- run:
name: terraform destroy
command: |
terraform apply -auto-approve

workflows:
version: 2
plan_approve_apply:
jobs:
- plan-apply
- hold-apply:
type: approval
requires:
- plan-apply
- apply:
requires:
- hold-apply
- plan-destroy:
requires:
- apply
- hold-destroy:
type: approval
requires:
- plan-destroy
- destroy:
requires:
- hold-destroy
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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*
20 changes: 20 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
version: 2

jobs:
plan-apply:
working_directory: /tmp/project
docker:
- image: docker.mirror.hashicorp.services/hashicorp/terraform:light
steps:
- checkout
- run:
name: terraform init & plan
command: |
terraform init -input=false
terraform plan -out tfapply -var-file variables.tfvars
- persist_to_workspace:
root: .
paths:
- .

apply:
docker:
- image: docker.mirror.hashicorp.services/hashicorp/terraform:light
steps:
- attach_workspace:
at: .
- run:
name: terraform
command: |
terraform apply -auto-approve tfapply
- persist_to_workspace:
root: .
paths:
- .

plan-destroy:
docker:
- image: docker.mirror.hashicorp.services/hashicorp/terraform:light
steps:
- attach_workspace:
at: .
- run:
name: terraform create destroy plan
command: |
terraform plan -destroy -out tfdestroy -var-file variables.tfvars
- persist_to_workspace:
root: .
paths:
- .

destroy:
docker:
- image: docker.mirror.hashicorp.services/hashicorp/terraform:light
steps:
- attach_workspace:
at: .
- run:
name: terraform destroy
command: |
terraform apply -auto-approve tfdestroy

workflows:
version: 2
plan_approve_apply:
jobs:
- plan-apply
- hold-apply:
type: approval
requires:
- plan-apply
- apply:
requires:
- hold-apply
- plan-destroy:
requires:
- apply
- hold-destroy:
type: approval
requires:
- plan-destroy
- destroy:
requires:
- hold-destroy
29 changes: 29 additions & 0 deletions Section 1 - Deploying Infrastructure with Terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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*

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 0 additions & 31 deletions Section 1 - Deploying Infrastructure with Terraform/first-ec2.md

This file was deleted.

53 changes: 53 additions & 0 deletions Section 1 - Deploying Infrastructure with Terraform/first-ec2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Important Note

Note that every region has a different AMI ID. The AMI ID's keeps on changing so make sure you use the latest AMI ID from the AWS console similar to the way it is shown in the video.

Documentation Referred:

https://registry.terraform.io/

https://registry.terraform.io/providers/hashicorp/aws/latest/docs


first_ec2.tf
Configure the AWS Provider
*/

provider "aws" {
region = "us-west-2" # Oregon
}

data "aws_ami" "ubuntu" {
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["099720109477"] # Canonical
}

resource "aws_key_pair" "deployer" {
key_name = "tf-packer"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCu1VZLS3dXyzg0whw9NlqboZg53ZY+1SOORWfqgJ31NWP7RNe6hoo+WpYTzZ1q1rWqMGu6vLpTPOgtvEzdIFC1mmcJDsgSFD01H4a5dfcnvMMLwYeEjR68KeNGTOCYTIMXdTVGlqgJzagwKdWfdsck1raVjBQM5ZEl7r5EiRRMTFWN5XVQ6v0rK1BI7VPgd2e2FJ26/8KGRdN7RQVPvGZ7JFtW+osRJ/XgRtbF9eVZoK6r/5jTUAv/esTK24lYqwDxfDZkQDG2AEaCsQysiKfjBWAiWbe2OMpKpVpDvbkNVnXp5G+gSKIO6DhwCucCHWqsV8hIwvDvj3LmglD7nP5uA8vrPE3UwOg3RQLm2ajYlMjVEDWxvt4ObX0QUhS9GrblUslKhFcmz6NiEmBMEjDmk4C8KW7SO8wsshMPR/XJKLI8WnJxAhqdKrZy1iAb0tEo9hEDjP17lj+5YFm7qIrYW1ahXt8drHRONMt/XZcmPLOslIXHOSSE6UN5K+rGcyE= [email protected]"

tags = {
Name = "Section 1 - Deploying Infrastructure with Terraform"
}
}

resource "aws_instance" "server0" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"

tags = {
Name = "Section 1 - Deploying Infrastructure with Terraform"
}
# user_data = filebase64("${path.module}/example.sh")
}
Loading