Create a Terraform module to provision an aws ec2 instance
- User
Create a Terraform module to provision an aws ec2 instance
- Assistant
Here is an example Terraform module for provisioning an AWS EC2 instance:
codemodule "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" name = "my-ec2-instance" ami = "ami-0ff8a91507f77f867" instance_type = "t2.micro" key_name = "my-key-pair" vpc_security_group_ids = ["sg-01234567890abcdef0"] subnet_id = "subnet-01234567890abcdef0" }This module uses the EC2 instance module from the official AWS Terraform modules. The
namevariable sets the name of the EC2 instance, theamivariable sets the Amazon Machine Image (AMI) to use, theinstance_typevariable sets the type of instance, thekey_namevariable sets the key pair to use for SSH access, thevpc_security_group_idsvariable sets the VPC security group to associate with the instance, and thesubnet_idvariable sets the subnet to launch the instance in.You will need to configure your AWS credentials and default region in Terraform backend prior to running this module.
It's a good practice to use variables and outputs to make the module more flexible and reusable.
Please note that this is just a basic example and you may need to add more variables and resources depending on your specific requirements.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.