diff --git a/aws_instance/terraform_grafana/.terraform.lock.hcl b/aws_instance/terraform_grafana/.terraform.lock.hcl new file mode 100644 index 0000000..95a1bb5 --- /dev/null +++ b/aws_instance/terraform_grafana/.terraform.lock.hcl @@ -0,0 +1,44 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/archive" { + version = "1.3.0" + constraints = "~> 1.3" + hashes = [ + "h1:T3DszgOa/75SiiONgEDRujpN5rSqIw9TvFZXHjpqMB4=", + "zh:115aa6bc7825402a8d4e2e954378a9f48e4fdbeabe081ffd04e0a2f6786159bb", + "zh:21f731ffac20a67615c64a7a8a96949c971ee28ffd5807d8c299faba73b5e273", + "zh:2e81b58e141b175cbf801ade5e87c5db4cb28933216b0547ef32c95500385904", + "zh:3acbb96fd142b4d193dc18861340281249301368029169e346d15410d0572492", + "zh:4346edee0dfe97154b6f28d9ef0fa762131db92b78bbd1b3207945201cb59818", + "zh:93916a84cc6ff6778456dd170a657326c4dd3a86b4434e424a66a87c2535b888", + "zh:ade675c3ac8b9ec91131bac5881fbd4efad46a3683f2fea2efb9493a2c1b9ffb", + "zh:b0a0cb13fc850903aa7a057ae7e06366939b8f347926dce1137cd47b9123ad93", + "zh:d6d838cceffb7f3ff27fb9b51d78fccdef15bd32408f33a726556bfe66315bd3", + "zh:ddc4ac6aea6537f8096ffeb8ff3bca355f0972793184e0f6df120aa6460b4446", + "zh:e0d1213625d40d124bd9570f0d92907416f8d61bc8c389c776e72c0a97020cce", + "zh:eb707b69f9093b97d98e2dece9822852a27849dd1627d35302e8d6b9801407ef", + ] +} + +provider "registry.terraform.io/hashicorp/aws" { + version = "4.52.0" + hashes = [ + "h1:Ofm8syFCBU8MFOiU+zg+vnTWkSdozpmvaA9xukNvcBg=", + "zh:00c865de3a0e7643f4e2e5c8d4ba91eee94a46d41090eb134baca6b58c107172", + "zh:1430682e26eba25d8ace19fa780361187f474153e455545235b4fe30637fdcc2", + "zh:1b9a4e5c889bd2022bd59fb924dc78e189f1b7a4fd718fcacda0f0a4cb74d6eb", + "zh:2485260141608f1d386d0f68934092bbf68a27d96f0d83c73222d0382aee02f5", + "zh:2fe67ee94e2df7dabee7e474356f8e907e7c8011533f9d71df8702d59f9060b2", + "zh:37babd1b7ff96ff1f42aa56d7575cacabda6f9f460ff651d70662bfd90076341", + "zh:54aa8d39f22ecab6613169f49d37d2ccfaf417e59dd7a8c8fc6bf92600c3384f", + "zh:5bf4a84b962a8d2da8f4ccf2a7de56fb6c7a1f566e8393b563977fc7872a8740", + "zh:8cb4a51f209a3cc497e53f09188c15c6675697587fe2ea14a6c7fff10c8c8476", + "zh:91f6bdcbb1e36471140982e9048b7ced437d3290b2cc21079e5429cc84fed2fd", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9f8c01c3f677bc64ddefa41e59c6fc98860c11875d7f148af55969d3e3847f77", + "zh:b6b4fc0bd6f3c0adcd9531da3ccf8c25787ccd6ccc568f13ebbff1336d71a9e1", + "zh:d52a428bd92cc319088685ecac63b9f7d12d4cd6725604edb20d0c4f37a9936e", + "zh:e20252a851a0d38548a3c01a006bfc59ee1fc84217bf9eb95b22724769601b2b", + ] +} diff --git a/aws_instance/terraform_grafana/ec2.tf b/aws_instance/terraform_grafana/ec2.tf new file mode 100644 index 0000000..78c8a72 --- /dev/null +++ b/aws_instance/terraform_grafana/ec2.tf @@ -0,0 +1,60 @@ +resource "aws_security_group" "grafana-allow-security" { + name = "grafana-allow-security" + description = "Allow inbound traffic" + vpc_id = var.VPC_ID + + ingress { + description = "SSH" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["118.223.123.161/32"] + } + + ingress { + description = "TLS from grafana" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["118.223.123.161/32"] + } + + ingress { + description = "http fron grafana" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["118.223.123.161/32"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } + + tags = { + Name = "grafana-allow-security" + } +} + +resource "aws_instance" "grafana" { + ami = "ami-0409b7ddbc59e3222" + instance_type = "t3.small" + key_name = "kp-jay-bastion-datasaker" + vpc_security_group_ids = [aws_security_group.grafana-allow-security.id] + availability_zone = "ap-northeast-2a" + subnet_id = var.Public_Subnet_ID_1 + + root_block_device { + delete_on_termination = true + volume_size = 30 + } + + tags = { + Name = "grafana" + } +} + diff --git a/aws_instance/terraform_grafana/main.tf b/aws_instance/terraform_grafana/main.tf new file mode 100644 index 0000000..dd4bd35 --- /dev/null +++ b/aws_instance/terraform_grafana/main.tf @@ -0,0 +1,10 @@ +provider "aws" { + region = "ap-northeast-2" +} + +terraform { + required_providers { + archive = "~> 1.3" + } +} + diff --git a/aws_instance/terraform_grafana/terraform.tfstate b/aws_instance/terraform_grafana/terraform.tfstate new file mode 100644 index 0000000..cc3d74b --- /dev/null +++ b/aws_instance/terraform_grafana/terraform.tfstate @@ -0,0 +1,220 @@ +{ + "version": 4, + "terraform_version": "1.3.1", + "serial": 3, + "lineage": "946bb105-337f-c3fc-6b8b-e09f72b8b293", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "aws_instance", + "name": "grafana", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 1, + "attributes": { + "ami": "ami-0409b7ddbc59e3222", + "arn": "arn:aws:ec2:ap-northeast-2:508259851457:instance/i-09c4bc87fd369504e", + "associate_public_ip_address": false, + "availability_zone": "ap-northeast-2a", + "capacity_reservation_specification": [ + { + "capacity_reservation_preference": "open", + "capacity_reservation_target": [] + } + ], + "cpu_core_count": 1, + "cpu_threads_per_core": 2, + "credit_specification": [ + { + "cpu_credits": "unlimited" + } + ], + "disable_api_stop": false, + "disable_api_termination": false, + "ebs_block_device": [], + "ebs_optimized": false, + "enclave_options": [ + { + "enabled": false + } + ], + "ephemeral_block_device": [], + "get_password_data": false, + "hibernation": false, + "host_id": "", + "host_resource_group_arn": null, + "iam_instance_profile": "", + "id": "i-09c4bc87fd369504e", + "instance_initiated_shutdown_behavior": "stop", + "instance_state": "running", + "instance_type": "t3.small", + "ipv6_address_count": 0, + "ipv6_addresses": [], + "key_name": "kp-jay-bastion-datasaker", + "launch_template": [], + "maintenance_options": [ + { + "auto_recovery": "default" + } + ], + "metadata_options": [ + { + "http_endpoint": "enabled", + "http_put_response_hop_limit": 1, + "http_tokens": "optional", + "instance_metadata_tags": "disabled" + } + ], + "monitoring": false, + "network_interface": [], + "outpost_arn": "", + "password_data": "", + "placement_group": "", + "placement_partition_number": 0, + "primary_network_interface_id": "eni-0b48b92d69735da43", + "private_dns": "i-09c4bc87fd369504e.ap-northeast-2.compute.internal", + "private_dns_name_options": [ + { + "enable_resource_name_dns_a_record": true, + "enable_resource_name_dns_aaaa_record": false, + "hostname_type": "resource-name" + } + ], + "private_ip": "172.24.0.88", + "public_dns": "", + "public_ip": "", + "root_block_device": [ + { + "delete_on_termination": true, + "device_name": "/dev/sda1", + "encrypted": false, + "iops": 100, + "kms_key_id": "", + "tags": null, + "throughput": 0, + "volume_id": "vol-0f45b5aae9c328a33", + "volume_size": 30, + "volume_type": "gp2" + } + ], + "secondary_private_ips": [], + "security_groups": [], + "source_dest_check": true, + "subnet_id": "subnet-00c363356f133411d", + "tags": { + "Name": "grafana" + }, + "tags_all": { + "Name": "grafana" + }, + "tenancy": "default", + "timeouts": null, + "user_data": null, + "user_data_base64": null, + "user_data_replace_on_change": false, + "volume_tags": null, + "vpc_security_group_ids": [ + "sg-014638e423c769405" + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6MTIwMDAwMDAwMDAwMCwidXBkYXRlIjo2MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjEifQ==", + "dependencies": [ + "aws_security_group.grafana-allow-security" + ] + } + ] + }, + { + "mode": "managed", + "type": "aws_security_group", + "name": "grafana-allow-security", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 1, + "attributes": { + "arn": "arn:aws:ec2:ap-northeast-2:508259851457:security-group/sg-014638e423c769405", + "description": "Allow inbound traffic", + "egress": [ + { + "cidr_blocks": [ + "0.0.0.0/0" + ], + "description": "", + "from_port": 0, + "ipv6_cidr_blocks": [ + "::/0" + ], + "prefix_list_ids": [], + "protocol": "-1", + "security_groups": [], + "self": false, + "to_port": 0 + } + ], + "id": "sg-014638e423c769405", + "ingress": [ + { + "cidr_blocks": [ + "118.223.123.161/32" + ], + "description": "SSH", + "from_port": 22, + "ipv6_cidr_blocks": [], + "prefix_list_ids": [], + "protocol": "tcp", + "security_groups": [], + "self": false, + "to_port": 22 + }, + { + "cidr_blocks": [ + "118.223.123.161/32" + ], + "description": "TLS from grafana", + "from_port": 443, + "ipv6_cidr_blocks": [], + "prefix_list_ids": [], + "protocol": "tcp", + "security_groups": [], + "self": false, + "to_port": 443 + }, + { + "cidr_blocks": [ + "118.223.123.161/32" + ], + "description": "http fron grafana", + "from_port": 80, + "ipv6_cidr_blocks": [], + "prefix_list_ids": [], + "protocol": "tcp", + "security_groups": [], + "self": false, + "to_port": 80 + } + ], + "name": "grafana-allow-security", + "name_prefix": "", + "owner_id": "508259851457", + "revoke_rules_on_delete": false, + "tags": { + "Name": "grafana-allow-security" + }, + "tags_all": { + "Name": "grafana-allow-security" + }, + "timeouts": null, + "vpc_id": "vpc-00ba2b0e9ad59f0ed" + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6OTAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIxIn0=" + } + ] + } + ], + "check_results": [] +} diff --git a/aws_instance/terraform_grafana/variables.tf b/aws_instance/terraform_grafana/variables.tf new file mode 100644 index 0000000..a6a7336 --- /dev/null +++ b/aws_instance/terraform_grafana/variables.tf @@ -0,0 +1,35 @@ +#---------------------------------------------------------------# +# Network ID + +variable "VPC_ID" { + default = "vpc-00ba2b0e9ad59f0ed" +} + +variable "Network_CIDR" { + default = "172.24.0.0/19" +} + +variable "Private_Subnet_ID_1" { + default = "subnet-024f0deda82039fa4" +} + +variable "Private_Subnet_ID_2" { + default = "subnet-050d942fa1c46540a" +} + +variable "Private_Subnet_ID_3" { + default = "subnet-0946eb806af7377be" +} + +variable "Public_Subnet_ID_1" { + default = "subnet-00c363356f133411d" +} + +variable "Public_Subnet_ID_2" { + default = "subnet-07aa5e879a262014d" +} + +variable "Public_Subnet_ID_3" { + default = "subnet-0073a61bc56a68a3e" +} +