Last active
May 22, 2023 21:30
-
-
Save walkness/b98799eafcc14b14e23ea501f6f040b6 to your computer and use it in GitHub Desktop.
Generates Terraform Import Commands for v4 AWS S3 Bucket Configuration Changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const rawData = fs.readFileSync("plan.json"); | |
const data = JSON.parse(rawData); | |
const changes = data.resource_changes.filter( | |
(c) => | |
c.change.actions.indexOf("create") !== -1 && | |
c.type.startsWith("aws_s3_bucket_") | |
); | |
const lines = changes.map((c) => { | |
let base = `terraform import ${c.address} ${c.change.after.bucket}`; | |
if (c.type === "aws_s3_bucket_acl") { | |
base = `${base},${c.change.after.acl}`; | |
} | |
return base; | |
}); | |
console.log(lines.join("\n")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Variation for moving Route53 zone to a different account: