terraform: generate conf with http backend

This commit is contained in:
Iain Learmonth 2022-08-30 10:05:12 +01:00
parent affa0f0149
commit 32239c379a
16 changed files with 43 additions and 4 deletions

View file

@ -1,4 +1,5 @@
import datetime
import os
from typing import Iterable, Optional, Any, List
from app import app
@ -70,6 +71,12 @@ class BridgeAutomation(TerraformAutomation):
BridgeConf.provider == self.provider
).all(),
global_namespace=app.config['GLOBAL_NAMESPACE'],
terraform_modules_path=os.path.join(*list(os.path.split(app.root_path))[:-1], 'terraform-modules'),
backend_config=f"""backend "http" {{
lock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
unlock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
}}""",
**{
k: app.config[k.upper()]
for k in self.template_parameters

View file

@ -14,6 +14,7 @@ class BridgeAWSAutomation(BridgeAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
aws = {
version = "~> 4.2.0"

View file

@ -16,6 +16,7 @@ class BridgeGandiAutomation(BridgeAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"

View file

@ -13,6 +13,7 @@ class BridgeHcloudAutomation(BridgeAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
random = {
source = "hashicorp/random"

View file

@ -19,6 +19,7 @@ class BridgeOvhAutomation(BridgeAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
random = {
source = "hashicorp/random"

View file

@ -1,4 +1,5 @@
import datetime
import os
from typing import Any
from app import app
@ -39,6 +40,7 @@ class EotkAWSAutomation(TerraformAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
aws = {
version = "~> 4.4.0"
@ -84,6 +86,12 @@ class EotkAWSAutomation(TerraformAutomation):
Group.destroyed.is_(None)
).all(),
global_namespace=app.config['GLOBAL_NAMESPACE'],
terraform_modules_path=os.path.join(*list(os.path.split(app.root_path))[:-1], 'terraform-modules'),
backend_config=f"""backend "http" {{
lock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
unlock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
}}""",
**{
k: app.config[k.upper()]
for k in self.template_parameters

View file

@ -50,6 +50,12 @@ class ListAutomation(TerraformAutomation):
MirrorList.provider == self.provider,
).all(),
global_namespace=app.config['GLOBAL_NAMESPACE'],
terraform_modules_path=os.path.join(*list(os.path.split(app.root_path))[:-1], 'terraform-modules'),
backend_config=f"""backend "http" {{
lock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
unlock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
}}""",
**{
k: app.config[k.upper()]
for k in self.template_parameters

View file

@ -17,6 +17,7 @@ class ListGithubAutomation(ListAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
github = {
source = "integrations/github"

View file

@ -16,6 +16,7 @@ class ListGitlabAutomation(ListAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
gitlab = {
source = "gitlabhq/gitlab"

View file

@ -13,6 +13,7 @@ class ListS3Automation(ListAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
aws = {
version = "~> 4.4.0"

View file

@ -39,6 +39,10 @@ def update_smart_proxy_instance(group_id: int,
instance.instance_id = instance_id
def sp_trusted_prefixes() -> str:
return "\n".join([f"geoip2_proxy {p};" for p in all_cdn_prefixes()])
class ProxyAutomation(TerraformAutomation):
subgroup_max = math.inf
"""
@ -154,14 +158,16 @@ class ProxyAutomation(TerraformAutomation):
Proxy.provider == self.provider, Proxy.destroyed.is_(None)).all(), subgroups=self.get_subgroups(),
global_namespace=app.config['GLOBAL_NAMESPACE'], bypass_token=app.config['BYPASS_TOKEN'],
terraform_modules_path=os.path.join(*list(os.path.split(app.root_path))[:-1], 'terraform-modules'),
backend_config=f"""backend "http" {{
lock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
unlock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
}}""",
**{k: app.config[k.upper()] for k in self.template_parameters})
if self.smart_proxies:
for group in groups:
self.sp_config(group)
def sp_trusted_prefixes(self) -> str:
return "\n".join([f"geoip2_proxy {p};" for p in all_cdn_prefixes()])
def sp_config(self, group: Group) -> None:
group_origins: List[Origin] = Origin.query.filter(
Origin.group_id == group.id,
@ -174,7 +180,7 @@ class ProxyAutomation(TerraformAutomation):
$geoip2_metadata_country_build metadata build_epoch;
$geoip2_data_country_code default=US country iso_code;
}
""" + self.sp_trusted_prefixes() + """
""" + sp_trusted_prefixes() + """
geoip2_proxy_recursive on;
map $geoip2_data_country_code $redirect_country {
default yes;

View file

@ -25,6 +25,7 @@ class ProxyAzureCdnAutomation(ProxyAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
azurerm = {
source = "hashicorp/azurerm"

View file

@ -25,6 +25,7 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
acme = {
source = "vancluever/acme"

View file

@ -20,6 +20,7 @@ class ProxyFastlyAutomation(ProxyAutomation):
template = """
terraform {
{{ backend_config }}
required_providers {
aws = {
version = "~> 4.4.0"