0
0
Terraformcloud~30 mins

JSON configuration alternative in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform JSON Configuration Alternative
📖 Scenario: You are setting up a simple cloud infrastructure using Terraform. Instead of using the usual .tf files, you will write the configuration using Terraform's JSON syntax. This helps when you want to generate Terraform configs programmatically or prefer JSON format.
🎯 Goal: Create a Terraform configuration in JSON format that defines a provider and a resource to launch a virtual machine instance with specific properties.
📋 What You'll Learn
Create a JSON object for Terraform configuration
Define the provider block for AWS with region us-east-1
Define a resource block for an AWS EC2 instance named example
Set the instance type to t2.micro and use AMI ID ami-0c55b159cbfafe1f0
Use valid JSON syntax compatible with Terraform
💡 Why This Matters
🌍 Real World
Terraform supports JSON configuration as an alternative to HCL. This is useful when generating configs programmatically or integrating with tools that produce JSON.
💼 Career
Understanding Terraform JSON syntax helps cloud engineers automate infrastructure provisioning and integrate Terraform with other systems.
Progress0 / 4 steps
1
Create the base JSON structure for Terraform
Create a JSON object called terraformConfig with an empty provider and resource keys as empty objects.
Terraform
Need a hint?

Start with an object that has provider and resource keys, both set to empty objects.

2
Add AWS provider configuration
Inside the provider object, add an aws key with an object that sets region to "us-east-1".
Terraform
Need a hint?

Inside provider, add "aws": { "region": "us-east-1" }.

3
Add AWS EC2 instance resource
Inside the resource object, add an aws_instance key. This key should be an object with a key example that contains an object with ami set to "ami-0c55b159cbfafe1f0" and instance_type set to "t2.micro".
Terraform
Need a hint?

Inside resource, add "aws_instance": { "example": { "ami": "ami-0c55b159cbfafe1f0", "instance_type": "t2.micro" } }.

4
Complete the Terraform JSON configuration
Ensure the JSON object has the provider with AWS region us-east-1 and the resource with an aws_instance named example with the specified AMI and instance type. The JSON must be valid and ready for Terraform to use.
Terraform
Need a hint?

Check that all required keys and values are present and the JSON syntax is correct.