Skip to content

Commit 194f2e5

Browse files
author
arnol377
committed
Refactor Terraform configuration to update variable name for the deployer key and simplify volume mapping
1 parent 0144028 commit 194f2e5

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

modules/codebuild/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ locals {
3333
# value is a map with keys vars, environment_variables, and buildspec.
3434
# This map is assigned to the build_projects local value.
3535
_build_projects = var.docker_build ? concat([
36-
for project in var.build_projects : project if !contains(["test", "build"], project.name)
36+
for project in var.build_projects : project if ! contains(["test", "build"], project.name)
3737
],
3838
[
3939
{
@@ -131,7 +131,8 @@ resource "aws_codebuild_project" "terraform_codebuild_project" {
131131
merge(
132132
each.value.vars,
133133
{
134-
required_packages = var.required_packages
134+
required_packages = var.required_packages,
135+
bucket = var.assets_bucket_name,
135136
}
136137
)) : templatefile(
137138
lookup(each.value, "buildspec") == null ? lookup(local.buildspecs, each.key) : lookup(each.value, "buildspec"),

modules/codebuild/templates/buildspec_build.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ phases:
3636
- /bin/packer init ${packer_config}
3737
- ln -s $${CODEBUILD_SRC_DIR_SourceAnsibleOutput}/roles
3838
- aws secretsmanager get-secret-value --secret-id ${ssh_private_key_secret_id} --query SecretString --output text > ${ssh_private_key_file}
39-
%{ for package in required_packages ~}
40-
- aws s3 cp ${package.src} ${package.dest}
41-
%{ endfor ~}
42-
- /bin/packer build -var project_name=${project_name} -var ansible_dir=$${CODEBUILD_SRC_DIR_SourceAnsibleOutput} -var ssh_private_key_file=${ssh_private_key_file} ${packer_config}
39+
- echo '${required_packages}' > required_packages.json
40+
- /bin/packer build -var bucket=${bucket} -var project_name=${project_name} -var ansible_dir=$${CODEBUILD_SRC_DIR_SourceAnsibleOutput} -var ssh_private_key_file=${ssh_private_key_file} ${packer_config}
4341
post_build:
4442
commands:
4543
- cd $${CODEBUILD_SRC_DIR}/$${CODE_SRC_DIR}

modules/codebuild/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ variable "role_arn" {
1515
default = ""
1616
}
1717

18+
variable assets_bucket_name {
19+
description = "Name of the S3 bucket used to store the deployment artifacts"
20+
type = string
21+
default = "image-pipeline-assets"
22+
}
23+
1824
variable "s3_bucket_name" {
1925
description = "Name of the S3 bucket used to store the deployment artifacts"
2026
type = string

parameters_and_secrets.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ locals {
7474
nonsensitive_parameters = tomap(
7575
{ for k, v in local.ssm_parameters :
7676
(issensitive(k) ? nonsensitive(k) : k) => (issensitive(v) ? nonsensitive(v) : v)
77-
if !contains(var.nonmanaged_parameters, issensitive(k) ? nonsensitive(k) : k)
77+
if ! contains(var.nonmanaged_parameters, issensitive(k) ? nonsensitive(k) : k)
7878
}
7979
)
8080
}

0 commit comments

Comments
 (0)