Browse Source

[Camilla] Example of variables and security group

Camilla 2 years ago
parent
commit
8df5f8fc58
2 changed files with 22 additions and 1 deletions
  1. 6 1
      terraform/README.md
  2. 16 0
      terraform/main.tf

+ 6 - 1
terraform/README.md

@@ -34,5 +34,10 @@ To actually run the file:
34 34
 terraform apply
35 35
 ```
36 36
 
37
+To pass Terraform a variable via command line
38
+```
39
+terraform plan -var server_port="8080"
40
+```
41
+
37 42
 ## Resources
38
-- (Introduction to Terraform (this is now OReilly book))[https://blog.gruntwork.io/an-introduction-to-terraform-f17df9c6d180]
43
+- (Introduction to Terraform, this is now OReilly book)[https://blog.gruntwork.io/an-introduction-to-terraform-f17df9c6d180]

+ 16 - 0
terraform/main.tf

@@ -6,3 +6,19 @@ resource "aws_instance" "example" {
6 6
     Name = "terraform-hello-world"
7 7
   }
8 8
 }
9
+
10
+# Variable declaration example
11
+variable "server_port" {
12
+  description = "The port the server will use for HTTP requests"
13
+}
14
+
15
+# Setting up security group
16
+resource "aws_security_group" "instance" {
17
+  name = "terraform-hello-world-instance"
18
+  ingress {
19
+    from_port = ${var.server_port}
20
+    to_port = ${var.server_port}
21
+    protocol = "tcp"
22
+    cidr_blocks = ["0.0.0.0/0"]
23
+  }
24
+}