carlos / opentofu Public

Clone
git clone https://amadan.net/carlos/opentofu

Plain git — no account needed to clone.

Download

Download this file

1override_resource {
2 target = module.deployment.aws_s3_bucket.this
3 values = { id = "test-control", arn = "arn:aws:s3:::test-control" }
4}
5override_resource {
6 target = module.primary_data.aws_s3_bucket.this
7 values = { id = "test-primary", arn = "arn:aws:s3:::test-primary" }
8}
9override_resource {
10 target = module.secondary_data.aws_s3_bucket.this
11 values = { id = "test-secondary", arn = "arn:aws:s3:::test-secondary" }
12}
13mock_provider "aws" {
14 mock_data "aws_ec2_instance_type_offerings" { defaults = { locations = ["eu-west-1a", "eu-west-1b"] } }
15 alias = "primary"
16 mock_data "aws_region" { defaults = { region = "eu-west-1" } }
17 mock_data "aws_availability_zones" { defaults = { names = ["eu-west-1a", "eu-west-1b"] } }
18 mock_data "aws_ami" { defaults = { id = "ami-0123456789abcdef0" } }
19 mock_resource "aws_s3_bucket" { defaults = { arn = "arn:aws:s3:::mock-test-bucket", id = "mock-test-bucket" } }
20 mock_resource "aws_iam_role" { defaults = { arn = "arn:aws:iam::123456789012:role/test" } }
21}
22mock_provider "aws" {
23 mock_data "aws_ec2_instance_type_offerings" { defaults = { locations = ["eu-west-2a", "eu-west-2b"] } }
24 alias = "secondary"
25 mock_data "aws_region" { defaults = { region = "eu-west-2" } }
26 mock_data "aws_availability_zones" { defaults = { names = ["eu-west-2a", "eu-west-2b"] } }
27 mock_data "aws_ami" { defaults = { id = "ami-0123456789abcdef0" } }
28 mock_resource "aws_s3_bucket" { defaults = { arn = "arn:aws:s3:::mock-test-bucket", id = "mock-test-bucket" } }
29 mock_resource "aws_iam_role" { defaults = { arn = "arn:aws:iam::123456789012:role/test" } }
30}
31variables {
32 aws_account_id = "123456789012"
33 name = "test-carlos"
34 apps_domain = "apps.example.com"
35 release_public_key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
36}
37run "topology" {
38 assert {
39 condition = toset(module.secondary.storage.object_resources) == toset(["arn:aws:s3:::test-control/*", "arn:aws:s3:::test-secondary/*"])
40 error_message = "The secondary region must not access the primary region's data."
41 }
42 assert {
43 condition = module.secondary.storage.data_bucket == "test-secondary" && module.secondary.storage.data_region == "eu-west-2" && module.secondary.storage.deployment_region == "eu-west-1" && module.secondary.storage.deployment_bucket == "test-control"
44 error_message = "Secondary-region storage and control-plane routing are crossed."
45 }
46 command = plan
47 assert {
48 condition = module.primary.host_count == 1 && module.secondary.host_count == 1
49 error_message = "Unexpected host count."
50 }
51}
52run "reject_invalid_public_key" {
53 command = plan
54 variables { release_public_key = "not-a-public-key" }
55 expect_failures = [var.release_public_key]
56}
57run "reject_shell_in_domain" {
58 command = plan
59 variables { apps_domain = "apps.example.com\nENVEOF\necho bad" }
60 expect_failures = [var.apps_domain]
61}
62run "reject_same_region" {
63 command = plan
64 variables { secondary_region = "eu-west-1" }
65 expect_failures = [terraform_data.topology]
66}
67