The AWS provider gives Terraform access to Amazon Web Services resources and data sources, such as an AWS instance. Configure its dependency and version in required_providers, then configure its AWS region in the provider block. section 2.1.3
Listing 2.1 Configuring required providers
terraform { #1
required_providers { #2
aws = { #3
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" { #4
region = "us-east-1" #5
}
Use this configuration to install the HashiCorp AWS provider at a compatible 5.x version and target the us-east-1 region. section 2.1.3
A practical AWS-provider workflow is:
- Declare hashicorp/aws and constrain its version in required_providers; relying on automatic installation prevents explicit version selection and can allow breaking changes. section 2.1.3
- Configure AWS credentials through the AWS CLI with aws configure, because the provider follows the standard configuration used by AWS tools such as Boto3 and the CLI. section 2.1.6
- Run terraform init to download providers, terraform plan to inspect intended actions, and terraform apply after confirming the plan. section 2.1.6
Launching an AWS instance
With the provider configured, Terraform can read AWS data sources such as a VPC, AMI, and subnets, then plan creation of aws_instance.hello_world. Applying the approved plan creates the instance and reports its AWS ID.
