Unknown model· unknown
from dpo-mix-7k (argilla)
Create a Terraform module to provision an aws ec2 instance
- User
Create a Terraform module to provision an aws ec2 instance
- Assistant
I'd be happy to help you create a Terraform module for provisioning an AWS EC2 instance! Before we begin, make sure you have Terraform installed and configured with your AWS credentials.
Here's a basic Terraform module structure for provisioning an AWS EC2 instance:
-
First, create a new directory for your Terraform module, e.g.,
aws_ec2_instance. -
Inside the
aws_ec2_instancedirectory, create amain.tffile:
hclresource "aws_instance" "this" { ami = var.ami instance_type = var.instance_type key_name = var.key_name subnet_id = var.subnet_id tags = { Name = var.instance_name } vpc_security_group_ids = var.security_groups } output "instance_id" { value = aws_instance.this.id } output "public_ip" { value = aws_instance.this.public_ip }- Now, create a
variables.tffile to define input variables:
hclvariable "ami" { type = string description = "The AMI ID for the EC2 instance" } variable "instance_type" { type = string description = "The instance type for the EC2 instance" } variable "instance_name" { type = string description = "The name tag for the EC2 instance" } variable "key_name" { type = string description = "The key pair name to associate with the instance (for SSH access)" } variable "subnet_id" { type = string description = "The VPC subnet ID where the EC2 instance will be launched" } variable "security_groups" { type = list(string) description = "A list of security group IDs to associate with the instance" }- Finally, you can create a file to document the usage of your module:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.