-
Notifications
You must be signed in to change notification settings - Fork 20
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
Get snapshots information from json file #341
Changes from 1 commit
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 | ||||
---|---|---|---|---|---|---|
|
@@ -85,6 +85,9 @@ max_cluster_capacity = 5 | |||||
# List of addtional namespaces to be created in the cluster | ||||||
#additional_namespaces = ["extra_namespace"] | ||||||
|
||||||
# Path to a JSON file with EBS and RDS snapshot IDs | ||||||
#snapshots_json_file_path = "test/dcapt-snapshots.json" | ||||||
|
||||||
################################################################################ | ||||||
# Osquery settings. Atlassian only! | ||||||
################################################################################ | ||||||
|
@@ -215,6 +218,9 @@ jira_db_iops = 1000 | |||||
# Set `null` if the snapshot does not have a default db name. | ||||||
jira_db_name = "jira" | ||||||
|
||||||
# Dataset size. Used only when snapshots_json_file_path is defined. Defaults to large | ||||||
# jira_dataset_size = "small" | ||||||
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.
Suggested change
When we default to something, we should keep the value here. |
||||||
|
||||||
# Database restore configuration | ||||||
# If you want to restore the database from a snapshot, uncomment the following line and provide the snapshot identifier. | ||||||
# This will restore the database from the snapshot and will not create a new database. | ||||||
|
@@ -310,6 +316,9 @@ confluence_db_iops = 1000 | |||||
# Set `null` if the snapshot does not have a default db name. | ||||||
confluence_db_name = "confluence" | ||||||
|
||||||
# Dataset size. Used only when snapshots_json_file_path is defined. Defaults to large | ||||||
# confluence_dataset_size = "small" | ||||||
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.
Suggested change
|
||||||
|
||||||
# Database restore configuration | ||||||
# If you want to restore the database from a snapshot, uncomment the following lines and provide the snapshot identifier. | ||||||
# This will restore the database from the snapshot and will not create a new database. | ||||||
|
@@ -420,6 +429,9 @@ bitbucket_db_name = "bitbucket" | |||||
#bitbucket_elasticsearch_storage = "<REQUESTS_STORAGE>" | ||||||
#bitbucket_elasticsearch_replicas = "<NUMBER_OF_NODES>" | ||||||
|
||||||
# Dataset size. Used only when snapshots_json_file_path is defined. Defaults to large | ||||||
# bitbucket_dataset_size = "small" | ||||||
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.
Suggested change
|
||||||
|
||||||
# Dataset Restore | ||||||
|
||||||
# Database restore configuration | ||||||
|
@@ -590,6 +602,9 @@ crowd_db_name = "crowd" | |||||
# if you encounter such an issue. This will apply to Crowd pods. | ||||||
#crowd_termination_grace_period = 0 | ||||||
|
||||||
# Dataset size. Used only when snapshots_json_file_path is defined. Defaults to large | ||||||
# crowd_dataset_size = "small" | ||||||
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.
Suggested change
|
||||||
|
||||||
# Dataset Restore | ||||||
|
||||||
# Database restore configuration | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,10 @@ pre_flight_checks() { | |
PRODUCT_VERSION=$(get_variable ${PRODUCT_VERSION_VAR} "${CONFIG_ABS_PATH}") | ||
MAJOR_MINOR_VERSION=$(echo "$PRODUCT_VERSION" | cut -d '.' -f1-2) | ||
EBS_SNAPSHOT_ID=$(get_variable ${SHARED_HOME_SNAPSHOT_VAR} "${CONFIG_ABS_PATH}") | ||
SNAPSHOTS_JSON_FILE_PATH=$(get_variable 'snapshots_json_file_path' "${CONFIG_ABS_PATH}") | ||
if [ "${SNAPSHOTS_JSON_FILE_PATH}" ]; then | ||
EBS_SNAPSHOT_ID=$(cat ${SNAPSHOTS_JSON_FILE_PATH} | jq ".${PRODUCT}.versions[] | select(.version == \"${PRODUCT_VERSION}\") | .data[] | select(.size == \"large\" and .type == \"ebs\") | .snapshots[] | .[\"${REGION}\"]" | sed 's/"//g') | ||
fi | ||
if [ ! -z ${EBS_SNAPSHOT_ID} ]; then | ||
log "Checking EBS snapshot ${EBS_SNAPSHOT_ID} compatibility with ${PRODUCT} version ${PRODUCT_VERSION}" | ||
EBS_SNAPSHOT_DESCRIPTION=$(aws ec2 describe-snapshots --snapshot-ids=${EBS_SNAPSHOT_ID} --region ${REGION} --query 'Snapshots[0].Description') | ||
|
@@ -147,6 +151,9 @@ pre_flight_checks() { | |
fi | ||
fi | ||
RDS_SNAPSHOT_ID=$(get_variable ${RDS_SNAPSHOT_VAR} "${CONFIG_ABS_PATH}") | ||
if [ "${SNAPSHOTS_JSON_FILE_PATH}" ]; then | ||
RDS_SNAPSHOT_ID=$(cat ${SNAPSHOTS_JSON_FILE_PATH} | jq ".${PRODUCT}.versions[] | select(.version == \"${PRODUCT_VERSION}\") | .data[] | select(.size == \"large\" and .type == \"rds\") | .snapshots[] | .[\"${REGION}\"]" | sed 's/"//g') | ||
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. Doesn't this always read the 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. Oh, that's the debug version. Let me fix it. |
||
fi | ||
if [ ! -z ${RDS_SNAPSHOT_ID} ]; then | ||
log "Checking RDS snapshot ${RDS_SNAPSHOT_ID} compatibility with ${PRODUCT} version ${PRODUCT_VERSION}" | ||
RDS_SNAPSHOT_VERSION=$(echo "${RDS_SNAPSHOT_ID}" | sed 's/.*dcapt-\(.*\)/\1/' | sed 's/-/./g' | cut -d '.' -f 2-) | ||
|
@@ -181,6 +188,15 @@ verify_configuration_file() { | |
HAS_VALIDATION_ERR=1 | ||
fi | ||
|
||
SNAPSHOTS_JSON_FILE_PATH=$(get_variable 'snapshots_json_file_path' "${CONFIG_ABS_PATH}") | ||
if [ "${SNAPSHOTS_JSON_FILE_PATH}" ]; then | ||
if [ ! -e "${SNAPSHOTS_JSON_FILE_PATH}" ]; then | ||
log "Snapshots json file not found at ${SNAPSHOTS_JSON_FILE_PATH}" | ||
log "Please make sure 'snapshots_json_file_path' in ${CONFIG_ABS_PATH} points to an existing valid json file" | ||
HAS_VALIDATION_ERR=1 | ||
fi | ||
fi | ||
|
||
if [ -n "${INVALID_CONTENT}" ]; then | ||
log "Configuration file '${CONFIG_ABS_PATH##*/}' is not valid." "ERROR" | ||
log "Terraform uses this file to generate customised infrastructure for '${ENVIRONMENT_NAME}' on your AWS account." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,100 @@ locals { | |
local_bamboo_chart_path = var.local_helm_charts_path != "" && var.bamboo_install_local_chart ? "${var.local_helm_charts_path}/bamboo" : "" | ||
local_agent_chart_path = var.local_helm_charts_path != "" && var.bamboo_install_local_chart ? "${var.local_helm_charts_path}/bamboo-agent" : "" | ||
local_crowd_chart_path = var.local_helm_charts_path != "" && var.crowd_install_local_chart ? "${var.local_helm_charts_path}/crowd" : "" | ||
|
||
# snapshots_json = var.snapshots_json_file_path != "" ? jsondecode(file(var.snapshots_json_file_path)) : jsondecode("{\"jira\": {\"versions\":[]},\"confluence\": {\"versions\":[]},\"crowd\": {\"versions\":[]},\"bitbucket\": {\"versions\":[]}}") | ||
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. Do we need this? |
||
snapshots_json = var.snapshots_json_file_path != "" ? jsondecode(file(var.snapshots_json_file_path)) : null | ||
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. Can we put a sentence or two describing the filtering process and how the snapshot values are determined? I had to read it a couple of times to see how this is used, and I am sure I will forget it before I will see this code again :) 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. If |
||
|
||
filtered_bitbucket_snapshots = local.snapshots_json != null ? flatten([ | ||
for version in local.snapshots_json.bitbucket.versions : | ||
[for snapshot in version.data : | ||
merge({ version = version.version }, snapshot) | ||
] | ||
]) : [] | ||
|
||
bitbucket_rds_snapshot = local.snapshots_json != null ? [ | ||
for snapshot in local.filtered_bitbucket_snapshots : | ||
snapshot.type == "rds" && snapshot.size == var.bitbucket_dataset_size && snapshot.version == var.bitbucket_version_tag ? snapshot.snapshots[0][var.region] : "" | ||
] : [] | ||
|
||
bitbucket_ebs_snapshot = local.snapshots_json != null ? [ | ||
for snapshot in local.filtered_bitbucket_snapshots : | ||
snapshot.type == "ebs" && snapshot.size == var.bitbucket_dataset_size && snapshot.version == var.bitbucket_version_tag ? snapshot.snapshots[0][var.region] : "" | ||
] : [] | ||
|
||
filtered_confluence_snapshots = local.snapshots_json != null ? flatten([ | ||
for version in local.snapshots_json.confluence.versions : | ||
[for snapshot in version.data : | ||
merge({ version = version.version }, snapshot) | ||
] | ||
]) : [] | ||
|
||
confluence_rds_snapshot = local.snapshots_json != null ? [ | ||
for snapshot in local.filtered_confluence_snapshots : | ||
snapshot.type == "rds" && snapshot.size == var.confluence_dataset_size && snapshot.version == var.confluence_version_tag ? snapshot.snapshots[0][var.region] : "" | ||
] : [] | ||
|
||
confluence_ebs_snapshot = local.snapshots_json != null ? [ | ||
for snapshot in local.filtered_confluence_snapshots : | ||
snapshot.type == "ebs" && snapshot.size == var.confluence_dataset_size && snapshot.version == var.confluence_version_tag ? snapshot.snapshots[0][var.region] : "" | ||
] : [] | ||
|
||
confluence_build_numbers = local.snapshots_json != null ? flatten([ | ||
for version in local.snapshots_json.confluence.versions : | ||
version.version == var.confluence_version_tag ? version.build_number : "" | ||
]) : [] | ||
|
||
filtered_crowd_snapshots = local.snapshots_json != null ? flatten([ | ||
for version in local.snapshots_json.crowd.versions : | ||
[for snapshot in version.data : | ||
merge({ version = version.version }, snapshot) | ||
] | ||
]) : [] | ||
|
||
crowd_rds_snapshot = local.snapshots_json != null ? [ | ||
for snapshot in local.filtered_crowd_snapshots : | ||
snapshot.type == "rds" && snapshot.size == var.crowd_dataset_size && snapshot.version == var.crowd_version_tag ? snapshot.snapshots[0][var.region] : "" | ||
] : [] | ||
|
||
crowd_ebs_snapshot = local.snapshots_json != null ? [ | ||
for snapshot in local.filtered_crowd_snapshots : | ||
snapshot.type == "ebs" && snapshot.size == var.crowd_dataset_size && snapshot.version == var.crowd_version_tag ? snapshot.snapshots[0][var.region] : "" | ||
] : [] | ||
|
||
crowd_build_numbers = local.snapshots_json != null ? flatten([ | ||
for version in local.snapshots_json.crowd.versions : | ||
version.version == var.crowd_version_tag ? version.build_number : "" | ||
]) : [] | ||
|
||
filtered_jira_snapshots = local.snapshots_json != null ? flatten([ | ||
for version in local.snapshots_json.jira.versions : | ||
[for snapshot in version.data : | ||
merge({ version = version.version }, snapshot) | ||
] | ||
]) : [] | ||
|
||
jira_rds_snapshot = local.snapshots_json != null ? [ | ||
for snapshot in local.filtered_jira_snapshots : | ||
snapshot.type == "rds" && snapshot.size == var.jira_dataset_size && snapshot.version == var.jira_version_tag ? snapshot.snapshots[0][var.region] : "" | ||
] : [] | ||
|
||
jira_ebs_snapshot = local.snapshots_json != null ? [ | ||
for snapshot in local.filtered_jira_snapshots : | ||
snapshot.type == "ebs" && snapshot.size == var.jira_dataset_size && snapshot.version == var.jira_version_tag ? snapshot.snapshots[0][var.region] : "" | ||
] : [] | ||
|
||
jira_rds_snapshot_id = length(compact(local.jira_rds_snapshot)) > 0 ? compact(local.jira_rds_snapshot)[0] : var.jira_db_snapshot_id != null ? var.jira_db_snapshot_id : null | ||
jira_ebs_snapshot_id = length(compact(local.jira_ebs_snapshot)) > 0 ? compact(local.jira_ebs_snapshot)[0] : var.jira_shared_home_snapshot_id != null ? var.jira_shared_home_snapshot_id : null | ||
|
||
confluence_rds_snapshot_id = length(compact(local.confluence_rds_snapshot)) > 0 ? compact(local.confluence_rds_snapshot)[0] : var.confluence_db_snapshot_id != null ? var.confluence_db_snapshot_id : null | ||
confluence_ebs_snapshot_id = length(compact(local.confluence_ebs_snapshot)) > 0 ? compact(local.confluence_ebs_snapshot)[0] : var.confluence_shared_home_snapshot_id != null ? var.confluence_shared_home_snapshot_id : null | ||
confluence_db_snapshot_build_number = length(compact(local.confluence_build_numbers)) > 0 ? compact(local.confluence_build_numbers)[0] : var.confluence_db_snapshot_build_number != null ? var.confluence_db_snapshot_build_number : null | ||
|
||
crowd_rds_snapshot_id = length(compact(local.crowd_rds_snapshot)) > 0 ? compact(local.crowd_rds_snapshot)[0] : var.crowd_db_snapshot_id != null ? var.crowd_db_snapshot_id : null | ||
crowd_ebs_snapshot_id = length(compact(local.crowd_ebs_snapshot)) > 0 ? compact(local.crowd_ebs_snapshot)[0] : var.crowd_shared_home_snapshot_id != null ? var.crowd_shared_home_snapshot_id : null | ||
crowd_db_snapshot_build_number = length(compact(local.crowd_build_numbers)) > 0 ? compact(local.crowd_build_numbers)[0] : var.crowd_db_snapshot_build_number != null ? var.crowd_db_snapshot_build_number : null | ||
|
||
bitbucket_rds_snapshot_id = length(compact(local.bitbucket_rds_snapshot)) > 0 ? compact(local.bitbucket_rds_snapshot)[0] : var.bitbucket_db_snapshot_id != null ? var.bitbucket_db_snapshot_id : null | ||
bitbucket_ebs_snapshot_id = length(compact(local.bitbucket_ebs_snapshot)) > 0 ? compact(local.bitbucket_ebs_snapshot)[0] : var.bitbucket_shared_home_snapshot_id != null ? var.bitbucket_shared_home_snapshot_id : null | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,3 +111,43 @@ output "confluence_s3_bucket" { | |
description = "Confluence S3 bucket name" | ||
value = var.confluence_s3_attachments_storage ? "${local.cluster_name}-confluence-storage" : null | ||
} | ||
|
||
output "jira_rds_snapshot" { | ||
value = local.jira_rds_snapshot_id | ||
} | ||
|
||
output "jira_ebs_snapshot" { | ||
value = local.jira_ebs_snapshot_id | ||
} | ||
|
||
output "confluence_rds_snapshot" { | ||
value = local.confluence_rds_snapshot_id | ||
} | ||
|
||
output "confluence_ebs_snapshot" { | ||
value = local.confluence_ebs_snapshot_id | ||
} | ||
|
||
output "confluence_db_snapshot_build_number" { | ||
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. Only Confluence and Crowd require build number? 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. |
||
value = local.confluence_db_snapshot_build_number | ||
} | ||
|
||
output "bitbucket_rds_snapshot" { | ||
value = local.bitbucket_rds_snapshot_id | ||
} | ||
|
||
output "bitbucket_ebs_snapshot" { | ||
value = local.bitbucket_ebs_snapshot_id | ||
} | ||
|
||
output "crowd_rds_snapshot" { | ||
value = local.crowd_rds_snapshot_id | ||
} | ||
|
||
output "crowd_ebs_snapshot" { | ||
value = local.crowd_ebs_snapshot_id | ||
} | ||
|
||
output "crowd_db_snapshot_build_number" { | ||
value = local.crowd_db_snapshot_build_number | ||
} |
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.
/nit we should be consistent with the space after the
#
comment symbol. I think leaving a space in is better for readability and removing the space is more convenient as I can just uncomment the line and don't delete the leading space.I am leaning towards leaving a space