Skip to content
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 tfstate change detection #324

Merged
merged 2 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion concourse/pipelines/template/bosh-pipeline.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ jobs:
OLD_FILE: "<%= terraform_config_path %>/terraform.tfstate"
NEW_FILE: "terraform.tfstate"
PROFILES: ((profiles))
COMMIT_MESSAGE: "Terraform TFState auto update\n\nActive profiles: ${PROFILES}\n[skip ci]"
COMMIT_MESSAGE: "Terraform TFState auto update\n\nActive profiles: ${PROFILES}"
on_failure:
put: failure-alert
params:
Expand Down
5 changes: 2 additions & 3 deletions concourse/tasks/git_update_a_file_from_generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ run:
cp generated-resource/${NEW_FILE} ${FINAL_RELEASE_REPO}/${OLD_FILE}

GIT_COMMIT_MESSAGE=$(eval echo $(echo $COMMIT_MESSAGE))
echo "$GIT_COMMIT_MESSAGE" > ${FINAL_RELEASE_REPO}/.git/message
echo -e "$GIT_COMMIT_MESSAGE" > ${FINAL_RELEASE_REPO}/.git/message
if [ -d concourse-meta ];then
cd concourse-meta
BUILD_TEAM=$(if [ -f build-team-name ];then cat build-team-name;fi)
Expand All @@ -53,8 +53,7 @@ run:
BUILD_NAME=$(if [ -f build-name ];then cat build-name;fi)
BUILD_INFO=$(echo "$BUILD_TEAM/$BUILD_PIPELINE/$BUILD_JOB/$BUILD_NAME - $BUILD_ID")
cd ..
echo "" >> ${FINAL_RELEASE_REPO}/.git/message
echo "Created by $BUILD_INFO" >> ${FINAL_RELEASE_REPO}/.git/message
echo -e "\nCreated by $BUILD_INFO" >> ${FINAL_RELEASE_REPO}/.git/message
fi

cd ${FINAL_RELEASE_REPO}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,15 @@
YAML
YAML.safe_load ci_deployments_yaml
end
let(:expected_tf_ensure_step) do
{"file" => "cf-ops-automation/concourse/tasks/git_update_a_file_from_generated.yml",
"input_mapping" => {"generated-resource"=>"terraform-cf", "reference-resource"=>"secrets-full-writer"},
"on_failure" => {"params"=>{"channel"=>"((slack-channel))", "icon_url"=>"http://cl.ly/image/3e1h0H3H2s0P/concourse-logo.png", "text"=>"Failure during [[$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME]($ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME)].", "username"=>"Concourse"}, "put"=>"failure-alert"},
"on_success" => {"get_params"=>{"submodules"=>"none"}, "params"=>{"rebase"=>true, "repository"=>"updated-terraform-state-secrets"}, "put"=>"secrets-full-writer"},
"output_mapping" => {"updated-git-resource"=>"updated-terraform-state-secrets"},
"params" => {"COMMIT_MESSAGE"=>"Terraform TFState auto update\n\nActive profiles: ${PROFILES}", "NEW_FILE"=>"terraform.tfstate", "OLD_FILE"=>"my-tfstate-location/terraform.tfstate", "PROFILES"=>"((profiles))"},
"task" => "update-terraform-state-file" }
end

it 'generates all resource_types' do
expect(generated_pipeline['resource_types']).to match(expected_resource_types)
Expand All @@ -522,6 +531,17 @@
expect(generated).to match(expected_tf_group)
end

it 'ensures tfstate is commited' do
terraform_apply_task = generated_pipeline['jobs']
.select { |job| job['name'] == "approve-and-enforce-terraform-consistency" }
.flat_map { |job| job['plan'] }
.select { |step| step['task'] == "terraform-apply" }
.first
ensure_definition = terraform_apply_task['ensure']
expect(ensure_definition).to match(expected_tf_ensure_step)

end

it 'generates a valid check-terraform-consistency job' do
expected_tf_job =
[
Expand Down