1
+ ---
2
+ - name : create a VPC
3
+ ec2_vpc_net :
4
+ name : " {{ vpc_name }}"
5
+ cidr_block : " {{ vpc_cidr_block }}"
6
+ region : " {{ aws_region }}"
7
+ aws_access_key : " {{ aws_access_key }}"
8
+ aws_secret_key : " {{ aws_secret_key }}"
9
+ state : " present"
10
+ register : vpc
11
+
12
+ - name : Set VPC ID in the variable
13
+ set_fact :
14
+ vpc_id : " {{ vpc.vpc.id }}"
15
+
16
+ - name : Create internet gateway for VPC
17
+ ec2_vpc_igw :
18
+ vpc_id : " {{ vpc_id }}"
19
+ region : " {{ aws_region }}"
20
+ aws_access_key : " {{ aws_access_key }}"
21
+ aws_secret_key : " {{ aws_secret_key }}"
22
+ state : " present"
23
+ register : vpc_igw
24
+
25
+ - name : Set internet gateway id in the variable
26
+ set_fact :
27
+ igw_id : " {{ vpc_igw.gateway_id }}"
28
+
29
+ - name : Create public subnet
30
+ ec2_vpc_subnet :
31
+ state : " present"
32
+ vpc_id : " {{ vpc_id }}"
33
+ cidr : " {{ public_subnet_cidr }}"
34
+ az : " {{ aws_region }}a"
35
+ region : " {{ aws_region }}"
36
+ aws_access_key : " {{ aws_access_key }}"
37
+ aws_secret_key : " {{ aws_secret_key }}"
38
+ resource_tags :
39
+ Name : " public subnet"
40
+ register : public_subnet
41
+
42
+ - name : Set public subnet id in the variable
43
+ set_fact :
44
+ public_subnet_id : " {{ public_subnet.subnet.id }}"
45
+
46
+ - name : Create route table
47
+ ec2_vpc_route_table :
48
+ vpc_id : " {{ vpc_id }}"
49
+ region : " {{ aws_region }}"
50
+ aws_access_key : " {{ aws_access_key }}"
51
+ aws_secret_key : " {{ aws_secret_key }}"
52
+ tags :
53
+ Name : " Public"
54
+ subnets :
55
+ - " {{ public_subnet_id }}"
56
+ routes :
57
+ - dest : " 0.0.0.0/0"
58
+ gateway_id : " {{ igw_id }}"
59
+
60
+ - name : Create Main Security Group
61
+ ec2_group :
62
+ name : " Personal Security Group"
63
+ description : " Personal Security Group"
64
+ vpc_id : " {{ vpc_id }}"
65
+ region : " {{ aws_region }}"
66
+ aws_access_key : " {{ aws_access_key }}"
67
+ aws_secret_key : " {{ aws_secret_key }}"
68
+ rules :
69
+ - proto : " tcp"
70
+ from_port : " 22"
71
+ to_port : " 22"
72
+ cidr_ip : " {{ my_ip }}/32"
0 commit comments