Skip to content

Commit

Permalink
Add PlatformTerraformManifestGenerator class
Browse files Browse the repository at this point in the history
  • Loading branch information
ksugden committed Jan 10, 2025
1 parent 58695dd commit 03fc0d3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
29 changes: 29 additions & 0 deletions dbt_platform_helper/domain/terraform_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@
from dbt_platform_helper.utils.template import setup_templates


class PlatformTerraformManifestGenerator:
def __init__(self):
self.manifest_template = setup_templates().get_template("environments/main.tf")

def generate_manifest(
self,
application_name: str,
environment_name: str,
environment_config,
terraform_platform_modules_version_override=None,
):
terraform_platform_modules_version = (
terraform_platform_modules_version_override
or environment_config.get("versions", {}).get(
"terraform-platform-modules", DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION
)
)
print(environment_config)

return self.manifest_template.render(
{
"application": application_name,
"environment": environment_name,
"config": environment_config,
"terraform_platform_modules_version": terraform_platform_modules_version,
}
)


class TerraformEnvironment:
def __init__(self, config_provider, echo_fn=click.echo):
self.echo = echo_fn
Expand Down
28 changes: 28 additions & 0 deletions dbt_platform_helper/domain/test_terraform_manifest_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from dbt_platform_helper.domain.terraform_environment import (
PlatformTerraformManifestGenerator,
)


class TestTerraformManifestGenerator:
def test_generator_generates_expected_manifest_content_with_version_override(self):
test_environment_config = {
"vpc": "vpc3",
"accounts": {
"deploy": {"name": "non-prod-acc", "id": "1122334455"},
"dns": {"name": "non-prod-dns-acc", "id": "6677889900"},
},
"versions": {"terraform-platform-modules": 3},
}
expected_header = "# WARNING: This is an autogenerated file, not for manual editing."
expected_modules = "git::https://github.com/uktrade/terraform-platform-modules.git//extensions?depth=1&ref=123456"
expected_moved_block = (
"moved {\n from = module.extensions-tf\n to = module.extensions\n}\n"
)

result = PlatformTerraformManifestGenerator().generate_manifest(
"test-app", "test", test_environment_config, 123456
)

assert expected_header in result
assert expected_modules in result
assert expected_moved_block in result

0 comments on commit 03fc0d3

Please sign in to comment.