File tree 8 files changed +341
-313
lines changed
8 files changed +341
-313
lines changed Original file line number Diff line number Diff line change 1
- name : Manual Apply # To prevent using a stale plan file, please run the Integrate workflow again.
1
+ name : Manual Apply
2
2
3
3
on :
4
4
workflow_dispatch :
20
20
with :
21
21
terraform_version : 1.6
22
22
23
+ - name : Setup SSH Private Key
24
+ run : |
25
+ echo "${{ secrets.AWS_PRIVATE_KEY }}" > b2111933-pair.pem
26
+ chmod 600 b2111933-pair.pem
27
+
23
28
- name : Download Planfile Artifact
24
29
uses : dawidd6/action-download-artifact@v7
25
30
with :
31
36
32
37
- name : Terraform Apply
33
38
run : terraform apply -input=false planfile
34
-
35
- config :
36
- runs-on : ubuntu-latest
37
- needs : apply # Run after terraform apply
38
- steps :
39
- - name : Checkout Code
40
- uses : actions/checkout@v3
41
-
42
- - name : Set up Ansible
43
- run : |
44
- sudo apt update
45
- sudo apt install -y ansible
46
-
47
- - name : Run Ansible Playbook
48
- run : |
49
- ansible-playbook -i ansible/inventory/aws_ec2.yaml ansible/playbooks/nginx.yml
Original file line number Diff line number Diff line change @@ -37,3 +37,6 @@ override.tf.json
37
37
# Ignore CLI configuration files
38
38
.terraformrc
39
39
terraform.rc
40
+
41
+ # Keys
42
+ b2111933-pair.pem
Original file line number Diff line number Diff line change @@ -9,6 +9,21 @@ resource "aws_instance" "amazon" {
9
9
subnet_id = var. public_subnet [0 ]
10
10
vpc_security_group_ids = [var . security_group [" sg_linux" ]]
11
11
12
+ provisioner "remote-exec" {
13
+ inline = [
14
+ " sudo dnf update -y" ,
15
+ " sudo dnf install -y amazon-linux-extras" ,
16
+ " sudo amazon-linux-extras enable ansible2" ,
17
+ " sudo dnf install -y ansible"
18
+ ]
19
+ connection {
20
+ type = " ssh"
21
+ user = " ec2-user"
22
+ private_key = file (var. private_key_path )
23
+ host = self. public_ip
24
+ }
25
+ }
26
+
12
27
tags = {
13
28
Name = " B2111933 Amazon Linux"
14
29
}
@@ -25,6 +40,21 @@ resource "aws_instance" "ubuntu" {
25
40
subnet_id = var. public_subnet [1 ]
26
41
vpc_security_group_ids = [var . security_group [" sg_linux" ]]
27
42
43
+ provisioner "remote-exec" {
44
+ inline = [
45
+ " sudo apt update -y" ,
46
+ " sudo apt install -y software-properties-common" ,
47
+ " sudo apt-add-repository --yes --update ppa:ansible/ansible" ,
48
+ " sudo apt install -y ansible"
49
+ ]
50
+ connection {
51
+ type = " ssh"
52
+ user = " ubuntu"
53
+ private_key = file (var. private_key_path )
54
+ host = self. public_ip
55
+ }
56
+ }
57
+
28
58
tags = {
29
59
Name = " B2111933 Ubuntu"
30
60
}
Original file line number Diff line number Diff line change @@ -34,3 +34,8 @@ variable "instance_type_free" {
34
34
type = string
35
35
default = " t2.micro"
36
36
}
37
+
38
+ variable "private_key_path" {
39
+ type = string
40
+ default = " b2111933-pair.pem"
41
+ }
Original file line number Diff line number Diff line change 1
- // just for practice
1
+ # //just for practice
2
2
3
- variables {
4
- bucket = " b2111933-tfbucket"
5
- dynamodb_table = " b2111933-tftable"
6
- dynamodb_key = " b2111933-tfstate"
7
- // more
8
- }
3
+ # variables {
4
+ # bucket = "b2111933-tfbucket"
5
+ # dynamodb_table = "b2111933-tftable"
6
+ # dynamodb_key = "b2111933-tfstate"
7
+ # //more
8
+ # }
9
9
10
- run "bucket_tests" {
11
- command = plan
12
- assert {
13
- condition = var. bucket == " b2111933-tfbucket"
14
- error_message = " Not our bucket!"
15
- }
16
- }
10
+ # run "bucket_tests" {
11
+ # command = plan
12
+ # assert {
13
+ # condition = var.bucket == "b2111933-tfbucket"
14
+ # error_message = "Not our bucket!"
15
+ # }
16
+ # }
17
17
18
- run "dynamodb_table_tests" {
19
- command = plan
20
- assert {
21
- condition = var. dynamodb_table == " b2111933-tftable"
22
- error_message = " Not our table!"
23
- }
24
- }
18
+ # run "dynamodb_table_tests" {
19
+ # command = plan
20
+ # assert {
21
+ # condition = var.dynamodb_table == "b2111933-tftable"
22
+ # error_message = "Not our table!"
23
+ # }
24
+ # }
25
25
26
- run "dynamodb_key_tests" {
27
- command = plan
28
- assert {
29
- condition = var. dynamodb_key == " b2111933-tfstate"
30
- error_message = " Not a valid key!"
31
- }
32
- }
26
+ # run "dynamodb_key_tests" {
27
+ # command = plan
28
+ # assert {
29
+ # condition = var.dynamodb_key == "b2111933-tfstate"
30
+ # error_message = "Not a valid key!"
31
+ # }
32
+ # }
33
33
Original file line number Diff line number Diff line change 1
- # Unit tests for the VPC and EC2 modules
1
+ # # Unit tests for the VPC and EC2 modules
2
2
3
- run "vpc_tests" {
4
- command = plan
3
+ # run "vpc_tests" {
4
+ # command = plan
5
5
6
- assert {
7
- condition = module. vpc . vpc_dns_hostnames_enabled == true
8
- error_message = " Must enable DNS hostname resolution!"
9
- }
6
+ # assert {
7
+ # condition = module.vpc.vpc_dns_hostnames_enabled == true
8
+ # error_message = "Must enable DNS hostname resolution!"
9
+ # }
10
10
11
- assert {
12
- condition = module. vpc . vpc_dns_support_enabled == true
13
- error_message = " Must enable DNS resolution!"
14
- }
15
- }
11
+ # assert {
12
+ # condition = module.vpc.vpc_dns_support_enabled == true
13
+ # error_message = "Must enable DNS resolution!"
14
+ # }
15
+ # }
16
16
17
- run "ec2_tests" {
18
- command = plan
17
+ # run "ec2_tests" {
18
+ # command = plan
19
19
20
- assert {
21
- condition = module. ec2 . amazon_instance_type [0 ] == " t2.micro"
22
- error_message = " Amazon Linux instance must be t2.micro for free tier!"
23
- }
20
+ # assert {
21
+ # condition = module.ec2.amazon_instance_type[0] == "t2.micro"
22
+ # error_message = "Amazon Linux instance must be t2.micro for free tier!"
23
+ # }
24
24
25
- assert {
26
- condition = module. ec2 . ubuntu_instance_type [0 ] == " t2.micro"
27
- error_message = " Ubuntu instance must be t2.micro for free tier!"
28
- }
25
+ # assert {
26
+ # condition = module.ec2.ubuntu_instance_type[0] == "t2.micro"
27
+ # error_message = "Ubuntu instance must be t2.micro for free tier!"
28
+ # }
29
29
30
- assert {
31
- condition = module. ec2 . windows_instance_type [0 ] == " t2.micro"
32
- error_message = " Windows instance must be t2.micro for free tier!"
33
- }
34
- }
30
+ # assert {
31
+ # condition = module.ec2.windows_instance_type[0] == "t2.micro"
32
+ # error_message = "Windows instance must be t2.micro for free tier!"
33
+ # }
34
+ # }
You can’t perform that action at this time.
0 commit comments