-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tf
More file actions
115 lines (93 loc) · 3.18 KB
/
main.tf
File metadata and controls
115 lines (93 loc) · 3.18 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# cloud-init config that installs the provisioning scripts
data "local_file" "write_ssh_interval" {
filename = "cloud-data"
}
data "local_file" "write_apt_update" {
filename = "cloud-data-configuration"
}
data "cloudinit_config" "provision" {
gzip = true
base64_encode = true
part {
content_type = "text/cloud-config"
content = data.local_file.write_ssh_interval.content
}
part {
content_type = "text/cloud-config"
content = data.local_file.write_apt_update.content
}
}
resource "aws_instance" "ec2" {
ami = var.ami
instance_type = var.instance_type
key_name = "aws_lajolla_public"
#user_data = data.cloudinit_config.provision.rendered
vpc_security_group_ids = [
"sg-0747026767ceec6b5",
"sg-06700b3cf3acc1772"
]
tags = {
Name = "new-instance_heat"
}
# Let's create and attach an ebs volume
# when we create the instance
ebs_block_device {
device_name = "/dev/xvdb"
volume_type = "gp2"
volume_size = 8
}
provisioner "file" {
source = "var.sh"
destination = "/home/ubuntu/var.sh"
}
# Copy in the bash script we want to execute.
# The source is the location of the bash script
# on the local linux box you are executing terraform
# from. The destination is on the new AWS instance.
provisioner "file" {
source = "providers.tf"
destination = "/home/ubuntu/providers.tf"
}
provisioner "file" {
source = "/Users/rickymarly/.ssh/aws_lajolla_public.pem"
destination = "/home/ubuntu/aws_lajolla_public.pem"
}
connection {
type = "ssh"
host = self.public_ip
user = "ubuntu"
private_key = file("/Users/rickymarly/.ssh/aws_lajolla_public.pem")
timeout = "4m"
}
provisioner "remote-exec" {
inline = [
"touch hello.txt",
"echo hello world remote provisioner >> hello.txt",
#"sudo apt -y update",
#"sudo apt install -y ansible",
#"sudo apt install -y yamllint",
"chmod 0400 /home/ubuntu/aws_lajolla_public.pem",
"chmod +x /home/ubuntu/var.sh",
"sudo bash /home/ubuntu/var.sh",
]
}
/* provisioner "local-exec" {
command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u centos --private-key ./Test-Key-1.pem -T 300 -i ${aws_instance.example.public_ip}, playbook.yml"
}*/
//ansible-pull --accept-host-key -d /home/ubuntu/git --key-file=/home/ubuntu/aws_lajolla -C HEAD -U 'git@github.com:marly10/keycode.git' -i hosts
//command used to install splunk:
//sudo apt update
// /home/ubuntu/.ssh/aws_lajolla
//sudo apt install alien
//wget -O splunk-9.0.0.1-9e907cedecb1-linux-2.6-x86_64.rpm "https://download.splunk.com/products/splunk/releases/9.0.0.1/linux/splunk-9.0.0.1-9e907cedecb1-linux-2.6-x86_64.rpm"
//sudo alien *.rpm
//sudo dpkg -i package_name.deb or sudo apt install ./package_name.deb
/*
cat << 'EOF' > /home/ubuntu/.ssh/sshd_config
ClientAliveInterval 120
ClientAliveCountMax 720
EOF
*/
}
# ansible-pull -C <branch name> -U https://github.com/<username>/<repo>.git <file_name>.yml
//ansible-pull --accept-host-key -d /home/ubuntu/git --key-file=/home/ubuntu/aws_lajolla -C master -U 'git@github.com:marly10/keycode.git' -i hosts