diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..c6fd22c --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,27 @@ +## Installation + +This plugin gets installed through ```bitops.config.yaml``` in the bitops core level. This file is located [here](https://github.com/bitovi/bitops/blob/plugins/bitops.config.yaml) + + +### Sample Config + +``` +bitops: + fail_fast: true + run_mode: default + logging: + level: DEBUG + color: + enabled: true + filename: bitops-run + err: bitops.logs + path: /var/logs/bitops + opsrepo_root_default_dir: _default + plugins: + cloudformation: + source: https://github.com/bitops-plugins/cloudformation +... +... +... + +``` diff --git a/README.md b/README.md index a2ebeee..331c4f7 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,19 @@ # Bitops Plugin for Cloudformation -## Introduction -This plugin will let BitOps to automatically deploy ``cloudformation`` templates on AWS platform. +## Table of contents -This plugin also manages ``create-stack`` or ``update-stack`` natively at the plugin level. +1. [Introduction](#Introduction) +2. [Installation](https://github.com/bitops-plugins/cloudformation/blob/main/INSTALL.md) +3. [Deployment](#Deployment) -## Installation +--- -This plugin gets installed through ```bitops.config.yaml```. -### Sample Config +## Introduction +This plugin will let BitOps to automatically deploy ``cloudformation`` templates on AWS platform. -``` -bitops: - fail_fast: true - run_mode: default - logging: - level: DEBUG - color: - enabled: true - filename: bitops-run - err: bitops.logs - path: /var/logs/bitops - opsrepo_root_default_dir: _default - plugins: - cloudformation: - source: https://github.com/bitops-plugins/cloudformation -... -... -... +This plugin also manages ``create-stack`` or ``update-stack`` natively at the plugin level. -``` ## Deployment @@ -73,8 +56,15 @@ Calls `aws cloudformation validate-template` * **BitOps Property:** `stack-action` * **Environment Variable:** `BITOPS_CFN_STACK_ACTION` * **default:** `deploy` +* **required:** `"true"` + +Controls what cloudformation action to apply on the stack. This config is a required parameter. -Controls what cloudformation action to apply on the stack +### skip-deploy +* **BitOps Property:** `skip-deploy` +* **Environment Variable:** `CFN_SKIP_DEPLOY` +* **default:** `""` +* **Description:** If set to true, regardless of the stack-action, deployment actions will be skipped. ------------------- @@ -85,8 +75,9 @@ Controls what cloudformation action to apply on the stack * **BitOps Property:** `cfn-stack-name` * **Environment Variable:** `BITOPS_CFN_STACK_NAME` * **default:** `""` +* **required:** `"true"` -Cloudformation stack name +Cloudformation stack name. This config is a required parameter. ------------------- ### capabilities @@ -118,10 +109,14 @@ Cloudformation capabilities * **BitOps Property:** `cfn-files` Allows for param files to be used. Has the following child-properties + #### template-file * **BitOps Property:** `cfn-files.template-file` +* **Environment Variable:** `BITOPS_CFN_TEMPLATE_FILENAME` +* **required:** `"true"` + +Template file to apply the params against. This config is a required parameter. -Template file to apply the params against #### parameters * **BitOps Property:** `cfn-files.parameters` @@ -159,5 +154,5 @@ The directory within the ansible workspace that contains json files that will be Although not captured in `bitops.config.yml`, the following environment variables can be set to further customize behaviour ------------------- -### SKIP_DEPLOY_CLOUDFORMATION +### CFN_SKIP_DEPLOY Will skill all cloudformation executions. This superseeds all other configuration \ No newline at end of file diff --git a/bitops.schema.yaml b/bitops.schema.yaml index 1591d18..9162e61 100644 --- a/bitops.schema.yaml +++ b/bitops.schema.yaml @@ -20,6 +20,10 @@ cloudformation: type: string export_env: CFN_STACK_NAME required: true + skip-deploy: + type: boolean + parameter: skip-deploy + export_env: CFN_SKIP_DEPLOY s3bucket: type: string export_env: CFN_TEMPLATE_S3_BUCKET @@ -35,7 +39,7 @@ cloudformation: template-file: type: string export_env: CFN_TEMPLATE_FILENAME - required: True + required: true parameters: type: object properties: diff --git a/deploy.sh b/deploy.sh index e4be059..0c7ef3a 100755 --- a/deploy.sh +++ b/deploy.sh @@ -11,7 +11,7 @@ echo "Welcome to the CloudFormation BitOps plugin!" # export BITOPS_SCHEMA_ENV_FILE="$CLOUDFORMATION_ROOT/ENV_FILE" # export BITOPS_CONFIG_SCHEMA="$PLUGINS_DIR/cloudformation/bitops.schema.yaml" export PLUGINS_ROOT_DIR="$BITOPS_PLUGINS_DIR" -export CLOUDFORMATION_ROOT_SCRIPTS="$BITOPS_PLUGIN_DIR" +export CLOUDFORMATION_ROOT_SCRIPTS="$BITOPS_INSTALLED_PLUGIN_DIR" export CLOUDFORMATION_ROOT_OPERATIONS="$BITOPS_OPSREPO_ENVIRONMENT_DIR" export CFN_STACK_NAME="$BITOPS_CFN_STACK_NAME" export CFN_TEMPLATE_FILENAME="$BITOPS_CFN_TEMPLATE_FILENAME" @@ -19,6 +19,7 @@ export CFN_TEMPLATE_PARAMS_FILENAME="$BITOPS_CFN_TEMPLATE_PARAMS_FILENAME" export CFN_TEMPLATE_VALIDATION="$BITOPS_CFN_TEMPLATE_VALIDATION" export CFN_STACK_ACTION="$BITOPS_CFN_STACK_ACTION" export CFN_PARAMS_FLAG="$BITOPS_CFN_PARAMS_FLAG" +export CFN_CAPABILITY="$BITOPS_CFN_CAPABILITY" export CLOUDFORMATION_BITOPS_CONFIG="$CLOUDFORMATION_ROOT_OPERATIONS/bitops.config.yaml" export BITOPS_SCHEMA_ENV_FILE="$CLOUDFORMATION_ROOT_OPERATIONS/ENV_FILE" @@ -26,6 +27,11 @@ export BITOPS_CONFIG_SCHEMA="$CLOUDFORMATION_ROOT_SCRIPTS/bitops.schema.yaml" export SCRIPTS_DIR="$CLOUDFORMATION_ROOT_SCRIPTS/scripts" +if [ "$CFN_SKIP_DEPLOY" == "true" ]; then + echo "CFN_SKIP_DEPLOY is set. Skipping." + exit 0 +fi + if [ ! -d "$CLOUDFORMATION_ROOT_OPERATIONS" ]; then echo "No cloudformation directory. Skipping." exit 0 @@ -54,6 +60,14 @@ else fi fi +aws sts get-caller-identity +result=$? +if [ $result != 0 ]; then + echo "AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY required for AWS authentication are not set or invalid." + echo "Check out BitOps documentation to understand what you're missing https://bitops.sh/examples/#docker-run-examples" + exit $result +fi + # Check for Before Deploy Scripts # bash $SCRIPTS_DIR/deploy/before-deploy.sh "$CLOUDFORMATION_ROOT_OPERATIONS" @@ -92,7 +106,7 @@ cd $CLOUDFORMATION_ROOT_OPERATIONS # bash $SCRIPTS_DIR/aws/sts.get-caller-identity.sh # always run cfn template validation first -if [[ "${CFN_TEMPLATE_VALIDATION}" == "True" ]] || [[ "${CFN_TEMPLATE_VALIDATION}" == "true" ]]; then +if [[ "${CFN_TEMPLATE_VALIDATION}" == "true" ]] || [[ "${CFN_TEMPLATE_VALIDATION}" == "True" ]]; then echo "Running Cloudformation Template Validation" bash $CLOUDFORMATION_ROOT_SCRIPTS/scripts/cloudformation_validate.sh "$CFN_TEMPLATE_FILENAME" fi