Can you write a Terraform script to provision an EC2 instance and an S3 bucket?
TechnicalDevOps EngineerCloud EngineerInfrastructure EngineerTo provision an EC2 instance and an S3 bucket using Terraform, I would start with the following script:
- Define the provider as AWS.
- Create the S3 bucket resource.
- Launch the EC2 instance with the necessary attributes.
Here's a simplified version:
provider "aws" { region = "us-east-1" } resource "aws_s3_bucket" "my_bucket" { bucket = "my-unique-bucket-name" } resource "aws_instance" "my_instance" { ami = "ami-0c55b159cbfafe01e" instance_type = "t2.micro" }This setup ensures I have a scalable architecture with cost efficiency.