-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/m policies #447
Fix/m policies #447
Changes from all commits
b1e7e9f
d815ff4
99b4bce
eb835a2
5708399
a61e6d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
import logging | ||
import os | ||
import time | ||
from typing import Any, List, Optional, Tuple | ||
from typing import Any, Dict, List, Optional, Tuple, cast | ||
|
||
from aws_codeseeder import EnvVar, EnvVarType, codeseeder, commands, services | ||
from cfn_tools import load_yaml | ||
|
@@ -99,10 +99,17 @@ def destroy_managed_policy_stack(account_id: str, region: str) -> None: | |
""" | ||
# Determine if managed policy stack already deployed | ||
session = SessionManager().get_or_create().get_deployment_session(account_id=account_id, region_name=region) | ||
project_managed_policy_stack_exists, _ = services.cfn.does_stack_exist( | ||
project_managed_policy_stack_exists, stack_outputs = services.cfn.does_stack_exist( | ||
stack_name=info.PROJECT_MANAGED_POLICY_CFN_NAME, session=session | ||
) | ||
_logger.debug("project_managed_policy_output is : %s", stack_outputs) | ||
has_roles_attached = False | ||
if project_managed_policy_stack_exists: | ||
project_managed_policy_arn = stack_outputs.get("ProjectPolicyARN") | ||
policy = iam.get_policy_info(policy_arn=project_managed_policy_arn, session=session) | ||
has_roles_attached = True if policy and policy["Policy"]["AttachmentCount"] > 0 else False | ||
|
||
if project_managed_policy_stack_exists and not has_roles_attached: | ||
_logger.info( | ||
"Destroying Stack %s in Account/Region: %s/%s", info.PROJECT_MANAGED_POLICY_CFN_NAME, account_id, region | ||
) | ||
|
@@ -117,6 +124,13 @@ def destroy_managed_policy_stack(account_id: str, region: str) -> None: | |
_logger.info( | ||
f"Failed to delete project stack {info.PROJECT_MANAGED_POLICY_CFN_NAME}, ignoring and moving on" | ||
) | ||
else: | ||
_logger.info( | ||
"Stack %s in Account/Region: %s/%s is either not deployed or has roles attached", | ||
info.PROJECT_MANAGED_POLICY_CFN_NAME, | ||
account_id, | ||
region, | ||
) | ||
|
||
|
||
def destroy_module_stack( | ||
|
@@ -307,13 +321,29 @@ def deploy_module_stack( | |
seedkit_managed_policy_arn = stack_outputs.get("SeedkitResourcesPolicyArn") | ||
|
||
# Extract Project Managed policy name | ||
project_managed_policy_stack_exists, stack_outputs = services.cfn.does_stack_exist( | ||
stack_name=info.PROJECT_MANAGED_POLICY_CFN_NAME, session=session | ||
) | ||
|
||
_logger.debug("project_managed_policy_output is : %s", stack_outputs) | ||
if project_managed_policy_stack_exists: | ||
project_managed_policy_arn = stack_outputs.get("ProjectPolicyARN") | ||
def _check_stack_status() -> Tuple[bool, Dict[str, str]]: | ||
return cast( | ||
Tuple[bool, Dict[str, str]], | ||
services.cfn.does_stack_exist(stack_name=info.PROJECT_MANAGED_POLICY_CFN_NAME, session=session), | ||
) | ||
|
||
retries = 3 | ||
project_managed_policy_arn = None | ||
while retries > 0: | ||
project_managed_policy_stack_exists, stack_outputs = _check_stack_status() | ||
if project_managed_policy_stack_exists: | ||
if stack_outputs.get("StackStatus") and "_IN_PROGRESS" in stack_outputs.get("StackStatus"): | ||
_logger.info("The managed policy stack is not complete, waiting 30 seconds") | ||
time.sleep(30) | ||
retries -= 1 | ||
else: | ||
_logger.debug("project_managed_policy_output is : %s", stack_outputs) | ||
project_managed_policy_arn = stack_outputs.get("ProjectPolicyARN", None) | ||
retries = -1 | ||
else: | ||
_logger.debug("project_managed_policy_output does not exist") | ||
retries = -1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need for this retry? we should retry only when the managed policy stack is in "*IN_PROGRESS" state There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this signals to break out of the loop... sets retries equal to -1 |
||
|
||
if not project_managed_policy_arn: | ||
raise seedfarmer.errors.InvalidConfigurationError( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should it retry once the
project_managed_policy_arn
is obtained? shoudn't this bebreak
out of the while loop?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not...it is setting the retries value to -1