-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathec2.tf
More file actions
74 lines (67 loc) · 2.36 KB
/
ec2.tf
File metadata and controls
74 lines (67 loc) · 2.36 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
resource "tls_private_key" "airflow_server_private_key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "aws_key_pair" "generated_airflow_server_key" {
key_name = "auto-generated-key"
public_key = tls_private_key.airflow_server_private_key.public_key_openssh
}
resource "aws_instance" "ami_connect_airflow_server" {
ami = "ami-087f352c165340ea1"
instance_type = var.ami_connect_airflow_server_instance_size
vpc_security_group_ids = [aws_security_group.airflow_server_sg.id]
key_name = aws_key_pair.generated_airflow_server_key.key_name
iam_instance_profile = aws_iam_instance_profile.ami_instance_profile.name
root_block_device {
volume_size = 200 # GB
volume_type = "gp3"
encrypted = true
}
user_data = <<-EOF
#!/bin/bash
sudo yum install -y amazon-cloudwatch-agent
cat <<EOC > /opt/aws/amazon-cloudwatch-agent/bin/config.json
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"metrics": {
"append_dimensions": {
"InstanceId": "$${aws:InstanceId}"
},
"metrics_collected": {
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
},
"disk": {
"measurement": [
"used_percent"
],
"resources": [
"/"
],
"metrics_collection_interval": 60
},
"swap": {
"measurement": [
"swap_used_percent"
],
"metrics_collection_interval": 60
}
}
}
}
EOC
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
-a fetch-config -m ec2 \
-c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s
EOF
}
# Elastic IP
resource "aws_eip" "ami_connect_airflow_server_ip" {
instance = aws_instance.ami_connect_airflow_server.id
}