homebrew-core/Formula/atmos.rb

109 lines
3.9 KiB
Ruby

class Atmos < Formula
desc "Universal Tool for DevOps and Cloud Automation"
homepage "https://github.com/cloudposse/atmos"
url "https://github.com/cloudposse/atmos/archive/v1.20.0.tar.gz"
sha256 "378d995ba468d9bc1ced69e886a1e5961b3b8d2f694570e1f6afe8351a631cf5"
license "Apache-2.0"
bottle do
sha256 cellar: :any_skip_relocation, arm64_ventura: "9ef7616b94534e29a43bb63899d6490a996c5eb6ddb6d1b3facea2ade0453007"
sha256 cellar: :any_skip_relocation, arm64_monterey: "465e5537ee46eb3895eba3d398dd4bb22afebc1757588f077b4c972477274bcd"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "a29041117467e6975d587762311f871cc94b1dfa28893b312224ebcced43c983"
sha256 cellar: :any_skip_relocation, ventura: "d76352aeb5ffef57220663013cc84b101a16fbaa099174e2efe743ea239729b6"
sha256 cellar: :any_skip_relocation, monterey: "8e12b886fb6758bc65b827dc8ee176cd894fcdae6a8a276e1803aba921191278"
sha256 cellar: :any_skip_relocation, big_sur: "56cf9e6085503c090f6527b21393e0092c2f673b61732cd7e1f51c35da7e98b7"
sha256 cellar: :any_skip_relocation, x86_64_linux: "da26da07e1505d6d650466cfaade919d764d56dd4457c41291474fc0fedd231d"
end
depends_on "go" => :build
def install
system "go", "build", *std_go_args(ldflags: "-s -w -X 'github.com/cloudposse/atmos/cmd.Version=#{version}'")
generate_completions_from_executable(bin/"atmos", "completion")
end
test do
# create basic atmos.yaml
(testpath/"atmos.yaml").write <<~EOT
components:
terraform:
base_path: "./components/terraform"
apply_auto_approve: false
deploy_run_init: true
auto_generate_backend_file: false
helmfile:
base_path: "./components/helmfile"
kubeconfig_path: "/dev/shm"
helm_aws_profile_pattern: "{namespace}-{tenant}-gbl-{stage}-helm"
cluster_name_pattern: "{namespace}-{tenant}-{environment}-{stage}-eks-cluster"
stacks:
base_path: "./stacks"
included_paths:
- "**/*"
excluded_paths:
- "globals/**/*"
- "catalog/**/*"
- "**/*globals*"
name_pattern: "{tenant}-{environment}-{stage}"
logs:
verbose: false
colors: true
EOT
# create scaffold
mkdir_p testpath/"stacks"
mkdir_p testpath/"components/terraform/top-level-component1"
(testpath/"stacks/tenant1-ue2-dev.yaml").write <<~EOT
terraform:
backend_type: s3 # s3, remote, vault, static, etc.
backend:
s3:
encrypt: true
bucket: "eg-ue2-root-tfstate"
key: "terraform.tfstate"
dynamodb_table: "eg-ue2-root-tfstate-lock"
acl: "bucket-owner-full-control"
region: "us-east-2"
role_arn: null
remote:
vault:
vars:
tenant: tenant1
region: us-east-2
environment: ue2
stage: dev
components:
terraform:
top-level-component1: {}
EOT
# create expected file
(testpath/"backend.tf.json").write <<~EOT
{
"terraform": {
"backend": {
"s3": {
"workspace_key_prefix": "top-level-component1",
"acl": "bucket-owner-full-control",
"bucket": "eg-ue2-root-tfstate",
"dynamodb_table": "eg-ue2-root-tfstate-lock",
"encrypt": true,
"key": "terraform.tfstate",
"region": "us-east-2",
"role_arn": null
}
}
}
}
EOT
system bin/"atmos", "terraform", "generate", "backend", "top-level-component1", "--stack", "tenant1-ue2-dev"
actual_json = JSON.parse(File.read(testpath/"components/terraform/top-level-component1/backend.tf.json"))
expected_json = JSON.parse(File.read(testpath/"backend.tf.json"))
assert_equal expected_json["terraform"].to_set, actual_json["terraform"].to_set
end
end