Create a terraform module made of an EC2 instance and an attached cloudwatch alarm. Have…
- User
Create a terraform module made of an EC2 instance and an attached cloudwatch alarm. Have every parameter of these resources be variables that I will assign from the CLI, when calling the terraform module. Please split the code into files, according to best practices
Assistant
Here is a terraform module with an EC2 instance and CloudWatch alarm split into files according to best practices:
main.tf
terraform { required_providers { aws = { source = "hashicorp/aws" } } }
module "ec2_with_alarm" { source = "./modules/ec2_with_alarm"
EC2 variables
instance_type = var.instance_type ami = var.ami key_name = var.key_name subnet_id = var.subnet_id
Alarm variables
alarm_name = var.alarm_name comparison_operator = var.comparison_operator evaluation_periods = var.evaluation_periods metric_name = var.metric_name namespace = var.namespace period = var.period statistic = var.statistic threshold = var.threshold alarm_description = var.alarm_description alarm_actions = var.alarm_actions }
variables.tf
variable "instance_type" {} variable "ami" {} variable "key_name" {} variable "subnet_id" {}
variable "alarm_name" {} variable "comparison_operator" {} variable "evaluation_periods" {} variable "metric_name" {} variable "namespace" {} variable "period" {} variable "statistic" {} variable "threshold" {} variable "alarm_description" {} variable "alarm_actions" {}
modules/ec2_with_alarm/main.tf
resource "aws_instance" "example" { ami = var.ami instance_type = var.instance_type
key_name = var.key_name
subnet_id = var.subnet_id }
resource "aws_cloudwatch_metric_alarm" "example" { alarm_name = var.alarm_name comparison_operator = var.comparison_operator evaluation_periods = var.evaluation_periods metric_name = var.metric_name namespace = var.namespace period = var.period statistic = var.statistic threshold = var.threshold alarm_description = var.alarm_description alarm_actions = var
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.