Convert AWS S3 Bucket HCL to JSON

Convert a complete S3 bucket Terraform configuration with versioning, encryption, and lifecycle rules from HCL to JSON format.

Resources

Detailed Explanation

S3 Bucket Configuration

Modern Terraform AWS provider (v4+) uses separate resources for bucket sub-configurations. Converting these multi-resource HCL configurations to JSON shows how related resources are organized.

HCL Configuration

resource "aws_s3_bucket" "assets" {
  bucket = "my-app-assets-2024"

  tags = {
    Name        = "Assets"
    Environment = "production"
  }
}

resource "aws_s3_bucket_versioning" "assets" {
  bucket = "my-app-assets-2024"

  versioning_configuration {
    status = "Enabled"
  }
}

resource "aws_s3_bucket_server_side_encryption_configuration" "assets" {
  bucket = "my-app-assets-2024"

  rule {
    apply_server_side_encryption_by_default {
      sse_algorithm = "AES256"
    }
  }
}

JSON Structure

Multiple resources of different types each get their own entry under the resource key. The JSON structure groups by resource type, then resource name:

{
  "resource": {
    "aws_s3_bucket": {
      "assets": { "bucket": "...", "tags": {...} }
    },
    "aws_s3_bucket_versioning": {
      "assets": { ... }
    }
  }
}

Deeply Nested Blocks

The encryption configuration demonstrates three levels of block nesting (rule > apply_server_side_encryption_by_default), each becoming a nested JSON object.

Security Best Practices

This configuration follows AWS security recommendations: server-side encryption with AES256, versioning enabled for data protection, and a clear tagging strategy.

Use Case

Setting up S3 buckets for static website hosting, application asset storage, or data lake configurations. Converting these configurations to JSON is useful when generating Terraform from AWS CloudFormation templates or other infrastructure tools.

Try It — HCL ↔ JSON Converter

Open full tool