Skip to content

Commit

Permalink
Terraform V12 Windows-2016 Server with Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
quickbooks2018 committed May 30, 2020
1 parent 81843f3 commit 912604a
Show file tree
Hide file tree
Showing 37 changed files with 2,099 additions and 0 deletions.
141 changes: 141 additions & 0 deletions terraform.v12/vpc+windows/Terraform Important Commands.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
a. terraform init
b. terraform plan
c terraform apply


1. terraform destroy -target resource_type.resource_logical_name

2. terraform get -update=true

3. terraform output -module=module-name

4.terraform plan -target=module.cloudgeeks.ca-vpc ---> only plan specific modules

5.terraform apply -target=module.cloudgeeks.ca-vpc ---> only apply specific modules

6.terraform state pull----> ok

7.terraform state push---->danger

8.terraform state rm module.cloudgeeks.ca-rds-app1 ----> https://stackoverflow.com/questions/43950097/how-to-import-manual-changes-into-terraform-remote-state

9.terraform show ---> see after deployment

10. terraform state list

#Note: Pull directly from git hub

#https://www.terraform.io/docs/modules/sources.html

11. source = "github.com/quickbooks2018/Terraform-Classic-Modules/modules/vpc"

# ssh generate public key from a private key

12. ssh-keygen -y -f terraform.pem > terraform.pub

13. terraform apply -var-file=dmz.tfvars

14. terraform destroy -var-file=dmz.tfvars

15. terraform import -var-file=dmz.tfvars module.sg7.aws_security_group.security_group sg-00afc6e255cc55387

16. terraform plan -var-file=secrets.tfvars -var-file=dmz.tfvars -target=module.directory-service -out plan



#############################################################################################################

List the Terraform commands:

terraform
Common commands:
apply: Builds or changes infrastructure
console: Interactive console for Terraform interpolations
destroy: Destroys Terraform-managed infrastructure
fmt: Rewrites configuration files to canonical format
get: Downloads and installs modules for the configuration
graph: Creates a visual graph of Terraform resources
import: Imports existing infrastructure into Terraform
init: Initializes a new or existing Terraform configuration
output: Reads an output from a state file
plan: Generates and shows an execution plan
providers: Prints a tree of the providers used in the configuration
push: Uploads this Terraform module to Terraform Enterprise to run
refresh: Updates local state file against real resources
show: Inspects Terraform state or plan
taint: Manually marks a resource for recreation
untaint: Manually unmarks a resource as tainted
validate: Validates the Terraform files
version: Prints the Terraform version
workspace: Workspace management

Set up the environment:

mkdir -p terraform/basics
cd terraform/basics
Create a Terraform script:

vi main.tf
main.tf contents:

# Download the latest Ghost image
resource "docker_image" "image_id" {
name = "ghost:latest"
}
Initialize Terraform:

terraform init
Validate the Terraform file:

terraform validate
List providers in the folder:

ls .terraform/plugins/linux_amd64/
List providers used in the configuration:

terraform providers
Terraform Plan:

terraform plan
Useful flags for plan:
-out=path: Writes a plan file to the given path. This can be used as input to the "apply" command.
-var 'foo=bar': Set a variable in the Terraform configuration. This flag can be set multiple times.

Terraform Apply:

terraform apply
Useful flags for apply:
-auto-approve: This skips interactive approval of plan before applying.
-var 'foo=bar': This sets a variable in the Terraform configuration. It can be set multiple times.

Confirm your apply by typing yes. The apply will take a bit to complete.

List the Docker images:

docker image ls
Terraform Show:

terraform show
Terraform Destroy:

terraform destroy
Confirm your destroy by typing yes.

Useful flags for destroys:
-auto-approve: Skip interactive approval of plan before applying.

Re-list the Docker images:

docker image ls
Using a plan:

terraform plan -out=tfplan
Applying a plan:

terraform apply tfplan
Show the Docker Image resource:

terraform show
Destroy the resource once again:

terraform destroy
71 changes: 71 additions & 0 deletions terraform.v12/vpc+windows/aws/environment/dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
provider "aws" {
region = "us-east-1"
}

#####
# Vpc
#####

