2022-03-10 14:26:22 +00:00
|
|
|
from app import app
|
2022-04-22 14:01:16 +01:00
|
|
|
from app.models.base import Group
|
2022-03-10 14:26:22 +00:00
|
|
|
from app.terraform import BaseAutomation
|
|
|
|
|
|
|
|
|
|
|
|
class EotkAutomation(BaseAutomation):
|
|
|
|
short_name = "eotk"
|
|
|
|
|
|
|
|
template_parameters = [
|
|
|
|
"aws_access_key",
|
|
|
|
"aws_secret_key"
|
|
|
|
]
|
|
|
|
|
|
|
|
template = """
|
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
aws = {
|
|
|
|
version = "~> 4.4.0"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
provider "aws" {
|
|
|
|
access_key = "{{ aws_access_key }}"
|
|
|
|
secret_key = "{{ aws_secret_key }}"
|
2022-04-25 12:58:49 +01:00
|
|
|
region = "us-east-2"
|
|
|
|
}
|
|
|
|
|
|
|
|
provider "aws" {
|
|
|
|
access_key = "{{ aws_access_key }}"
|
|
|
|
secret_key = "{{ aws_secret_key }}"
|
|
|
|
region = "eu-central-1"
|
|
|
|
alias = "second_region"
|
2022-03-10 14:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{% for group in groups %}
|
2022-04-25 12:58:49 +01:00
|
|
|
module "eotk_{{ group.id }}" {
|
|
|
|
providers = {
|
|
|
|
aws = aws,
|
|
|
|
aws.second_region = aws.second_region
|
|
|
|
}
|
|
|
|
source = "sr2c/eotk/aws"
|
2022-05-03 15:33:49 +01:00
|
|
|
version = "0.0.5"
|
2022-03-10 14:26:22 +00:00
|
|
|
namespace = "{{ global_namespace }}"
|
|
|
|
tenant = "{{ group.group_name }}"
|
2022-04-25 12:58:49 +01:00
|
|
|
name = "eotk"
|
2022-03-10 14:26:22 +00:00
|
|
|
label_order = ["namespace", "tenant", "name", "attributes"]
|
2022-04-25 13:04:06 +01:00
|
|
|
disable_api_termination = true
|
2022-03-10 14:26:22 +00:00
|
|
|
}
|
|
|
|
{% endfor %}
|
|
|
|
"""
|
|
|
|
|
|
|
|
def generate_terraform(self):
|
|
|
|
self.write_terraform_config(
|
|
|
|
self.template,
|
|
|
|
groups=Group.query.filter(Group.eotk == True).all(),
|
|
|
|
global_namespace=app.config['GLOBAL_NAMESPACE'],
|
|
|
|
**{
|
|
|
|
k: app.config[k.upper()]
|
|
|
|
for k in self.template_parameters
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
with app.app_context():
|
|
|
|
auto = EotkAutomation()
|
|
|
|
auto.generate_terraform()
|
|
|
|
auto.terraform_init()
|
|
|
|
auto.terraform_apply()
|