-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommands
141 lines (93 loc) · 3.73 KB
/
commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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