module "vpc" {
source = "../../modules/aws-vpc"

vpc-location = "Virginia"
namespace = "cloudgeeks.ca"
name = "vpc"
stage = "windows-dev"
map_public_ip_on_launch = "true"
total-nat-gateway-required = "1"
create_database_subnet_group = "false"
vpc-cidr = "10.20.0.0/16"
vpc-public-subnet-cidr = ["10.20.1.0/24","10.20.2.0/24","10.20.3.0/24","10.20.4.0/24"]
vpc-private-subnet-cidr = ["10.20.6.0/24","10.20.7.0/24"]
vpc-database_subnets-cidr = ["10.20.8.0/24", "10.20.9.0/24"]
}


module "sg1" {
source = "../../modules/aws-sg-cidr"
namespace = "cloudgeeks.ca"
stage = "dev"
name = "windows"
tcp_ports = "3389"
cidrs = ["111.119.187.3/32"]
security_group_name = "windows"
vpc_id = module.vpc.vpc-id
}

module "sg2" {
source = "../../modules/aws-sg-ref-v2"
namespace = "cloudgeeks.ca"
stage = "dev"
name = "windows-Ref"
tcp_ports = "3389,80,443"
ref_security_groups_ids = [module.sg1.aws_security_group_default,module.sg1.aws_security_group_default,module.sg1.aws_security_group_default]
security_group_name = "windows-Ref"
vpc_id = module.vpc.vpc-id
}


module "ec2-keypair" {
source = "../../modules/aws-ec2-keypair"
key-name = "windows"
public-key = file("../../modules/secrets/windows.pub")
}

module "ec2-windows" {
source = "../../modules/aws-ec2"
namespace = "cloudgeeks.ca"
stage = "dev"
name = "windows"
key_name = "windows"
user_data = file("../../modules/aws-ec2/user-data/windows/user-data")
instance_count = 4
ami = "ami-0cc5ea3dde5301489"
instance_type = "t3a.medium"
associate_public_ip_address = "true"
root_volume_size = 35
subnet_ids = module.vpc.public-subnet-ids
vpc_security_group_ids = [module.sg1.aws_security_group_default]

}

1 change: 1 addition & 0 deletions terraform.v12/vpc+windows/aws/environment/dev/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#variable "rds-secret" { type = string }
3 changes: 3 additions & 0 deletions terraform.v12/vpc+windows/aws/environment/dev/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = "~> 0.12.0"
}
19 changes: 19 additions & 0 deletions terraform.v12/vpc+windows/aws/modules/aws-ec2-keypair/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#########
# Labels
########
module "label" {
source = "../terraform-label"
namespace = var.namespace
name = var.name
stage = var.stage
delimiter = var.delimiter
attributes = var.attributes
tags = var.tags
enabled = var.enabled
}

resource "aws_key_pair" "keypair" {
key_name = var.key-name
public_key = var.public-key
}
12 changes: 12 additions & 0 deletions terraform.v12/vpc+windows/aws/modules/aws-ec2-keypair/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#OUTPUT EC2 KEYPAIR
output "key-pair" {
value = aws_key_pair.keypair.id
}

output "key-name" {
value = aws_key_pair.keypair.key_name
}

output "public-key" {
value = aws_key_pair.keypair.public_key
}
49 changes: 49 additions & 0 deletions terraform.v12/vpc+windows/aws/modules/aws-ec2-keypair/variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#EC2 KEY PAIR VARIABLES
variable "namespace" {
type = string
description = "Namespace (e.g. `eg` or `cp`)"
default = ""
}

variable "stage" {
type = string
description = "Stage (e.g. `prod`, `dev`, `staging`)"
default = ""
}

variable "delimiter" {
type = string
default = "-"
description = "Delimiter to be used between `name`, `namespace`, `stage` and `attributes`"
}

variable "enabled" {
description = "Controls if VPC should be created (it affects almost all resources)"
type = bool
default = true
}

variable "attributes" {
type = list(string)
default = []
description = "Additional attributes (e.g. `1`)"
}

variable "name" {
description = "Name to be used on all the resources as identifier"
default = ""
}

variable "tags" {
description = "A map of tags to add to all resources"
type = map(string)
default = {}
}

variable "key-name" {
default = ""
}

variable "public-key" {
default = ""
}
Loading

0 comments on commit 912604a

Please sign in to comment.