Skip to content

Commit

Permalink
inline it all!
Browse files Browse the repository at this point in the history
  • Loading branch information
ksugden committed Jan 10, 2025
1 parent 6c7ec8c commit 58695dd
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions dbt_platform_helper/domain/terraform_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,34 @@


class TerraformEnvironment:
def __init__(self, config_provider):
def __init__(self, config_provider, echo_fn=click.echo):
self.echo = echo_fn
self.config_provider = config_provider
self.template = setup_templates().get_template("environments/main.tf")
self.config = self.config_provider.apply_environment_defaults(
self.config_provider.load_and_validate_platform_config()
)

def generate(self, environment_name, terraform_platform_modules_version_override=None):
env_config = self.config["environments"][environment_name]
terraform_platform_modules_version = (
terraform_platform_modules_version_override
or self.config["environments"][environment_name]
.get("versions", {})
.get("terraform-platform-modules")
or DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION
)

contents = self.template.render(
{
"application": self.config["application"],
"environment": environment_name,
"config": env_config,
"terraform_platform_modules_version": self._determine_terraform_platform_modules_version(
env_config, terraform_platform_modules_version_override
),
"config": self.config["environments"][environment_name],
"terraform_platform_modules_version": terraform_platform_modules_version,
}
)

click.echo(
self.echo(
FileProvider.mkfile(
".", f"terraform/environments/{environment_name}/main.tf", contents, overwrite=True
)
)

def _determine_terraform_platform_modules_version(
self, env_conf, terraform_platform_modules_version_override
):
"""
Terraform platform modules version can be defined as an override, within
the config, or defaulted. An override is always prioritied, followed by
config version.
Returns:
string: version by priority
"""
if terraform_platform_modules_version_override:
return terraform_platform_modules_version_override

config_version = env_conf.get("versions", {}).get("terraform-platform-modules")

if config_version:
return config_version

return DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION

0 comments on commit 58695dd

Please sign in to comment.