Skip to content

Commit a92bdb8

Browse files
authored
Initial module release (#1)
* Cloud Composer Module * Added missing test suite * Fixed inspec.yml * Added main.tf for module * Added permissions for creating network * Added permissions for composer env creation * Addressing PR comments * Fixed README * Fixing dependencies
1 parent 5b0d16f commit a92bdb8

File tree

35 files changed

+575
-244
lines changed

35 files changed

+575
-244
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2020 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# terraform-google-composer
22

3-
This module was generated from [terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template/), which by default generates a module that simply creates a GCS bucket. As the module develops, this README should be updated.
3+
This module makes it easy to create a Cloud Composer Environment. As the module develops, this README should be updated.
44

55
The resources/services/activations/deletions that this module will create/trigger are:
66

7-
- Create a GCS bucket with the provided name
7+
- Create a GCP Composer Environment
88

99
## Usage
1010

@@ -16,7 +16,8 @@ module "composer" {
1616
version = "~> 0.1"
1717
1818
project_id = "<PROJECT ID>"
19-
bucket_name = "gcs-test-bucket"
19+
name = "composer-env-test"
20+
region = "us-central1"
2021
}
2122
```
2223

@@ -28,14 +29,20 @@ Functional examples are included in the
2829

2930
| Name | Description | Type | Default | Required |
3031
|------|-------------|:----:|:-----:|:-----:|
31-
| bucket\_name | The name of the bucket to create | string | n/a | yes |
32-
| project\_id | The project ID to deploy to | string | n/a | yes |
32+
| composer\_env\_name | Name of Cloud Composer Environment | string | n/a | yes |
33+
| composer\_sa | Service Account to be used for running Cloud Composer Environment. | string | n/a | yes |
34+
| project\_id | Project ID where Cloud Composer Environment is created. | string | n/a | yes |
35+
| region | Region where the Cloud Composer Environment is created. | string | n/a | yes |
3336

3437
## Outputs
3538

3639
| Name | Description |
3740
|------|-------------|
38-
| bucket\_name | |
41+
| airflow\_uri | URI of the Apache Airflow Web UI hosted within the Cloud Composer Environment. |
42+
| composer\_env\_id | ID of Cloud Composer Environment. |
43+
| composer\_env\_name | The name of the Cloud Composer Environment. |
44+
| gcs\_bucket | Google Cloud Storage bucket which hosts DAGs for the Cloud Composer Environment. |
45+
| gke\_cluster | Google Kubernetes Engine cluster used to run the Cloud Composer Environment. |
3946

4047
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4148

@@ -55,7 +62,11 @@ The following dependencies must be available:
5562
A service account with the following roles must be used to provision
5663
the resources of this module:
5764

58-
- Storage Admin: `roles/storage.admin`
65+
- Project Editor: `roles/editor`
66+
- Network Admin: `roles/compute.networkAdmin`
67+
- Instance Admin: `roles/compute.instanceAdmin.v1`
68+
- Sercvice Account User: `roles/iam.serviceAccountUser`
69+
- Composer Worker: `roles/composer.worker`
5970

6071
The [Project Factory module][project-factory-module] and the
6172
[IAM module][iam-module] may be used in combination to provision a
@@ -66,7 +77,7 @@ service account with the necessary roles applied.
6677
A project with the following APIs enabled must be used to host the
6778
resources of this module:
6879

69-
- Google Cloud Storage JSON API: `storage-api.googleapis.com`
80+
- Cloud Composer API: `composer.googleapis.com`
7081

7182
The [Project Factory module][project-factory-module] can be used to
7283
provision a project with the necessary APIs enabled.

build/int.cloudbuild.yaml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2020 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -21,18 +21,30 @@ steps:
2121
- 'TF_VAR_org_id=$_ORG_ID'
2222
- 'TF_VAR_folder_id=$_FOLDER_ID'
2323
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
24-
- id: create
24+
25+
# ----- SUITE simple-composer-env-local
26+
27+
- id: create simple-composer-env-local
28+
waitFor:
29+
- prepare
2530
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
26-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create']
27-
- id: converge
31+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create simple-composer-env-local']
32+
- id: converge simple-composer-env-local
33+
waitFor:
34+
- create simple-composer-env-local
2835
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
29-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge']
30-
- id: verify
36+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge simple-composer-env-local']
37+
- id: verify simple-composer-env-local
38+
waitFor:
39+
- converge simple-composer-env-local
3140
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
32-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify']
33-
- id: destroy
41+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify simple-composer-env-local']
42+
- id: destroy simple-composer-env-local
43+
waitFor:
44+
- verify simple-composer-env-local
3445
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
35-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy']
46+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy simple-composer-env-local']
47+
3648
tags:
3749
- 'ci'
3850
- 'integration'

build/lint.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2020 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Simple Cloud Composer Environment Example
2+
3+
This example illustrates how to use the `composer` module.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|:----:|:-----:|:-----:|
10+
| composer\_env\_name | Name of Cloud Composer Environment. | string | n/a | yes |
11+
| composer\_service\_account | Service Account to be used for running Cloud Composer Environment. | string | n/a | yes |
12+
| project\_id | Project ID where Cloud Composer Environment is created. | string | n/a | yes |
13+
| region | Region where Cloud Composer Environment is created. | string | n/a | yes |
14+
15+
## Outputs
16+
17+
| Name | Description |
18+
|------|-------------|
19+
| airflow\_uri | URI of the Apache Airflow Web UI hosted within the Cloud Composer Environment. |
20+
| composer\_env\_id | ID of Cloud Composer Environment. |
21+
| composer\_env\_name | Name of the Cloud Composer Environment. |
22+
| gcs\_bucket | Google Cloud Storage bucket which hosts DAGs for the Cloud Composer Environment. |
23+
| gke\_cluster | Google Kubernetes Engine cluster used to run the Cloud Composer Environment. |
24+
25+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
26+
27+
To provision this example, run the following from within this directory:
28+
- `terraform init` to get the plugins
29+
- `terraform plan` to see the infrastructure plan
30+
- `terraform apply` to apply the infrastructure build
31+
- `terraform destroy` to destroy the built infrastructure

examples/simple_example/main.tf renamed to examples/simple_composer_env/main.tf

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2020 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,13 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17+
/******************************************
18+
Provider configuration
19+
*****************************************/
1720
provider "google" {
18-
version = "~> 2.0"
21+
version = "~> 3.3"
1922
}
2023

21-
module "composer" {
22-
source = "../.."
24+
provider "google-beta" {
25+
version = "~> 3.3"
26+
}
27+
28+
module "simple-composer-environment" {
29+
source = "../../modules/create_environment"
30+
31+
project_id = var.project_id
32+
composer_env_name = var.composer_env_name
33+
region = var.region
2334

24-
project_id = var.project_id
25-
bucket_name = var.bucket_name
35+
composer_service_account = var.composer_service_account
2636
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "composer_env_name" {
18+
description = "Name of the Cloud Composer Environment."
19+
value = module.simple-composer-environment.composer_env_name
20+
}
21+
22+
output "composer_env_id" {
23+
description = "ID of Cloud Composer Environment."
24+
value = module.simple-composer-environment.composer_env_id
25+
}
26+
27+
output "gke_cluster" {
28+
description = "Google Kubernetes Engine cluster used to run the Cloud Composer Environment."
29+
value = module.simple-composer-environment.gke_cluster
30+
}
31+
32+
output "gcs_bucket" {
33+
description = "Google Cloud Storage bucket which hosts DAGs for the Cloud Composer Environment."
34+
value = module.simple-composer-environment.gcs_bucket
35+
}
36+
37+
output "airflow_uri" {
38+
description = "URI of the Apache Airflow Web UI hosted within the Cloud Composer Environment."
39+
value = module.simple-composer-environment.airflow_uri
40+
}

test/fixtures/simple_example/variables.tf renamed to examples/simple_composer_env/variables.tf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2020 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,21 @@
1515
*/
1616

1717
variable "project_id" {
18-
description = "The ID of the project in which to provision resources."
18+
description = "Project ID where Cloud Composer Environment is created."
19+
type = string
20+
}
21+
22+
variable "composer_env_name" {
23+
description = "Name of Cloud Composer Environment."
24+
type = string
25+
}
26+
27+
variable "region" {
28+
description = "Region where Cloud Composer Environment is created."
29+
type = string
30+
}
31+
32+
variable "composer_service_account" {
33+
description = "Service Account to be used for running Cloud Composer Environment."
1934
type = string
2035
}

examples/simple_example/versions.tf renamed to examples/simple_composer_env/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2020 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

examples/simple_example/README.md

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

0 commit comments

Comments
 (0)