AWS resource and data source schemas
Choose ownership before writing a declaration
A resource block asks Terraform to manage an object through its lifecycle. A data source obtains information about an object without taking over its lifecycle. Suppose the catalog team owns a new virtual network (VPC) while a platform team owns a shared network. These two examples are separate static alternatives and require the approved AWS provider configuration from the preceding lesson if ever used in a real environment. Never apply them as part of this tutorial.
resource "aws_vpc" "catalog" { cidr_block = "10.40.0.0/16" tags = { Name = "catalog-test" }}output "catalog_vpc_id" { value = aws_vpc.catalog.id}The address aws_vpc.catalog identifies the managed instance in Terraform. Its id is assigned by the service, so it may be unknown in an initial plan. The private IPv4 range is an input, not a promise of private connectivity. Routes, internet gateways, public IPs, security groups and network ACLs affect reachability.
variable "shared_vpc_id" { type = string}data "aws_vpc" "shared" { id = var.shared_vpc_id}output "shared_network" { value = data.aws_vpc.shared.cidr_block}Here the caller supplies the existing VPC ID, and the data source reads the selected network’s CIDR. No Terraform-owned VPC is created by this declaration. A real lookup can fail for missing objects, the wrong region, insufficient permission or ambiguous filters. If the ID is unknown until apply, the read may be deferred. Do not declare a managed resource with the same remote identity in another state. Use an intentional ownership-transfer/import process where appropriate.
Read the provider schema as a contract
Terraform syntax alone cannot tell you which fields an AWS resource accepts. Review the exact provider documentation and, in an approved initialized environment, the provider schema. The following command is shown for reference only; it can load provider binaries and is not run in this chapter.
terraform providers schema -jsonThe JSON includes provider, managed resource and data source schema maps. A required attribute needs a value, an optional attribute can be omitted, and a computed attribute can be supplied by the provider. An attribute can be optional and computed. A schema version is not a package version. Schema inspection does not prove that AWS will accept the request or that a change avoids replacement. Review provider behavior and an authorized plan separately.
Identify service boundaries
Terraform AWS names often start with aws_, but each resource type has a different interface. Examples to investigate in their own versioned references: aws_iam_role for a role and trust policy; aws_vpc for network boundaries; aws_instance for EC2 compute; aws_s3_bucket for object storage; aws_db_instance for a managed database instance; aws_lambda_function for a function deployment. This is a vocabulary map, not a complete schema or deployment guide. Use the independent AWS track for IAM evaluation, network routing, storage behavior, engine requirements and operational cost. Prefer private network access and narrow permissions; never infer security from a resource type name.
Compare Terraform with native AWS interfaces
CloudFormation is an AWS-managed infrastructure template system. The following alternative template fragment expresses a similar IPv4 VPC request; it is not a Terraform file and must not be deployed alongside the managed example.
Resources: CatalogNetwork: Type: AWS::EC2::VPC Properties: CidrBlock: 10.40.0.0/16 Tags: - Key: Name Value: catalog-testThe CloudFormation logical ID and Terraform resource address are different identities. Both rely on AWS APIs, but schema fields, defaults, update semantics, state/stack ownership and supported features need separate review. An AWS API action such as CreateVpc is an operation, not a persistent configuration declaration. Avoid two systems managing the same object.
Use a mocked test to check configuration intent
A native Terraform test can substitute a mock provider for real AWS behavior. Mocking still requires the correct provider schema and approved plugin binaries. This is a staged, unexecuted test file for the managed VPC example only.
mock_provider "aws" {}
run "catalog_network_input" { command = plan assert { condition = aws_vpc.catalog.cidr_block == "10.40.0.0/16" error_message = "The catalog network range changed." }}The assertion checks the configured CIDR value. It does not prove AWS IP allocation, routing, IAM authorization, service quotas, availability or cost. A mock may generate unrealistic computed IDs; never use them as real identifiers. The offline exercise instead classifies resource and data-source addresses and reviews a fictional schema without loading any plugin.
Review before moving on
For each planned object, name its owner, state, account, region, inputs, outputs, security controls and cost-bearing dependencies. Check whether a plan proposes creation, update, replacement or deletion. The following chapter builds private architecture from small modules. Its real-world constraints cannot be proven from these static examples.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
AWS resource and data source schemas — knowledge check
Review AWS provider configuration and lifecycle ownership.
Which address reads the existing shared VPC?
Why might a new VPC id be unknown in a plan?
What does a provider schema describe?
What does a passing mock CIDR assertion establish?
Who should manage the same remote VPC lifecycle?