-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test Case 1
49 lines (39 loc) · 1.61 KB
/
Test Case 1
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
Getting Started with Terraform
Terraform is the most popular langauge for defining and provisioning infrastructure as code (IaC).
To install Terraform, simply visit Terraform.io and download the compressed binary application executable file deliverable for your platform, machine or environment on which you like to run code and do development.
With Terraform installed, let's dive right into it and start creating some infrastructure.
Most guys find it easiest to create a new directory on there local machine and create Terraform configuration code inside it.
$ mkdir terraform-demo
$ cd terraform-demo
Next, create a file for your Terraform configuration code.
$ touch main.tf
Paste the following lines into the file.
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
}
}
}
provider "docker" {
host = "unix:///var/run/docker.sock"
}
resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = "training"
ports {
internal = 80
external = 80
}
}
resource "docker_image" "nginx" {
name = "nginx:latest"
}
Initialize Terraform with the init command. The AWS provider will be installed.
$ terraform init
You shoud check for any errors. If it ran successfully, provision the resource with the apply command.
$ terraform apply
The command will take up to a few minutes to run and will display a message indicating that the resource was created.
Finally, destroy the infrastructure.
$ terraform destroy
Look for a message are the bottom of the output asking for confirmation. Type yes and hit ENTER. Terraform will destroy the resources it had created earlier.