Skip to content

Instantly share code, notes, and snippets.

@alsmola
Last active March 23, 2026 20:31
Show Gist options
  • Select an option

  • Save alsmola/e51a5a100a4c537b8d19f2366f593b1a to your computer and use it in GitHub Desktop.

Select an option

Save alsmola/e51a5a100a4c537b8d19f2366f593b1a to your computer and use it in GitHub Desktop.

Verify AWS credentials and trailtool readiness

$ trailtool status
AWS credentials: OK (account [redacted])
Ingestor stack: OK (trailtool-ingestor)
Data access: OK

Good, trailtool is ready. Let me find ClickOps resources from the last 30 days.

List ClickOps resources from last 30 days

$ trailtool resources list --clickops --days 30 --format json
[
  {
    "identifier": "s3:bucket:i-need-this-bucket-sorry-for-click-opsing",
    "type": "s3:bucket",
    "arn": "arn:aws:s3:::i-need-this-bucket-sorry-for-click-opsing",
    "name": "i-need-this-bucket-sorry-for-click-opsing",
    "account_id": "[redacted]",
    "total_events": 49,
    "roles_count": 3,
    "services_used": ["s3.amazonaws.com"],
    "top_event_names": {
      "CreateBucket": 1,
      "GetBucketEncryption": 8,
      "GetBucketOwnershipControls": 5,
      "GetBucketPublicAccessBlock": 5,
      "GetBucketVersioning": 4,
      "GetBucketTagging": 4,
      "GetBucketLogging": 3,
      "GetBucketObjectLockConfiguration": 3,
      "GetAccelerateConfiguration": 2,
      "GetBucketLifecycle": 2,
      "GetBucketLocation": 2,
      "GetBucketReplication": 2,
      "GetBucketRequestPayment": 2,
      "GetBucketAcl": 1,
      "GetBucketCors": 1,
      "GetBucketPolicy": 1,
      "GetBucketWebsite": 1,
      "ListTagsForResource": 1,
      "PutBucketEncryption": 1
    },
    "clickops_accesses": [
      {
        "person_email": "alex@engseclabs.com",
        "event_name": "PutBucketEncryption",
        "access_time": "2026-03-23T18:34:28Z"
      },
      {
        "person_email": "alex@engseclabs.com",
        "event_name": "CreateBucket",
        "access_time": "2026-03-23T18:34:28Z"
      }
    ],
    "first_seen": "2026-03-23",
    "last_seen": "2026-03-23"
  }
]

Found 1 ClickOps resource: S3 bucket i-need-this-bucket-sorry-for-click-opsing created by alex@engseclabs.com today. Let me get the current bucket config to write accurate HCL.

Check bucket region

$ aws s3api get-bucket-location --bucket i-need-this-bucket-sorry-for-click-opsing
{
    "LocationConstraint": null
}

Get bucket encryption config

$ aws s3api get-bucket-encryption --bucket i-need-this-bucket-sorry-for-click-opsing
{
    "ServerSideEncryptionConfiguration": {
        "Rules": [
            {
                "ApplyServerSideEncryptionByDefault": {
                    "SSEAlgorithm": "AES256"
                },
                "BucketKeyEnabled": true
            }
        ]
    }
}

Get public access block config

$ aws s3api get-public-access-block --bucket i-need-this-bucket-sorry-for-click-opsing
{
    "PublicAccessBlockConfiguration": {
        "BlockPublicAcls": true,
        "IgnorePublicAcls": true,
        "BlockPublicPolicy": true,
        "RestrictPublicBuckets": true
    }
}

Get bucket versioning config

$ aws s3api get-bucket-versioning --bucket i-need-this-bucket-sorry-for-click-opsing
# (no output — versioning not enabled)

Get bucket ownership controls

$ aws s3api get-bucket-ownership-controls --bucket i-need-this-bucket-sorry-for-click-opsing
{
    "OwnershipControls": {
        "Rules": [
            {
                "ObjectOwnership": "BucketOwnerEnforced"
            }
        ]
    }
}

Get bucket tags

$ aws s3api get-bucket-tagging --bucket i-need-this-bucket-sorry-for-click-opsing
An error occurred (NoSuchTagSet) when calling the GetBucketTagging operation: The TagSet does not exist

Bucket is in us-east-1 (LocationConstraint: null) — matches the sandbox provider. Now I'll add the HCL and run the full import workflow.

Add HCL to main.tf — added aws_s3_bucket, aws_s3_bucket_server_side_encryption_configuration, aws_s3_bucket_public_access_block, and aws_s3_bucket_ownership_controls resources, all with provider = aws.sandbox-admin.

Now running init, import, and plan.

Initialize Terraform

$ terraform init -input=false
...
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory.

Import S3 bucket

$ terraform import 'aws_s3_bucket.clickops_bucket' 'i-need-this-bucket-sorry-for-click-opsing'
aws_s3_bucket.clickops_bucket: Import prepared!
Import successful!

Import S3 bucket encryption

$ terraform import 'aws_s3_bucket_server_side_encryption_configuration.clickops_bucket' \
    'i-need-this-bucket-sorry-for-click-opsing'
aws_s3_bucket_server_side_encryption_configuration.clickops_bucket: Import prepared!
Import successful!

Import S3 public access block

$ terraform import 'aws_s3_bucket_public_access_block.clickops_bucket' \
    'i-need-this-bucket-sorry-for-click-opsing'
aws_s3_bucket_public_access_block.clickops_bucket: Import prepared!
Import successful!

Import S3 ownership controls

$ terraform import 'aws_s3_bucket_ownership_controls.clickops_bucket' \
    'i-need-this-bucket-sorry-for-click-opsing'
aws_s3_bucket_ownership_controls.clickops_bucket: Import prepared!
Import successful!

All 4 resources imported. Running plan to verify zero diff.

Verify zero diff with terraform plan

$ terraform plan
...
No changes. Your infrastructure matches the configuration.

No changes — the plan is clean.


Summary:

  • 1 ClickOps resource found: S3 bucket i-need-this-bucket-sorry-for-click-opsing (created by alex@engseclabs.com today via console)
  • 4 Terraform resources added to main.tf:
    • aws_s3_bucket.clickops_bucket
    • aws_s3_bucket_server_side_encryption_configuration.clickops_bucket (AES256, bucket key enabled)
    • aws_s3_bucket_public_access_block.clickops_bucket (all 4 blocks enabled)
    • aws_s3_bucket_ownership_controls.clickops_bucket (BucketOwnerEnforced)
  • All resources imported into state with provider = aws.sandbox-admin
  • terraform plan confirms zero diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment