diff --git a/.gitmodules b/.gitmodules index 9b7f929..a774209 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "BP-BASE-SHELL-STEPS"] path = BP-BASE-SHELL-STEPS url = https://github.com/OT-BUILDPIPER-MARKETPLACE/BP-BASE-SHELL-STEPS.git + branch = v0.6 \ No newline at end of file diff --git a/BP-BASE-SHELL-STEPS b/BP-BASE-SHELL-STEPS new file mode 160000 index 0000000..f17d79e --- /dev/null +++ b/BP-BASE-SHELL-STEPS @@ -0,0 +1 @@ +Subproject commit f17d79e471c6e30174de519b1949bb83a6f070ba diff --git a/BP-BASE-SHELL-STEPS/.github/workflows/reviewdog.yml b/BP-BASE-SHELL-STEPS/.github/workflows/reviewdog.yml deleted file mode 100644 index 824ee7e..0000000 --- a/BP-BASE-SHELL-STEPS/.github/workflows/reviewdog.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: reviewdog -on: [pull_request] -jobs: - shellcheck: - name: runner / shellcheck - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: shellcheck - uses: reviewdog/action-shellcheck@v1 - with: - github_token: ${{ secrets.github_token }} - reporter: github-pr-review # Change reporter. - path: "." # Optional. - pattern: "*.sh" # Optional. - exclude: "./.git/*" # Optional. - check_all_files_with_shebangs: "false" # Optional. diff --git a/BP-BASE-SHELL-STEPS/README.md b/BP-BASE-SHELL-STEPS/README.md deleted file mode 100644 index 1af2fae..0000000 --- a/BP-BASE-SHELL-STEPS/README.md +++ /dev/null @@ -1 +0,0 @@ -# BP-BASE-SHELL-STEPS \ No newline at end of file diff --git a/BP-BASE-SHELL-STEPS/functions.sh b/BP-BASE-SHELL-STEPS/functions.sh deleted file mode 100755 index f276a4c..0000000 --- a/BP-BASE-SHELL-STEPS/functions.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -generateOutput() { - Task=$1 - Status=$2 - Message=$3 - OUTPUT_DIR=/src/${EXECUTION_DIR}/${EXECUTION_TASK_ID} - mkdir -p "${OUTPUT_DIR}" - echo "{ \"${Task}\": {\"status\": \"${Status}\", \"message\": \"${Message}\"}}" | jq . > "${OUTPUT_DIR}"/summary.json - echo "{ \"status\": \"${Status}\", \"message\": \"${Message}\"}" | jq . > "${OUTPUT_DIR}"/"${Task}".json -} - -function getComponentName() { - COMPONENT_NAME=$(jq -r .build_detail.repository.name < /bp/data/environment_build ) - echo "$COMPONENT_NAME" -} - -function getRepositoryTag() { - BUILD_REPOSITORY_TAG=$(jq -r .build_detail.repository.tag < /bp/data/environment_build) - echo "$BUILD_REPOSITORY_TAG" -} - -function saveTaskStatus() { - TASK_STATUS=$1 - ACTIVITY_SUB_TASK_CODE=$2 - - if [ "$TASK_STATUS" -eq 0 ] - then - logInfoMessage "Congratulations ${ACTIVITY_SUB_TASK_CODE} succeeded!!!" - generateOutput "${ACTIVITY_SUB_TASK_CODE}" true "Congratulations ${ACTIVITY_SUB_TASK_CODE} succeeded!!!" - elif [ "$VALIDATION_FAILURE_ACTION" == "FAILURE" ] - then - logErrorMessage "Please check ${ACTIVITY_SUB_TASK_CODE} failed!!!" - generateOutput "${ACTIVITY_SUB_TASK_CODE}" false "Please check ${ACTIVITY_SUB_TASK_CODE} failed!!!" - exit 1 - else - logWarningMessage "Please check ${ACTIVITY_SUB_TASK_CODE} failed!!!" - generateOutput "${ACTIVITY_SUB_TASK_CODE}" true "Please check ${ACTIVITY_SUB_TASK_CODE} failed!!!" - fi -} - - diff --git a/BP-BASE-SHELL-STEPS/log-functions.sh b/BP-BASE-SHELL-STEPS/log-functions.sh deleted file mode 100644 index c7a61ab..0000000 --- a/BP-BASE-SHELL-STEPS/log-functions.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -GREEN="32m" -RED="31m" -YELLOW="1;33m" - -COLOR_START="\e[" -COLOR_END="\e[0m" - -function logColoredMessage() { - COLOR=$1 - LOG_LEVEL=$2 - MESSAGE="$3" - - CURRENT_DATE=$(date "+%D: %T") - echo -e "[$CURRENT_DATE]"" ""${COLOR_START}""${COLOR}""[""$LOG_LEVEL""]""${COLOR_END}"" ""$MESSAGE" -} - -function logInfoMessage() { - MESSAGE="$1" - - logColoredMessage ${GREEN} INFO "${MESSAGE}" -} - -function logErrorMessage() { - MESSAGE="$1" - - logColoredMessage ${RED} ERROR "${MESSAGE}" -} - -function logWarningMessage() { - MESSAGE="$1" - logColoredMessage ${YELLOW} WARNING "${MESSAGE}" -} diff --git a/Dockerfile b/Dockerfile index 092638f..8e07d23 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,15 +2,13 @@ FROM hashicorp/terraform RUN apk add --no-cache --upgrade bash RUN apk add jq +RUN apk add --no-cache aws-cli ENV SLEEP_DURATION 5s COPY build.sh . ADD BP-BASE-SHELL-STEPS /opt/buildpiper/shell-functions/ -ADD modules /opt/buildpiper/modules -ENV ACTIVITY_SUB_TASK_CODE TF_MODULES_EXECUTE ENV INSTRUCTION "apply" -ENV MODULE "ELASTICACHE" ENTRYPOINT [ "./build.sh" ] diff --git a/README.md b/README.md index 8250a03..0901f9d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ I'll let people to use all the available OpsTree tf module via this step ``` git submodule init git submodule update -docker build -t ot/tf-modules-step:0.0.1 . +docker build -t ot/tf-modules-step:0.1 . ``` diff --git a/build.sh b/build.sh index 6a7b774..8e7be7e 100755 --- a/build.sh +++ b/build.sh @@ -1,13 +1,17 @@ #!/bin/bash source /opt/buildpiper/shell-functions/functions.sh source /opt/buildpiper/shell-functions/log-functions.sh +source /opt/buildpiper/shell-functions/aws-functions.sh logInfoMessage "Creating for $MODULE" -logInfoMessage "I'll create/update [$MODULE] whose properties are available at [$WORKSPACE] and have mounted at [$CODEBASE_DIR]" +tfCodeLocation="${WORKSPACE}"/"${CODEBASE_DIR}"/"${TF_CODE_LOCATION}" +logInfoMessage "I'll create/update [$MODULE] available at [$tfCodeLocation]" sleep "$SLEEP_DURATION" -cd "$WORKSPACE"/"${CODEBASE_DIR}" -cp /opt/buildpiper/modules/${MODULE}/*.tf . +getAssumeRole ${AWS_ASSUME_ROLE_ARN} + +cd "${tfCodeLocation}" +cp /opt/buildpiper/modules/* . logInfoMessage "Running below tf command" logInfoMessage "terraform $INSTRUCTION" diff --git a/modules/ELASTICACHE/elasticache.tf b/modules/ELASTICACHE/elasticache.tf deleted file mode 100644 index 6dff613..0000000 --- a/modules/ELASTICACHE/elasticache.tf +++ /dev/null @@ -1,37 +0,0 @@ -module "elasticache" { - source = "OT-CLOUD-KIT/elasticache/aws" - version = "0.0.1" - name = var.name - notification_topic_arn = var.notification_topic_arn - security_group_ids = var.security_group_ids - snapshot_arns = var.snapshot_arns - snapshot_name = var.snapshot_name - subnet_ids = var.subnet_ids - apply_immediately = var.apply_immediately - at_rest_encryption_enabled = var.at_rest_encryption_enabled - auth_token = var.auth_token - auto_minor_version_upgrade = var.auto_minor_version_upgrade - automatic_failover_enabled = var.automatic_failover_enabled - cluster_mode_enabled = var.cluster_mode_enabled - final_snapshot_identifier = var.final_snapshot_identifier - kms_key_id = var.kms_key_id - maintenance_window = var.maintenance_window - multi_az_enabled = var.multi_az_enabled - node_type = var.node_type - num_node_groups = var.num_node_groups - number_cache_clusters = var.number_cache_clusters - parameter = var.parameter - parameter_group_enabled = var.parameter_group_enabled - parameter_group_name = var.parameter_group_name - port = var.port - redis_engine_version = var.redis_engine_version - redis_family = var.redis_family - replicas_per_node_group = var.replicas_per_node_group - replication_group_description = var.replication_group_description - snapshot_retention_limit = var.snapshot_retention_limit - snapshot_window = var.snapshot_window - subnet_group_name = var.subnet_group_name - tags = var.tags - transit_encryption_enabled = var.transit_encryption_enabled -} - diff --git a/modules/ELASTICACHE/elasticache_variable.tf b/modules/ELASTICACHE/elasticache_variable.tf deleted file mode 100644 index de31d5a..0000000 --- a/modules/ELASTICACHE/elasticache_variable.tf +++ /dev/null @@ -1,180 +0,0 @@ -variable "name" { - type = string - description = "Name of the cluster" -} -variable "notification_topic_arn" { - type = string - default = null - description = "An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: arn:aws:sns:us-east-1:012345678999:my_sns_topic" -} -variable "security_group_ids" { - type = list(string) - description = "One or more Amazon VPC security groups associated with this replication group. Use this parameter only when you are creating a replication group in an Amazon Virtual Private Cloud" -} -variable "snapshot_arns" { - type = list(string) - default = null - description = "A list of Amazon Resource Names (ARNs) that identify Redis RDB snapshot files stored in Amazon S3. The names object names cannot contain any commas." -} -variable "snapshot_name" { - type = string - default = null - description = "The name of a snapshot from which to restore data into the new node group. Changing the snapshot_name forces a new resource." -} -variable "subnet_ids" { - type = list(string) - description = "List of VPC Subnet IDs for the cache subnet group" -} -variable "apply_immediately" { - type = bool - default = false - description = "Specifies whether any modifications are applied immediately, or during the next maintenance window. Default is false." -} -variable "at_rest_encryption_enabled" { - type = bool - default = false - description = "Whether to enable encryption at rest." -} -variable "auth_token" { - type = string - default = "" - description = "The password used to access a password protected server. Can be specified only if transit_encryption_enabled = true." -} -variable "auto_minor_version_upgrade" { - type = bool - default = true - description = "Specifies whether a minor engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. This parameter is currently not supported by the AWS API. Defaults to true." -} -variable "automatic_failover_enabled" { - type = bool - default = false - description = "Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. If enabled, number_cache_clusters must be greater than 1." -} -variable "cluster_mode_enabled" { - type = bool - default = false - description = "Specify the mode of redis cluster means cluster mode disabled and cluster mode enabled" -} -variable "final_snapshot_identifier" { - type = string - default = "" - description = "The name of your final node group (shard) snapshot. ElastiCache creates the snapshot from the primary node in the cluster. If omitted, no final snapshot will be made." -} -variable "kms_key_id" { - type = string - default = "" - description = "The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if at_rest_encryption_enabled = true." -} -variable "maintenance_window" { - type = string - default = "sun:05:00-sun:09:00" - description = "Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period. Example: sun:05:00-sun:09:00" -} -variable "multi_az_enabled" { - type = bool - default = false - description = "Specifies whether to enable Multi-AZ Support for the replication group." -} -variable "node_type" { - type = string - default = "cache.t2.micro" - description = " The instance class to be used." - validation { - #regex(...) fails if it cannot find a match - condition = can(regex("^cache.", var.node_type)) - error_message = "The node_type value must be a valid Node Type, starting with \"cache.\"." - } -} -variable "num_node_groups" { - type = number - default = 1 - description = "Specify the number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications." - validation { - condition = contains(range(1, 91), var.num_node_groups) - error_message = "Required when `cluster_mode_enabled` is set to true. Specify the number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications. Valid values are 1 to 90." - } -} -variable "number_cache_clusters" { - type = number - default = 1 - description = "The number of cache clusters (primary and replicas) this replication group will have. If Multi-AZ is enabled, the value of this parameter must be at least 2. Updates will occur before other modifications." -} -variable "parameter" { - type = list(object({ - name = string - value = string - })) - default = [] - description = "A list of Redis & memcached parameters to apply depends engine type. Note that parameters may differ from one family to another" -} -variable "parameter_group_enabled" { - type = bool - default = true - description = "If you want to create Elasticache parameter from module override this variable." -} -variable "parameter_group_name" { - type = string - default = "" -} -variable "port" { - type = number - default = 6379 - description = "The port number on which each of the cache nodes will accept connections. For Memcache the default is 11211, and for Redis the default port is 6379." -} -variable "redis_engine_version" { - type = string - default = "6.x" - description = "The version number of the cache engine to be used for the cache clusters in this replication group." - validation { - condition = contains(["6.x", "5.0.6", "4.0.10", "3.2.10", "3.2.6", "3.2.4", "2.8.24", "2.8.23", "2.8.22", "2.8.22", "2.8.19", "2.8.6", "2.6.13"], var.redis_engine_version) - error_message = "Currently Redis Supported version are \"6.x\",\"5.0.6\",\"4.0.10\",\"3.2.10\",\"3.2.6\",\"3.2.4\",\"2.8.24\",\"2.8.23\",\"2.8.22\",\"2.8.22\",\"2.8.19\",\"2.8.6\",\"2.6.13\"." - } -} -variable "redis_family" { - type = string - default = "redis6.x" - description = "The family of the Redis cluster parameter group." - validation { - condition = contains(["redis6.x", "redis5.0", "redis4.0", "redis3.2", "redis2.8", "redis2.6"], var.redis_family) - error_message = "Valid values are \"redis6.x\",\"redis5.0\",\"redis4.0\",\"redis3.2\",\"redis2.8\",\"redis2.6\"." - } -} -variable "replicas_per_node_group" { - type = number - default = 0 - description = "Specify the number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will trigger an online resizing operation before other settings modifications." - validation { - condition = contains([0, 1, 2, 3, 4, 5], var.replicas_per_node_group) - error_message = "Specify the number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will trigger an online resizing operation before other settings modifications." - } -} -variable "replication_group_description" { - type = string - description = "Describe of the cluster" - default = "" -} -variable "snapshot_retention_limit" { - type = number - default = 0 - description = "The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot_retention_limit is not supported on cache.t1.micro cache nodes" -} -variable "snapshot_window" { - type = string - default = "03:00-04:00" - description = "The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. The minimum snapshot window is a 60 minute period. Example: 05:00-09:00" -} -variable "subnet_group_name" { - type = string - default = "" - description = "The name of the cache subnet group to be used for the replication group." -} -variable "tags" { - type = map(string) - default = {} -} -variable "transit_encryption_enabled" { - type = bool - default = false - description = "Whether to enable encryption in transit." -} -