Skip to content

Commit 076e5a9

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#46)
* Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Use `splat+join`
1 parent 7da8df5 commit 076e5a9

22 files changed

+656
-232
lines changed

.travis.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2017-2018 Cloud Posse, LLC
189+
Copyright 2017-2019 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[![Cloud Posse][logo]](https://cpco.io/homepage)
55

6-
# terraform-aws-codebuild [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-codebuild.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-codebuild) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-codebuild.svg)](https://github.com/cloudposse/terraform-aws-codebuild/releases) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
6+
# terraform-aws-codebuild [![Codefresh Build Status](https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-codebuild?type=cf-1)](https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d198705e38a0429d812f7e4) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-codebuild.svg)](https://github.com/cloudposse/terraform-aws-codebuild/releases) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
77

88

99
Terraform module to create AWS CodeBuild project for AWS CodePipeline.
@@ -52,21 +52,21 @@ Include this module in your existing terraform code:
5252
```hcl
5353
module "build" {
5454
source = "git::https://github.com/cloudposse/terraform-aws-codebuild.git?ref=master"
55-
namespace = "general"
56-
name = "ci"
55+
namespace = "eg"
5756
stage = "staging"
57+
name = "app"
5858
5959
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
60-
build_image = "aws/codebuild/docker:1.12.1"
60+
build_image = "aws/codebuild/standard:2.0"
6161
build_compute_type = "BUILD_GENERAL1_SMALL"
62-
build_timeout = "60"
62+
build_timeout = 60
6363
6464
# These attributes are optional, used as ENV variables when building Docker images and pushing them to ECR
6565
# For more info:
6666
# http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html
6767
# https://www.terraform.io/docs/providers/aws/r/codebuild_project.html
6868
69-
privileged_mode = "true"
69+
privileged_mode = true
7070
aws_region = "us-east-1"
7171
aws_account_id = "xxxxxxxxxx"
7272
image_repo_name = "ecr-repo-name"
@@ -89,19 +89,6 @@ module "build" {
8989
}
9090
```
9191

92-
### To hide warnings about unset versions in providers
93-
94-
Add this to your .tf files
95-
```hcl
96-
provider "random" {
97-
version = "~> 1.0"
98-
}
99-
100-
provider "null" {
101-
version = "~> 1.0"
102-
}
103-
```
104-
10592

10693

10794

@@ -121,32 +108,32 @@ Available targets:
121108

122109
| Name | Description | Type | Default | Required |
123110
|------|-------------|:----:|:-----:|:-----:|
124-
| artifact_type | The build output artifact's type. Valid values for this parameter are: CODEPIPELINE, NO_ARTIFACTS or S3. | string | `CODEPIPELINE` | no |
125-
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
111+
| artifact_type | The build output artifact's type. Valid values for this parameter are: CODEPIPELINE, NO_ARTIFACTS or S3 | string | `CODEPIPELINE` | no |
112+
| attributes | Additional attributes (e.g. `policy` or `role`) | list(string) | `<list>` | no |
126113
| aws_account_id | (Optional) AWS Account ID. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html | string | `` | no |
127114
| aws_region | (Optional) AWS Region, e.g. us-east-1. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html | string | `` | no |
128-
| badge_enabled | Generates a publicly-accessible URL for the projects build badge. Available as badge_url attribute when enabled. | string | `false` | no |
115+
| badge_enabled | Generates a publicly-accessible URL for the projects build badge. Available as badge_url attribute when enabled | bool | `false` | no |
129116
| build_compute_type | Instance type of the build instance | string | `BUILD_GENERAL1_SMALL` | no |
130-
| build_image | Docker image for build environment, e.g. 'aws/codebuild/docker:1.12.1' or 'aws/codebuild/eb-nodejs-6.10.0-amazonlinux-64:4.0.0'. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref.html | string | `aws/codebuild/docker:1.12.1` | no |
131-
| 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. | string | `60` | no |
117+
| build_image | Docker image for build environment, e.g. 'aws/codebuild/standard:2.0' or 'aws/codebuild/eb-nodejs-6.10.0-amazonlinux-64:4.0.0'. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref.html | string | `aws/codebuild/standard:2.0` | no |
118+
| 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 | string | `60` | no |
132119
| buildspec | Optional buildspec declaration to use for building the project | string | `` | no |
133-
| cache_bucket_suffix_enabled | The cache bucket generates a random 13 character string to generate a unique bucket name. If set to false it uses terraform-null-label's id value | string | `true` | no |
134-
| cache_enabled | If cache_enabled is true, create an S3 bucket for storing codebuild cache inside | string | `true` | no |
120+
| cache_bucket_suffix_enabled | The cache bucket generates a random 13 character string to generate a unique bucket name. If set to false it uses terraform-null-label's id value | bool | `true` | no |
121+
| cache_enabled | If cache_enabled is true, create an S3 bucket for storing codebuild cache inside | bool | `true` | no |
135122
| cache_expiration_days | How many days should the build cache be kept | string | `7` | no |
136123
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
137-
| enabled | A boolean to enable/disable resource creation | string | `true` | no |
138-
| environment_variables | A list of maps, that contain both the key 'name' and the key 'value' to be used as additional environment variables for the build. | list | `<list>` | no |
124+
| enabled | A boolean to enable/disable resource creation | bool | `true` | no |
125+
| environment_variables | A list of maps, that contain both the key 'name' and the key 'value' to be used as additional environment variables for the build | object | `<list>` | no |
139126
| github_token | (Optional) GitHub auth token environment variable (`GITHUB_TOKEN`) | string | `` | no |
140127
| image_repo_name | (Optional) ECR repository name to store the Docker image built by this module. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html | string | `UNSET` | no |
141128
| image_tag | (Optional) Docker image tag in the ECR repository, e.g. 'latest'. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html | string | `latest` | no |
142-
| name | Solution name, e.g. 'app' or 'jenkins' | string | `codebuild` | no |
143-
| namespace | Namespace, which could be your organization name, e.g. 'cp' or 'cloudposse' | string | `global` | no |
144-
| privileged_mode | (Optional) If set to true, enables running the Docker daemon inside a Docker container on the CodeBuild instance. Used when building Docker images | string | `false` | no |
145-
| 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 source_type is BITBUCKET or GITHUB. | string | `false` | no |
146-
| source_location | The location of the source code from git or s3. | string | `` | no |
147-
| source_type | The type of repository that contains the source code to be built. Valid values for this parameter are: CODECOMMIT, CODEPIPELINE, GITHUB, GITHUB_ENTERPRISE, BITBUCKET or S3. | string | `CODEPIPELINE` | no |
148-
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `default` | no |
149-
| tags | Additional tags (e.g. `map('BusinessUnit', 'XYZ')` | map | `<map>` | no |
129+
| name | Solution name, e.g. 'app' or 'jenkins' | string | - | yes |
130+
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | `` | no |
131+
| privileged_mode | (Optional) If set to true, enables running the Docker daemon inside a Docker container on the CodeBuild instance. Used when building Docker images | bool | `false` | no |
132+
| 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 source_type is BITBUCKET or GITHUB | bool | `false` | no |
133+
| source_location | The location of the source code from git or s3 | string | `` | no |
134+
| source_type | The type of repository that contains the source code to be built. Valid values for this parameter are: CODECOMMIT, CODEPIPELINE, GITHUB, GITHUB_ENTERPRISE, BITBUCKET or S3 | string | `CODEPIPELINE` | no |
135+
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
136+
| tags | Additional tags (e.g. `map('BusinessUnit', 'XYZ')` | map(string) | `<map>` | no |
150137

151138
## Outputs
152139

README.yaml

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ github_repo: cloudposse/terraform-aws-codebuild
3333

3434
# Badges to display
3535
badges:
36-
- name: "Build Status"
37-
image: "https://travis-ci.org/cloudposse/terraform-aws-codebuild.svg?branch=master"
38-
url: "https://travis-ci.org/cloudposse/terraform-aws-codebuild"
36+
- name: "Codefresh Build Status"
37+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-codebuild?type=cf-1"
38+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d198705e38a0429d812f7e4"
3939
- name: "Latest Release"
4040
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-codebuild.svg"
4141
url: "https://github.com/cloudposse/terraform-aws-codebuild/releases"
@@ -59,21 +59,21 @@ usage: |-
5959
```hcl
6060
module "build" {
6161
source = "git::https://github.com/cloudposse/terraform-aws-codebuild.git?ref=master"
62-
namespace = "general"
63-
name = "ci"
62+
namespace = "eg"
6463
stage = "staging"
64+
name = "app"
6565
6666
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
67-
build_image = "aws/codebuild/docker:1.12.1"
67+
build_image = "aws/codebuild/standard:2.0"
6868
build_compute_type = "BUILD_GENERAL1_SMALL"
69-
build_timeout = "60"
69+
build_timeout = 60
7070
7171
# These attributes are optional, used as ENV variables when building Docker images and pushing them to ECR
7272
# For more info:
7373
# http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html
7474
# https://www.terraform.io/docs/providers/aws/r/codebuild_project.html
7575
76-
privileged_mode = "true"
76+
privileged_mode = true
7777
aws_region = "us-east-1"
7878
aws_account_id = "xxxxxxxxxx"
7979
image_repo_name = "ecr-repo-name"
@@ -96,19 +96,6 @@ usage: |-
9696
}
9797
```
9898
99-
### To hide warnings about unset versions in providers
100-
101-
Add this to your .tf files
102-
```hcl
103-
provider "random" {
104-
version = "~> 1.0"
105-
}
106-
107-
provider "null" {
108-
version = "~> 1.0"
109-
}
110-
```
111-
11299
# Other files to include in this README from the project folder
113100
include:
114101
- "docs/targets.md"
@@ -125,4 +112,4 @@ contributors:
125112
- name: "Jamie Nelson"
126113
github: "Jamie-BitfFlight"
127114
- name: "Sarkis Varozian"
128-
github: "sarkis"
115+
github: "sarkis"

codefresh/test.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: '1.0'
2+
3+
stages:
4+
- Prepare
5+
- Test
6+
7+
steps:
8+
wait:
9+
title: Wait
10+
stage: Prepare
11+
image: codefresh/cli:latest
12+
commands:
13+
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
14+
retry:
15+
maxAttempts: 10
16+
delay: 20
17+
exponentialFactor: 1.1
18+
19+
main_clone:
20+
title: "Clone repository"
21+
type: git-clone
22+
stage: Prepare
23+
description: "Initialize"
24+
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
25+
git: CF-default
26+
revision: ${{CF_REVISION}}
27+
28+
clean_init:
29+
title: Prepare build-harness and test-harness
30+
image: ${{TEST_IMAGE}}
31+
stage: Prepare
32+
commands:
33+
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
34+
- make init
35+
- git -C build-harness checkout master
36+
- make -C test/ clean init TEST_HARNESS_BRANCH=master
37+
- make -C test/src clean init
38+
- find . -type d -name '.terraform' | xargs rm -rf
39+
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;
40+
41+
test:
42+
type: "parallel"
43+
title: "Run tests"
44+
description: "Run all tests in parallel"
45+
stage: Test
46+
steps:
47+
test_readme_lint:
48+
title: "Test README.md updated"
49+
stage: "Test"
50+
image: ${{TEST_IMAGE}}
51+
description: Test "readme/lint"
52+
commands:
53+
- make readme/lint
54+
55+
test_module:
56+
title: Test module with bats
57+
image: ${{TEST_IMAGE}}
58+
stage: Test
59+
commands:
60+
- make -C test/ module
61+
62+
test_examples_complete:
63+
title: Test "examples/complete" with bats
64+
image: ${{TEST_IMAGE}}
65+
stage: Test
66+
commands:
67+
- make -C test/ examples/complete
68+
69+
test_examples_complete_terratest:
70+
title: Test "examples/complete" with terratest
71+
image: ${{TEST_IMAGE}}
72+
stage: Test
73+
commands:
74+
- make -C test/src

0 commit comments

Comments
 (0)