77$ hcl' 
88# Specify the provider and access details 
99provider "aws" { 
10-  region = "${var.aws_region}" 
10+  access_key = "${var.access_key}" 
11+  secret_key = "${var.secret_key}" 
12+  region = "${var.region}" 
1113} 
1214
13- # Create a VPC to launch our instances into 
14- resource "aws_vpc" "default" { 
15-  cidr_block = "10.0.0.0/16" 
16- } 
17- 
18- # Create an internet gateway to give our subnet access to the outside world 
19- resource "aws_internet_gateway" "default" { 
20-  vpc_id = "${aws_vpc.default.id}" 
21- } 
22- 
23- # Grant the VPC internet access on its main route table 
24- resource "aws_route" "internet_access" { 
25-  route_table_id = "${aws_vpc.default.main_route_table_id}" 
26-  destination_cidr_block = "0.0.0.0/0" 
27-  gateway_id = "${aws_internet_gateway.default.id}" 
28- } 
29- 
30- # Create a subnet to launch our instances into 
31- resource "aws_subnet" "default" { 
32-  vpc_id = "${aws_vpc.default.id}" 
33-  cidr_block = "10.0.1.0/24" 
34-  map_public_ip_on_launch = true 
35- } 
36- 
37- # A security group for the ELB so it is accessible via the web 
38- resource "aws_security_group" "elb" { 
39-  name = "terraform_example_elb" 
40-  description = "Used in the terraform" 
41-  vpc_id = "${aws_vpc.default.id}" 
42- 
43-  # HTTP access from anywhere 
44-  ingress { 
45-  from_port = 80 
46-  to_port = 80 
47-  protocol = "tcp" 
48-  cidr_blocks = ["0.0.0.0/0"] 
49-  } 
50- 
51-  # outbound internet access 
52-  egress { 
53-  from_port = 0 
54-  to_port = 0 
55-  protocol = "-1" 
56-  cidr_blocks = ["0.0.0.0/0"] 
57-  } 
58- } 
59- 
60- # Our default security group to access 
61- # the instances over SSH and HTTP 
62- resource "aws_security_group" "default" { 
63-  name = "terraform_example" 
64-  description = "Used in the terraform" 
65-  vpc_id = "${aws_vpc.default.id}" 
66- 
67-  # SSH access from anywhere 
68-  ingress { 
69-  from_port = 22 
70-  to_port = 22 
71-  protocol = "tcp" 
72-  cidr_blocks = ["0.0.0.0/0"] 
73-  } 
74- 
75-  # HTTP access from the VPC 
76-  ingress { 
77-  from_port = 80 
78-  to_port = 80 
79-  protocol = "tcp" 
80-  cidr_blocks = ["10.0.0.0/16"] 
81-  } 
82- 
83-  # outbound internet access 
84-  egress { 
85-  from_port = 0 
86-  to_port = 0 
87-  protocol = "-1" 
88-  cidr_blocks = ["0.0.0.0/0"] 
89-  } 
15+ # Create an instance 
16+ resource "aws_instance" "example" { 
17+  ami = "ami-2757f631" 
18+  instance_type = "t2.micro" 
9019} 
9120
92- resource "aws_elb" "web" { 
93-  name = "terraform-example-elb" 
94- 
95-  subnets = ["${aws_subnet.default.id}"] 
96-  security_groups = ["${aws_security_group.elb.id}"] 
97-  instances = ["${aws_instance.web.id}"] 
21+ 
9822
99-  listener { 
100-  instance_port = 80 
101-  instance_protocol = "http" 
102-  lb_port = 80 
103-  lb_protocol = "http" 
23+ $ configObjectnew  HCLParser ($ hclparse ();
24+ 
25+ var_dump ($ configObject
26+ 
27+ /* 
28+ 
29+ object(stdClass)#5 (2) { 
30+  ["provider"]=> 
31+  array(1) { 
32+  [0]=> 
33+  object(stdClass)#4 (1) { 
34+  ["aws"]=> 
35+  array(1) { 
36+  [0]=> 
37+  object(stdClass)#2 (3) { 
38+  ["access_key"]=> 
39+  string(17) "${var.access_key}" 
40+  ["region"]=> 
41+  string(13) "${var.region}" 
42+  ["secret_key"]=> 
43+  string(17) "${var.secret_key}" 
44+  } 
45+  } 
46+  } 
10447 } 
105- } 
106- 
107- resource "aws_key_pair" "auth" { 
108-  key_name = "${var.key_name}" 
109-  public_key = "${file(var.public_key_path)}" 
110- } 
111- 
112- resource "aws_instance" "web" { 
113-  # The connection block tells our provisioner how to 
114-  # communicate with the resource (instance) 
115-  connection { 
116-  # The default username for our AMI 
117-  user = "ubuntu" 
118- 
119-  # The connection will use the local SSH agent for authentication. 
120-  } 
121- 
122-  instance_type = "t2.micro" 
123- 
124-  # Lookup the correct AMI based on the region 
125-  # we specified 
126-  ami = "${lookup(var.aws_amis, var.aws_region)}" 
127- 
128-  # The name of our SSH keypair we created above. 
129-  key_name = "${aws_key_pair.auth.id}" 
130- 
131-  # Our Security group to allow HTTP and SSH access 
132-  vpc_security_group_ids = ["${aws_security_group.default.id}"] 
133- 
134-  # We \'re going to launch into the same subnet as our ELB. In a production 
135-  # environment it \'s more common to have a separate private subnet for 
136-  # backend instances. 
137-  subnet_id = "${aws_subnet.default.id}" 
138- 
139-  # We run a remote provisioner on the instance after creating it. 
140-  # In this case, we just install nginx and start it. By default, 
141-  # this should be on port 80 
142-  provisioner "remote-exec" { 
143-  inline = [ 
144-  "sudo apt-get -y update", 
145-  "sudo apt-get -y install nginx", 
146-  "sudo service nginx start", 
147-  ] 
48+  ["resource"]=> 
49+  array(1) { 
50+  [0]=> 
51+  object(stdClass)#8 (1) { 
52+  ["aws_instance"]=> 
53+  array(1) { 
54+  [0]=> 
55+  object(stdClass)#7 (1) { 
56+  ["example"]=> 
57+  array(1) { 
58+  [0]=> 
59+  object(stdClass)#6 (2) { 
60+  ["ami"]=> 
61+  string(12) "ami-2757f631" 
62+  ["instance_type"]=> 
63+  string(8) "t2.micro" 
64+  } 
65+  } 
66+  } 
67+  } 
68+  } 
14869 } 
14970} 
150- 
151- 
152- $ objectnew  HCLParser ($ hclparse ();
15371
154- var_dump ( $ object ); 
72+ */ 
0 commit comments