Files
kodekloud-engineer/terraform/task-18.md

3.8 KiB

Assignment

The Nautilus DevOps team needs to create an AWS Kinesis data stream for real-time data processing. This stream will be used to ingest and process large volumes of streaming data, which will then be consumed by various applications for analytics and real-time decision-making.

The stream should be named xfusion-stream.

Use Terraform to create this Kinesis stream.

The Terraform working directory is /home/bob/terraform. Create the main.tf file (do not create a different .tf file) to accomplish this task.

Note:

Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal. Before submitting the task, ensure that terraform plan returns No changes. Your infrastructure matches the configuration.

Solution

Kinesis Data Stream — xfusion-stream

Terraform solution to create a provisioned Kinesis data stream with a single shard, configured so terraform plan reports no drift after apply.

main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_kinesis_stream" "xfusion_stream" {
  name             = "xfusion-stream"
  shard_count      = 1
  retention_period = 24

  stream_mode_details {
    stream_mode = "PROVISIONED"
  }
}

How to run

cd /home/bob/terraform
terraform init
terraform apply -auto-approve

# Idempotency check required by the task:
terraform plan
# -> "No changes. Your infrastructure matches the configuration."

How it works

aws_kinesis_stream

  • name = "xfusion-stream" — the stream name, exactly as required.

  • stream_mode_details { stream_mode = "PROVISIONED" } — Kinesis has two capacity modes: PROVISIONED (you manage shards) and ON_DEMAND (AWS auto-scales). This is set to PROVISIONED explicitly. The two modes are mutually exclusive with shard_count: PROVISIONED requires shard_count, while ON_DEMAND forbids it. Getting this pairing wrong is the usual cause of a perpetual non-empty plan or an apply error.

  • shard_count = 1 — one shard. A shard is the base throughput unit (1 MB/s or 1000 records/s in, 2 MB/s out). One shard is plenty for a lab and is the provisioned-capacity choice that pairs with PROVISIONED mode.

  • retention_period = 24 — hours that records stay in the stream before aging out. 24 is the AWS default and the minimum; setting it explicitly to the default value keeps the resource stable and readable.

Why the plan comes back clean

The task explicitly requires terraform plan to report no changes after apply. Two things guarantee that here:

  1. Mode and shard count are consistent. PROVISIONED + an explicit shard_count is the stable, non-conflicting combination. Mixing ON_DEMAND with a shard_count, or omitting the mode and letting it get inferred, is what typically produces a drift diff on the next plan.

  2. Every value set matches what AWS stores. retention_period = 24 equals the service default, and no other arguments (encryption, shard-level metrics) are toggled, so there's nothing for the provider to reconcile on refresh.

Sandbox note

Constrained lab environments cap Kinesis at PROVISIONED mode, 1 shard per stream, ≤24h retention, and ≤2 streams per account. This config sits inside every one of those limits, so it won't be silently reset or rejected.

Verify

aws kinesis describe-stream-summary --stream-name xfusion-stream \
  --query 'StreamDescriptionSummary.{Name:StreamName,Status:StreamStatus,Mode:StreamModeDetails.StreamMode,Shards:OpenShardCount,Retention:RetentionPeriodHours}'

Expected — name xfusion-stream, StreamStatus: ACTIVE (a few seconds after create), StreamMode: PROVISIONED, OpenShardCount: 1, retention 24.