AWS provider configuration
Configure the AWS provider without making a cloud request
The AWS provider is the Terraform plugin that translates infrastructure declarations into operations on AWS. A configuration chooses a provider package and a connection context. The following is a static teaching example for a fictional test account. The account ID is a placeholder, not a valid lab credential. Terraform 1.14.8 is the previously proposed CLI baseline; AWS provider 6.55.0 is a separate illustrative pin, not a claim that either is the newest or approved for production. Do not initialize or execute this AWS example.
terraform { required_version = "= 1.14.8" required_providers { aws = { source = "hashicorp/aws" version = "= 6.55.0" } }}provider "aws" { region = "eu-west-1" allowed_account_ids = ["000000000000"] default_tags { tags = { Project = "catalog-lab" Environment = "test" } }}The source identifies the publisher and package. The version constraint selects the permitted plugin release; the lockfile records the selected release and checksums. The region is the default regional target, not an account identifier. The account allowlist adds a protective check; it does not grant permissions. Some recent provider resources can override the default region, so review resource-level settings as well.
Use temporary identities rather than embedded credentials
An account owns resources, a principal makes requests, and an IAM policy determines allowed actions. For an approved deployment, use an organization-managed short-lived session or workload federation with scoped permissions. Never put access keys, secret keys or session tokens into provider blocks, variable defaults, committed files or shell command arguments. A role session can only be obtained when the required permissions and trust relationships permit it. The next illustration replaces the provider block above; it is not an executable account setup.
# Alternative provider configuration; do not combine with the preceding block.provider "aws" { region = "eu-west-1" allowed_account_ids = ["000000000000"] assume_role { role_arn = "arn:aws:iam::000000000000:role/ExampleTerraformRole" }}The role ARN selects a target identity, not a network region. Before a separately authorized real run, confirm the resolved account, principal, region, partition, backend and planned resource ownership. An STS caller identity check can identify the caller but uses an AWS API; it must not be used here. Confirm the provider’s resolved identity as well, since its assumed role may differ from the CLI identity.
Review tags and environment safeguards
Tags help teams identify purpose, environment, ownership and cost allocation. In supported resources, provider default tags can be combined with resource-specific tags, with explicit resource values overriding matching keys. Some resources do not support the same tag behavior. Never treat a tag as an authorization control by itself. A test account should also have isolated credentials, state, restricted IAM permissions and a reviewed spending plan. The region and account settings do not enforce a private subnet or guarantee a low bill.
Practice identity review offline
A learner can reason about account selection without contacting AWS. In this separate, complete provider-free fixture, both account values are synthetic. It illustrates an equality check, not real credential verification.
terraform { required_version = "= 1.14.8"}locals { expected_account = "000000000000" observed_account = "111111111111" expected_region = "eu-west-1" observed_region = "eu-west-1"}output "context_matches" { value = local.expected_account == local.observed_account && local.expected_region == local.observed_region}Predicted output: false, because the two account IDs differ despite matching regions. Stop the hypothetical change; do not replace the allowlist with the observed account to make the check pass. Inspect the approved environment mapping and obtain authorization for the intended identity. No execution was performed.
Prepare a cost and security checklist
A provider connection does not automatically make a workload secure. Before approval, inventory public addressing, routes, access rules, IAM policies, data retention and resource counts. Estimate regional costs for compute time, persistent storage, requests, network transfer and managed service charges. Use dated official pricing and actual usage assumptions for a real estimate. The learner needs no AWS account, credentials or purchases for this chapter. The worksheet checks account boundaries and tags; the next lesson examines resource schemas.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
AWS provider configuration — knowledge check
Review AWS provider configuration and lifecycle ownership.
Which value identifies the provider package?
The expected account differs from the observed account. What should happen?
What does a provider version constraint control?
Where should real AWS session credentials be stored in this exercise?
What is a limitation of default tags?