feat: add --profile option allowing to overwrite the used AWS profile being used
All checks were successful
ZeroDownTime/CloudBender/pipeline/head This commit looks good

This commit is contained in:
Stefan Reimer 2022-06-30 13:24:44 +02:00
parent 0182847ab3
commit ac51a0774a
4 changed files with 31 additions and 9 deletions

View File

@ -9,6 +9,9 @@ First class support for:
# Installation
The preferred way of running CloudBender is using the public container. This ensure all tools and dependencies are in sync and underwent some basic testing during the development and build phase.
As a fall back CloudBender and its dependencies can be installed locally see step *1b* below.
## 1a. Containerized
@ -50,9 +53,10 @@ which should get you something like:
Usage: cloudbender [OPTIONS] COMMAND [ARGS]...
Options:
--debug Turn on debug logging.
--dir TEXT Specify cloudbender project directory.
--help Show this message and exit.
--profile TEXT Use named AWS .config profile, overwrites any stack config
--dir TEXT Specify cloudbender project directory.
--debug Turn on debug logging.
--help Show this message and exit.
Commands:
assimilate Imports potentially existing resources into Pulumi...

View File

@ -18,10 +18,15 @@ logger = logging.getLogger(__name__)
@click.group()
@click.option("--debug", is_flag=True, help="Turn on debug logging.")
@click.option(
"--profile",
"profile",
help="Use named AWS .config profile, overwrites any stack config",
)
@click.option("--dir", "directory", help="Specify cloudbender project directory.")
@click.option("--debug", is_flag=True, help="Turn on debug logging.")
@click.pass_context
def cli(ctx, debug, directory):
def cli(ctx, profile, debug, directory):
setup_logging(debug)
# Skip parsing all the things if we just want the versions
@ -37,7 +42,7 @@ def cli(ctx, debug, directory):
# Read global config
try:
cb = CloudBender(directory)
cb = CloudBender(directory, profile)
except InvalidProjectDir as e:
logger.error(e)
sys.exit(1)

View File

@ -11,7 +11,7 @@ logger = logging.getLogger(__name__)
class CloudBender(object):
"""Config Class to handle recursive conf/* config tree"""
def __init__(self, root_path):
def __init__(self, root_path, profile):
self.root = pathlib.Path(root_path)
self.sg = None
self.all_stacks = []
@ -22,8 +22,12 @@ class CloudBender(object):
"docs_path": self.root.joinpath("docs"),
"outputs_path": self.root.joinpath("outputs"),
"artifact_paths": [self.root.joinpath("artifacts")],
"profile": profile,
}
if profile:
logger.info("Profile overwrite: using {}".format(self.ctx["profile"]))
if not self.ctx["config_path"].is_dir():
raise InvalidProjectDir(
"Check '{0}' exists and is a valid CloudBender project folder.".format(

View File

@ -56,7 +56,7 @@ class Stack(object):
self.outputs = {}
self.options = {}
self.region = "global"
self.profile = "default"
self.profile = None
self.onfailure = "DELETE"
self.notfication_sns = []
@ -103,10 +103,19 @@ class Stack(object):
self.pulumi.update(sg_config.get("pulumi", {}))
# by default inherit parent group settings
for p in ["region", "profile", "notfication_sns", "template_bucket_url"]:
for p in ["region", "notfication_sns", "template_bucket_url"]:
if p in sg_config:
setattr(self, p, sg_config[p])
# profile needs special treatment due to cmd line overwrite option
if self.ctx["profile"]:
self.profile = self.ctx["profile"]
else:
if "profile" in sg_config:
self.profile = sg_config["profile"]
else:
self.profile = "default"
# now override stack specific settings
_config = read_config_file(self.path, sg_config.get("variables", {}))
for p in [