lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -15,21 +15,26 @@ from app.terraform.terraform import TerraformAutomation
|
|||
def import_state(state: Any) -> None:
|
||||
if not isinstance(state, dict):
|
||||
raise RuntimeError("The Terraform state object returned was not a dict.")
|
||||
if "values" not in state or "child_modules" not in state['values']['root_module']:
|
||||
if "values" not in state or "child_modules" not in state["values"]["root_module"]:
|
||||
# There are no CloudFront origins deployed to import state for
|
||||
return
|
||||
# CloudFront distributions (origins)
|
||||
for mod in state['values']['root_module']['child_modules']:
|
||||
if mod['address'].startswith('module.static_'):
|
||||
static_id = mod['address'][len('module.static_'):]
|
||||
for mod in state["values"]["root_module"]["child_modules"]:
|
||||
if mod["address"].startswith("module.static_"):
|
||||
static_id = mod["address"][len("module.static_") :]
|
||||
logging.debug("Found static module in state: %s", static_id)
|
||||
for res in mod['resources']:
|
||||
if res['address'].endswith('aws_cloudfront_distribution.this'):
|
||||
for res in mod["resources"]:
|
||||
if res["address"].endswith("aws_cloudfront_distribution.this"):
|
||||
logging.debug("and found related cloudfront distribution")
|
||||
static = StaticOrigin.query.filter(StaticOrigin.id == static_id).first()
|
||||
static.origin_domain_name = res['values']['domain_name']
|
||||
logging.debug("and found static origin: %s to update with domain name: %s", static.id,
|
||||
static.origin_domain_name)
|
||||
static = StaticOrigin.query.filter(
|
||||
StaticOrigin.id == static_id
|
||||
).first()
|
||||
static.origin_domain_name = res["values"]["domain_name"]
|
||||
logging.debug(
|
||||
"and found static origin: %s to update with domain name: %s",
|
||||
static.id,
|
||||
static.origin_domain_name,
|
||||
)
|
||||
static.terraform_updated = datetime.now(tz=timezone.utc)
|
||||
break
|
||||
db.session.commit()
|
||||
|
@ -128,14 +133,18 @@ class StaticAWSAutomation(TerraformAutomation):
|
|||
groups=groups,
|
||||
storage_cloud_accounts=storage_cloud_accounts,
|
||||
source_cloud_accounts=source_cloud_accounts,
|
||||
global_namespace=current_app.config['GLOBAL_NAMESPACE'], bypass_token=current_app.config['BYPASS_TOKEN'],
|
||||
terraform_modules_path=os.path.join(*list(os.path.split(current_app.root_path))[:-1], 'terraform-modules'),
|
||||
global_namespace=current_app.config["GLOBAL_NAMESPACE"],
|
||||
bypass_token=current_app.config["BYPASS_TOKEN"],
|
||||
terraform_modules_path=os.path.join(
|
||||
*list(os.path.split(current_app.root_path))[:-1], "terraform-modules"
|
||||
),
|
||||
backend_config=f"""backend "http" {{
|
||||
lock_address = "{current_app.config['TFSTATE_BACKEND']}/{self.short_name}"
|
||||
unlock_address = "{current_app.config['TFSTATE_BACKEND']}/{self.short_name}"
|
||||
address = "{current_app.config['TFSTATE_BACKEND']}/{self.short_name}"
|
||||
}}""",
|
||||
**{k: current_app.config[k.upper()] for k in self.template_parameters})
|
||||
**{k: current_app.config[k.upper()] for k in self.template_parameters},
|
||||
)
|
||||
|
||||
def tf_posthook(self, *, prehook_result: Any = None) -> None:
|
||||
import_state(self.tf_show())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue