Skip to content

Commit dfe3549

Browse files
authored
Merge pull request #12 from lgallard/feature/secondary-resources
Feature/secondary resources
2 parents bb98d76 + af95716 commit dfe3549

File tree

5 files changed

+87
-41
lines changed

5 files changed

+87
-41
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.5.0 (March 18, 2021)
2+
3+
FEATURES:
4+
5+
* Add secondary sources (based on @brettminnie's)
6+
* Update example with secondary sources
7+
18
## 0.4.0 (March 17, 2021)
29

310
FEATURES:

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ module "myapp-project" {
136136
137137
}
138138
```
139-
140139
## Requirements
141140

142141
No requirements.
@@ -180,13 +179,12 @@ No Modules.
180179
| build\_timeout | How long in minutes, from 5 to 480 (8 hours), for AWS CodeBuild to wait until timing out any related build that does not get marked as completed.The default is 60 minutes. | `number` | `60` | no |
181180
| cache | Information about the cache storage for the project. | `any` | `{}` | no |
182181
| cache\_location | The location where the AWS CodeBuild project stores cached resources. For type S3 the value must be a valid S3 bucket name/prefix. (Required when cache `type` is `S3`) | `string` | `null` | no |
183-
| cache\_modes | Specifies settings that AWS CodeBuild uses to store and reuse build dependencies. Valid values: `LOCAL_SOURCE_CACHE`, `LOCAL_DOCKER_LAYER_CACHE`, and `LOCAL_CUSTOM_CACHE`. (Required when cache type is `LOCAL`) | `list` | `[]` | no |
182+
| cache\_modes | Specifies settings that AWS CodeBuild uses to store and reuse build dependencies. Valid values: `LOCAL_SOURCE_CACHE`, `LOCAL_DOCKER_LAYER_CACHE`, and `LOCAL_CUSTOM_CACHE`. (Required when cache type is `LOCAL`) | `list(any)` | `[]` | no |
184183
| cache\_type | The type of storage that will be used for the AWS CodeBuild project cache. Valid values: `NO_CACHE`, `LOCAL`, and `S3`. | `string` | `"NO_CACHE"` | no |
185184
| cloudwatch\_logs | Configuration for the builds to store log data to CloudWatch. | `any` | `{}` | no |
186185
| cloudwatch\_logs\_group\_name | The group name of the logs in CloudWatch Logs. | `string` | `null` | no |
187186
| cloudwatch\_logs\_status | Current status of logs in CloudWatch Logs for a build project. Valid values: `ENABLED`, `DISABLED.` | `string` | `"ENABLED"` | no |
188187
| cloudwatch\_logs\_stream\_name | The stream name of the logs in CloudWatch Logs. | `string` | `null` | no |
189-
| codebuild\_secondary\_source | Information about the project's secondary source code. | `any` | `{}` | no |
190188
| codebuild\_secondary\_source\_auth | Information about the authorization settings for AWS CodeBuild to access the source code to be built. | `map` | `{}` | no |
191189
| codebuild\_secondary\_source\_auth\_resource | The resource value that applies to the specified authorization type. | `string` | `null` | no |
192190
| codebuild\_secondary\_source\_auth\_type | The authorization type to use. The only valid value is OAUTH | `string` | `"OAUTH"` | no |
@@ -199,13 +197,14 @@ No Modules.
199197
| codebuild\_secondary\_source\_location | The location of the source code from git or s3. | `string` | `null` | no |
200198
| codebuild\_secondary\_source\_report\_build\_status | Set to true to report the status of a build's start and finish to your source provider. This option is only valid when the type is `BITBUCKET` or `GITHUB`. | `bool` | `false` | no |
201199
| codebuild\_secondary\_source\_type | The type of repository that contains the secondary source code to be built. Valid values for this parameter are: `CODECOMMIT`, `CODEPIPELINE`, `GITHUB`, `GITHUB_ENTERPRISE`, `BITBUCKET`, `S3` or `NO_SOURCE`. | `string` | `"CODEPIPELINE"` | no |
200+
| codebuild\_secondary\_sources | Information about the project's secondary sources code. See the related codebuild source objects for descriptions of each parameter.<br> The parameter `source_identifier` is the name of the directory to clone the secondary source into as a sibling to the primary source code directory.<br> If this variable is omitted, no secondary sources are created.<br><br> eg:<pre>codebuild_secondary_sources = [<br> {<br> type = "GITHUB"<br> location = "https://github.com/myprofile/myproject-1.git"<br> source_identifier = "my_awesome_project1"<br> },<br> {<br> type = "GITHUB"<br> location = "https://github.com/myprofile/myproject-2.git"<br> git_clone_depth = 1<br> source_identifier = "my_awesome_project2"<br> report_build_status = true<br> insecure_ssl = true<br> }<br> ]</pre> | `any` | `[]` | no |
202201
| codebuild\_source | Information about the project's input source code. | `any` | `{}` | no |
203-
| codebuild\_source\_auth | Information about the authorization settings for AWS CodeBuild to access the source code to be built. | `map` | `{}` | no |
202+
| codebuild\_source\_auth | Information about the authorization settings for AWS CodeBuild to access the source code to be built. | `map(any)` | `{}` | no |
204203
| codebuild\_source\_auth\_resource | The resource value that applies to the specified authorization type. | `string` | `null` | no |
205204
| codebuild\_source\_auth\_type | The authorization type to use. The only valid value is OAUTH | `string` | `"OAUTH"` | no |
206205
| codebuild\_source\_buildspec | The build spec declaration to use for this build project's related builds. This must be set when type is iNO\_SOURCE | `string` | `null` | no |
207206
| codebuild\_source\_git\_clone\_depth | Information about the Git submodules configuration for an AWS CodeBuild build project. Git submodules config blocks are documented below. This option is only valid when the type is `CODECOMMIT`. | `number` | `0` | no |
208-
| codebuild\_source\_git\_submodules\_config | Information about the Git submodules configuration for an AWS CodeBuild build project. Git submodules config blocks are documented below. This option is only valid when the type is `CODECOMMIT`. | `map` | `{}` | no |
207+
| codebuild\_source\_git\_submodules\_config | Information about the Git submodules configuration for an AWS CodeBuild build project. Git submodules config blocks are documented below. This option is only valid when the type is `CODECOMMIT`. | `map(any)` | `{}` | no |
209208
| codebuild\_source\_git\_submodules\_config\_fetch\_submodules | If set to true, fetches Git submodules for the AWS CodeBuild build project. | `bool` | `true` | no |
210209
| codebuild\_source\_insecure\_ssl | Ignore SSL warnings when connecting to source control. | `bool` | `false` | no |
211210
| codebuild\_source\_location | The location of the source code from git or s3. | `string` | `null` | no |
@@ -220,9 +219,9 @@ No Modules.
220219
| environment\_image | The Docker image to use for this build project. Valid values include Docker images provided by CodeBuild (e.g `aws/codebuild/standard:2.0`), Docker Hub images (e.g. `hashicorp/terraform:latest`), and full Docker repository URIs such as those for ECR (e.g. `137112412989.dkr.ecr.us-west-2.amazonaws.com/amazonlinux:latest`) | `string` | `"aws/codebuild/standard:2.0"` | no |
221220
| environment\_image\_pull\_credentials\_type | The type of credentials AWS CodeBuild uses to pull images in your build. Available values for this parameter are `CODEBUID` or `SERVICE_ROLE`. When you use a cross-account or private registry image, you must use SERVICE\_ROLE credentials. When you use an AWS CodeBuild curated image, you must use CODEBUILD credentials. | `string` | `"CODEBUILD"` | no |
222221
| environment\_privileged\_mode | If set to true, enables running the Docker daemon inside a Docker container. | `bool` | `false` | no |
223-
| environment\_registry\_credential | Information about credentials for access to a private Docker registry. Registry Credential config blocks are documented below. | `map` | `{}` | no |
222+
| environment\_registry\_credential | Information about credentials for access to a private Docker registry. Registry Credential config blocks are documented below. | `map(any)` | `{}` | no |
224223
| environment\_type | The type of build environment to use for related builds. Available values are: `LINUX_CONTAINER`, `LINUX_GPU_CONTAINER`, `WINDOWS_CONTAINER` or `ARM_CONTAINER`. | `string` | `"LINUX_CONTAINER"` | no |
225-
| environment\_variables | A list of sets of environment variables to make available to builds for this build project. | `list` | `[]` | no |
224+
| environment\_variables | A list of sets of environment variables to make available to builds for this build project. | `list(any)` | `[]` | no |
226225
| name | The projects name. | `string` | n/a | yes |
227226
| queued\_timeout | How long in minutes, from 5 to 480 (8 hours), a build is allowed to be queued before it times out.The default is 8 hours. | `number` | `480` | no |
228227
| s3\_logs | Configuration for the builds to store log data to S3. | `any` | `{}` | no |

examples/codebuild_using_objects/main.tf

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CodeBuild
22
module "myapp-project" {
33

4-
source = "git::https://github.com/lgallard/terraform-aws-codebuild.git"
4+
source = "lgallard/codebuild/aws"
55

66
name = "my-app"
77
description = "Codebuild for deploying myapp"
@@ -18,6 +18,23 @@ module "myapp-project" {
1818
}
1919
}
2020

21+
# Secondary Sources
22+
codebuild_secondary_sources = [
23+
{
24+
type = "GITHUB"
25+
location = "https://github.com/myprofile/myproject-1.git"
26+
source_identifier = "my_awesome_project1"
27+
},
28+
{
29+
type = "GITHUB"
30+
location = "https://github.com/myprofile/myproject-2.git"
31+
git_clone_depth = 1
32+
source_identifier = "my_awesome_project2"
33+
report_build_status = true
34+
insecure_ssl = true
35+
}
36+
]
37+
2138
# Environment
2239
environment = {
2340
compute_type = "BUILD_GENERAL1_SMALL"
@@ -29,11 +46,11 @@ module "myapp-project" {
2946
variables = [
3047
{
3148
name = "REGISTRY_URL"
32-
value = "012345678910.dkr.ecr.us-east-1.amazonaws.com/my-ecr"
49+
value = "012345678910.dkr.ecr.us-west-1.amazonaws.com/my-ecr"
3350
},
3451
{
3552
name = "AWS_DEFAULT_REGION"
36-
value = "us-east-1"
53+
value = "us-west-1"
3754
},
3855
]
3956
}
@@ -68,7 +85,7 @@ module "myapp-project" {
6885

6986
# S3
7087
resource "aws_s3_bucket" "myapp-project" {
71-
bucket = "myapp-project-bucket"
72-
acl = "private"
88+
bucket_prefix = "myapp-project-bucket-"
89+
acl = "private"
7390
}
7491

main.tf

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ resource "aws_codebuild_project" "cb_project" {
6060
content {
6161
name = environment_variable.value.name
6262
value = environment_variable.value.value
63-
type = lookup(environment_variable.value, "type", null) == null ? "PLAINTEXT" : environment_variable.value.type
63+
type = lookup(environment_variable.value, "type", null) == null ? "PLAINTEXT" : environment_variable.value.type
6464
}
6565
}
6666
}
@@ -127,15 +127,15 @@ resource "aws_codebuild_project" "cb_project" {
127127

128128
# Secondary Sources
129129
dynamic "secondary_sources" {
130-
for_each = local.secondary_source
130+
for_each = local.secondary_sources
131131
content {
132-
type = lookup(secondary_sources.value, "type")
133-
buildspec = lookup(secondary_sources.value, "buildspec")
134-
git_clone_depth = lookup(secondary_sources.value, "git_clone_depth")
135-
insecure_ssl = lookup(secondary_sources.value, "insecure_ssl")
136-
location = lookup(secondary_sources.value, "location")
137-
report_build_status = lookup(secondary_sources.value, "report_build_status")
138-
source_identifier = lookup(secondary_sources.value, "source_identifier")
132+
type = lookup(secondary_sources.value, "type", "CODEBUILD")
133+
buildspec = lookup(secondary_sources.value, "buildspec", null)
134+
git_clone_depth = lookup(secondary_sources.value, "git_clone_depth", 0)
135+
insecure_ssl = lookup(secondary_sources.value, "insecure_ssl", var.codebuild_source_insecure_ssl)
136+
location = lookup(secondary_sources.value, "location", null)
137+
report_build_status = lookup(secondary_sources.value, "report_build_status", var.codebuild_source_report_build_status)
138+
source_identifier = lookup(secondary_sources.value, "source_identifier", null)
139139

140140
# Auth
141141
dynamic "auth" {
@@ -253,22 +253,22 @@ locals {
253253
}
254254
]
255255

256-
# Secondary Sources
257-
# If no block is provided build one using defaults
258-
secondary_source = [
256+
secondary_sources = [
257+
for source in var.codebuild_secondary_sources :
259258
{
260-
type = lookup(var.codebuild_secondary_source, "type", null) == null ? var.codebuild_secondary_source_type : lookup(var.codebuild_secondary_source, "type")
261-
buildspec = lookup(var.codebuild_secondary_source, "buildspec", null) == null ? var.codebuild_secondary_source_buildspec : lookup(var.codebuild_secondary_source, "buildspec")
262-
git_clone_depth = lookup(var.codebuild_secondary_source, "git_clone_depth", null) == null ? var.codebuild_secondary_source_git_clone_depth : lookup(var.codebuild_secondary_source, "git_clone_depth")
263-
insecure_ssl = lookup(var.codebuild_secondary_source, "insecure_ssl", null) == null ? var.codebuild_secondary_source_insecure_ssl : lookup(var.codebuild_secondary_source, "insecure_ssl")
264-
location = lookup(var.codebuild_secondary_source, "location", null) == null ? var.codebuild_secondary_source_location : lookup(var.codebuild_secondary_source, "location")
265-
report_build_status = lookup(var.codebuild_secondary_source, "report_build_status", null) == null ? var.codebuild_secondary_source_report_build_status : lookup(var.codebuild_secondary_source, "report_build_status")
266-
source_identifier = lookup(var.codebuild_secondary_source, "source_identifier", null) == null ? var.codebuild_secondary_source_identifier : lookup(var.codebuild_secondary_source, "source_identifier")
267-
auth = lookup(var.codebuild_secondary_source, "auth", null) == null ? var.codebuild_secondary_source_auth : lookup(var.codebuild_secondary_source, "auth")
268-
git_submodules_config = lookup(var.codebuild_secondary_source, "git_submodules_config", null) == null ? var.codebuild_secondary_source_git_submodules_config : lookup(var.codebuild_secondary_source, "git_submodules_config")
259+
type = lookup(source, "type", null) == null ? var.codebuild_secondary_source_type : lookup(source, "type")
260+
buildspec = lookup(source, "buildspec", null) == null ? var.codebuild_secondary_source_buildspec : lookup(source, "buildspec")
261+
git_clone_depth = lookup(source, "git_clone_depth", null) == null ? var.codebuild_secondary_source_git_clone_depth : lookup(source, "git_clone_depth")
262+
insecure_ssl = lookup(source, "insecure_ssl", null) == null ? var.codebuild_secondary_source_insecure_ssl : lookup(source, "insecure_ssl")
263+
location = lookup(source, "location", null) == null ? var.codebuild_secondary_source_location : lookup(source, "location")
264+
report_build_status = lookup(source, "report_build_status", null) == null ? var.codebuild_secondary_source_report_build_status : lookup(source, "report_build_status")
265+
source_identifier = lookup(source, "source_identifier", null) == null ? var.codebuild_secondary_source_identifier : lookup(source, "source_identifier")
266+
auth = lookup(source, "auth", null) == null ? var.codebuild_secondary_source_auth : lookup(source, "auth")
267+
git_submodules_config = lookup(source, "git_submodules_config", null) == null ? var.codebuild_secondary_source_git_submodules_config : lookup(source, "git_submodules_config")
269268
}
270269
]
271270

271+
272272
# VPC Config
273273
# If no VPC Config block is provided, build one using the default values
274274
vpc_config = {

variables.tf

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ variable "cache_location" {
122122

123123
variable "cache_modes" {
124124
description = "Specifies settings that AWS CodeBuild uses to store and reuse build dependencies. Valid values: `LOCAL_SOURCE_CACHE`, `LOCAL_DOCKER_LAYER_CACHE`, and `LOCAL_CUSTOM_CACHE`. (Required when cache type is `LOCAL`)"
125-
type = list
125+
type = list(any)
126126
default = []
127127
}
128128

@@ -159,7 +159,7 @@ variable "environment_image_pull_credentials_type" {
159159

160160
variable "environment_variables" {
161161
description = "A list of sets of environment variables to make available to builds for this build project."
162-
type = list
162+
type = list(any)
163163
default = []
164164
}
165165

@@ -177,7 +177,7 @@ variable "environment_certificate" {
177177

178178
variable "environment_registry_credential" {
179179
description = "Information about credentials for access to a private Docker registry. Registry Credential config blocks are documented below."
180-
type = map
180+
type = map(any)
181181
default = {}
182182
}
183183

@@ -275,7 +275,7 @@ variable "codebuild_source_report_build_status" {
275275

276276
variable "codebuild_source_auth" {
277277
description = "Information about the authorization settings for AWS CodeBuild to access the source code to be built."
278-
type = map
278+
type = map(any)
279279
default = {}
280280
}
281281

@@ -293,7 +293,7 @@ variable "codebuild_source_auth_resource" {
293293

294294
variable "codebuild_source_git_submodules_config" {
295295
description = "Information about the Git submodules configuration for an AWS CodeBuild build project. Git submodules config blocks are documented below. This option is only valid when the type is `CODECOMMIT`."
296-
type = map
296+
type = map(any)
297297
default = {}
298298
}
299299

@@ -304,10 +304,33 @@ variable "codebuild_source_git_submodules_config_fetch_submodules" {
304304
}
305305

306306
# Secondary Source
307-
variable "codebuild_secondary_source" {
308-
description = "Information about the project's secondary source code."
307+
variable "codebuild_secondary_sources" {
308+
description = <<-EOF
309+
Information about the project's secondary sources code. See the related codebuild source objects for descriptions of each parameter.
310+
The parameter `source_identifier` is the name of the directory to clone the secondary source into as a sibling to the primary source code directory.
311+
If this variable is omitted, no secondary sources are created.
312+
313+
eg:
314+
```
315+
codebuild_secondary_sources = [
316+
{
317+
type = "GITHUB"
318+
location = "https://github.com/myprofile/myproject-1.git"
319+
source_identifier = "my_awesome_project1"
320+
},
321+
{
322+
type = "GITHUB"
323+
location = "https://github.com/myprofile/myproject-2.git"
324+
git_clone_depth = 1
325+
source_identifier = "my_awesome_project2"
326+
report_build_status = true
327+
insecure_ssl = true
328+
}
329+
]
330+
```
331+
EOF
309332
type = any
310-
default = {}
333+
default = []
311334
}
312335

313336
variable "codebuild_secondary_source_type" {

0 commit comments

Comments
 (0)