Skip to content

Commit 82e3c04

Browse files
authored
fix: duplicate maintenance_window (#100)
1 parent 9db266c commit 82e3c04

File tree

9 files changed

+115
-68
lines changed

9 files changed

+115
-68
lines changed

examples/simple_composer_env_v2/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Simple Cloud Composer Environment (V2) Example
22

3-
This example illustrates how to use the `composer` module.
3+
This example illustrates how to use the `composer` V2 module to deploy private composer environment with private GKE cluster, CloudSql instance and use private service connect (PSC) endpoint to connect to CloudSql instance. `use_private_environment` and `enable_private_endpoint` needs to be `true` to deploy private GKE cluster and CloudSql instance. `cloud_composer_connection_subnetwork` value will result in PSC endpoint for CloudSql instance.
4+
5+
This example also creates a Cloud Storage Bucket for scheduled snapshots and assign appropriate permission(s) to Composer Service Account on the bucket.
46

57
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
68
## Inputs
@@ -14,7 +16,8 @@ This example illustrates how to use the `composer` module.
1416
| project\_id | Project ID where Cloud Composer Environment is created. | `string` | n/a | yes |
1517
| region | Region where Cloud Composer Environment is created. | `string` | n/a | yes |
1618
| service\_ip\_allocation\_range\_name | The name of the services' secondary range used to allocate IP addresses to the cluster. | `string` | n/a | yes |
17-
| subnetwork | Subetwork where Cloud Composer is created. | `string` | n/a | yes |
19+
| subnetwork | Name of the Subetwork where Cloud Composer is created. | `string` | n/a | yes |
20+
| subnetwork\_self\_link | self\_link of the Subetwork where Cloud Composer is created. | `string` | n/a | yes |
1821

1922
## Outputs
2023

examples/simple_composer_env_v2/main.tf

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,36 @@ resource "google_storage_bucket_iam_member" "object_admin" {
3636
}
3737

3838
module "simple-composer-environment" {
39-
source = "../../modules/create_environment_v2"
40-
project_id = var.project_id
41-
composer_env_name = var.composer_env_name
42-
region = var.region
43-
composer_service_account = var.composer_service_account
44-
network = var.network
45-
subnetwork = var.subnetwork
46-
pod_ip_allocation_range_name = var.pod_ip_allocation_range_name
47-
service_ip_allocation_range_name = var.service_ip_allocation_range_name
48-
grant_sa_agent_permission = false
49-
environment_size = "ENVIRONMENT_SIZE_SMALL"
50-
enable_private_endpoint = true
51-
use_private_environment = true
39+
source = "../../modules/create_environment_v2"
40+
project_id = var.project_id
41+
composer_env_name = var.composer_env_name
42+
region = var.region
43+
composer_service_account = var.composer_service_account
44+
network = var.network
45+
subnetwork = var.subnetwork
46+
pod_ip_allocation_range_name = var.pod_ip_allocation_range_name
47+
service_ip_allocation_range_name = var.service_ip_allocation_range_name
48+
grant_sa_agent_permission = false
49+
environment_size = "ENVIRONMENT_SIZE_SMALL"
50+
enable_private_endpoint = true
51+
use_private_environment = true
52+
cloud_composer_connection_subnetwork = var.subnetwork_self_link
53+
cloud_data_lineage_integration = true
54+
resilience_mode = "STANDARD_RESILIENCE"
5255

5356
scheduler = {
5457
cpu = 0.5
5558
memory_gb = 1.875
5659
storage_gb = 1
5760
count = 2
61+
5862
}
5963
web_server = {
6064
cpu = 0.5
6165
memory_gb = 1.875
6266
storage_gb = 1
6367
}
68+
6469
worker = {
6570
cpu = 0.5
6671
memory_gb = 1.875
@@ -69,18 +74,22 @@ module "simple-composer-environment" {
6974
max_count = 3
7075
}
7176

77+
triggerer = {
78+
cpu = 1
79+
memory_gb = 1
80+
count = 2
81+
}
82+
7283
scheduled_snapshots_config = {
7384
enabled = true
7485
snapshot_location = google_storage_bucket.my_bucket.url
7586
snapshot_creation_schedule = "0 4 * * *"
7687
time_zone = "UTC+01"
7788
}
7889

79-
maintenance_window = {
80-
start_time = "2023-01-01T00:00:00Z"
81-
end_time = "2023-01-01T12:00:00Z"
82-
recurrence = "FREQ=WEEKLY;BYDAY=SU,WE,SA"
83-
}
90+
maintenance_start_time = "2023-01-01T00:00:00Z"
91+
maintenance_end_time = "2023-01-01T12:00:00Z"
92+
maintenance_recurrence = "FREQ=WEEKLY;BYDAY=SU,SA"
8493

8594
depends_on = [
8695
google_storage_bucket_iam_member.object_admin,

examples/simple_composer_env_v2/variables.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ variable "network" {
4141
}
4242

4343
variable "subnetwork" {
44-
description = "Subetwork where Cloud Composer is created."
44+
description = "Name of the Subetwork where Cloud Composer is created."
45+
type = string
46+
}
47+
48+
variable "subnetwork_self_link" {
49+
description = "self_link of the Subetwork where Cloud Composer is created."
4550
type = string
4651
}
4752

modules/create_environment_v2/README.md

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,96 @@
11
# Module Cloud Composer Environment ([V2](https://cloud.google.com/composer/docs/composer-2/composer-overview))
22

3-
This optional module is used to create a Cloud Composer environment.
3+
This module is used to create a Cloud Composer V2 environment.
4+
45

56
```hcl
6-
module "composer" {
7-
source = "terraform-google-modules/composer/google//modules/create_environment_v2"
7+
module "simple-composer-environment" {
8+
source = "terraform-google-modules/composer/google//modules/create_environment_v2"
9+
version = "~> 4.0"
10+
project_id = var.project_id
11+
composer_env_name = "test-composer-env"
12+
region = "us-central1"
13+
composer_service_account = var.composer_service_account
14+
network = "test-vpc"
15+
subnetwork = "test-subnet"
16+
pod_ip_allocation_range_name = "test-subnet-pod-ip-name"
17+
service_ip_allocation_range_name = "test-subnet-service-ip-name"
18+
grant_sa_agent_permission = false
19+
environment_size = "ENVIRONMENT_SIZE_SMALL"
20+
enable_private_endpoint = true
21+
use_private_environment = true
22+
cloud_composer_connection_subnetwork = var.subnetwork_self_link
23+
24+
scheduler = {
25+
cpu = 0.5
26+
memory_gb = 1.875
27+
storage_gb = 1
28+
count = 2
29+
}
30+
31+
web_server = {
32+
cpu = 0.5
33+
memory_gb = 1.875
34+
storage_gb = 1
35+
}
36+
37+
worker = {
38+
cpu = 0.5
39+
memory_gb = 1.875
40+
storage_gb = 1
41+
min_count = 2
42+
max_count = 3
43+
}
44+
45+
triggerer = {
46+
cpu = 1
47+
memory_gb = 1
48+
count = 2
49+
}
850
9-
project = "project-123"
10-
name = "Composer-Prod-Env"
11-
region = "us-central1"
1251
}
52+
1353
```
1454
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1555
## Inputs
1656

1757
| Name | Description | Type | Default | Required |
1858
|------|-------------|------|---------|:--------:|
1959
| airflow\_config\_overrides | Airflow configuration properties to override. Property keys contain the section and property names, separated by a hyphen, for example "core-dags\_are\_paused\_at\_creation". | `map(string)` | `{}` | no |
20-
| cloud\_composer\_connection\_subnetwork | When specified, the environment will use Private Service Connect instead of VPC peerings to connect to Cloud SQL in the Tenant Project | `string` | `null` | no |
21-
| cloud\_composer\_network\_ipv4\_cidr\_block | The CIDR block from which IP range in tenant project will be reserved. | `string` | `null` | no |
60+
| cloud\_composer\_connection\_subnetwork | Subnetwork self-link. When specified, the environment will use Private Service Connect instead of VPC peerings to connect to CloudSQL in the Tenant Project. IP address of psc endpoint is allocated from this subnet | `string` | `null` | no |
61+
| cloud\_composer\_network\_ipv4\_cidr\_block | The CIDR block from which IP range in tenant project will be reserved. Required if VPC peering is used to connect to CloudSql instead of PSC | `string` | `null` | no |
2262
| cloud\_data\_lineage\_integration | Whether or not Dataplex data lineage integration is enabled. Cloud Composer environments in versions composer-2.1.2-airflow-..* and newer) | `bool` | `false` | no |
23-
| cloud\_sql\_ipv4\_cidr | The CIDR block from which IP range in tenant project will be reserved for Cloud SQL. | `string` | `null` | no |
63+
| cloud\_sql\_ipv4\_cidr | The CIDR block from which IP range in tenant project will be reserved for Cloud SQL private service access. Required if VPC peering is used to connect to CloudSql instead of PSC | `string` | `null` | no |
2464
| composer\_env\_name | Name of Cloud Composer Environment | `string` | n/a | yes |
2565
| composer\_service\_account | Service Account for running Cloud Composer. | `string` | `null` | no |
2666
| enable\_ip\_masq\_agent | Deploys 'ip-masq-agent' daemon set in the GKE cluster and defines nonMasqueradeCIDRs equals to pod IP range so IP masquerading is used for all destination addresses, except between pods traffic. | `bool` | `false` | no |
27-
| enable\_private\_endpoint | Configure public access to the cluster endpoint. | `bool` | `false` | no |
67+
| enable\_private\_endpoint | Configure private access to the cluster endpoint. If true, access to the public endpoint of the GKE cluster is denied | `bool` | `false` | no |
2868
| env\_variables | Variables of the airflow environment. | `map(string)` | `{}` | no |
29-
| environment\_size | The environment size controls the performance parameters of the managed Cloud Composer infrastructure that includes the Airflow database. Values for environment size are: ENVIRONMENT\_SIZE\_SMALL, ENVIRONMENT\_SIZE\_MEDIUM, and ENVIRONMENT\_SIZE\_LARGE. | `string` | `"ENVIRONMENT_SIZE_MEDIUM"` | no |
69+
| environment\_size | The environment size controls the performance parameters of the managed Cloud Composer infrastructure that includes the Airflow database. Values for environment size are: `ENVIRONMENT_SIZE_SMALL`, `ENVIRONMENT_SIZE_MEDIUM`, and `ENVIRONMENT_SIZE_LARGE`. | `string` | `"ENVIRONMENT_SIZE_MEDIUM"` | no |
3070
| grant\_sa\_agent\_permission | Cloud Composer relies on Workload Identity as Google API authentication mechanism for Airflow. | `bool` | `true` | no |
3171
| image\_version | The version of the aiflow running in the cloud composer environment. | `string` | `"composer-2.5.0-airflow-2.6.3"` | no |
3272
| labels | The resource labels (a map of key/value pairs) to be applied to the Cloud Composer. | `map(string)` | `{}` | no |
3373
| maintenance\_end\_time | Time window specified for recurring maintenance operations in RFC3339 format | `string` | `null` | no |
3474
| maintenance\_recurrence | Frequency of the recurring maintenance window in RFC5545 format. | `string` | `null` | no |
3575
| maintenance\_start\_time | Time window specified for daily or recurring maintenance operations in RFC3339 format | `string` | `"05:00"` | no |
36-
| maintenance\_window | The recovery configuration settings for the Cloud Composer environment | <pre>object({<br> start_time = string<br> end_time = string<br> recurrence = string<br> })</pre> | `null` | no |
3776
| master\_authorized\_networks | List of master authorized networks. If none are provided, disallow external access (except the cluster node IPs, which GKE automatically whitelists). | <pre>list(object({<br> cidr_block = string<br> display_name = string<br> }))</pre> | `[]` | no |
38-
| master\_ipv4\_cidr | The CIDR block from which IP range in tenant project will be reserved for the master. | `string` | `null` | no |
77+
| master\_ipv4\_cidr | The CIDR block from which IP range in tenant project will be reserved for the GKE master. Required when `use_private_environment` and `enable_private_endpoint` is `true` | `string` | `null` | no |
3978
| network | The VPC network to host the composer cluster. | `string` | n/a | yes |
4079
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
41-
| pod\_ip\_allocation\_range\_name | The name of the cluster's secondary range used to allocate IP addresses to pods. | `string` | `null` | no |
80+
| pod\_ip\_allocation\_range\_name | The name of the subnet secondary range, used to allocate IP addresses for the pods. | `string` | `null` | no |
4281
| project\_id | Project ID where Cloud Composer Environment is created. | `string` | n/a | yes |
4382
| pypi\_packages | Custom Python Package Index (PyPI) packages to be installed in the environment. Keys refer to the lowercase package name (e.g. "numpy"). | `map(string)` | `{}` | no |
4483
| region | Region where the Cloud Composer Environment is created. | `string` | `"us-central1"` | no |
4584
| resilience\_mode | Cloud Composer 2.1.15 or newer only. The resilience mode states whether high resilience is enabled for the environment or not. Values for resilience mode are `HIGH_RESILIENCE` for high resilience and `STANDARD_RESILIENCE` for standard resilience | `string` | `null` | no |
4685
| scheduled\_snapshots\_config | The recovery configuration settings for the Cloud Composer environment | <pre>object({<br> enabled = optional(bool, false)<br> snapshot_location = optional(string)<br> snapshot_creation_schedule = optional(string)<br> time_zone = optional(string)<br> })</pre> | `null` | no |
4786
| scheduler | Configuration for resources used by Airflow schedulers. | <pre>object({<br> cpu = string<br> memory_gb = number<br> storage_gb = number<br> count = number<br> })</pre> | <pre>{<br> "count": 2,<br> "cpu": 2,<br> "memory_gb": 7.5,<br> "storage_gb": 5<br>}</pre> | no |
48-
| service\_ip\_allocation\_range\_name | The name of the services' secondary range used to allocate IP addresses to the cluster. | `string` | `null` | no |
87+
| service\_ip\_allocation\_range\_name | The name of the subnet secondary range, used to allocate IP addresses for the Services. | `string` | `null` | no |
4988
| storage\_bucket | Name of an existing Cloud Storage bucket to be used by the environment | `string` | `null` | no |
50-
| subnetwork | The subnetwork to host the composer cluster. | `string` | n/a | yes |
89+
| subnetwork | The name of the subnetwork to host the composer cluster. | `string` | n/a | yes |
5190
| subnetwork\_region | The subnetwork region of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
5291
| tags | Tags applied to all nodes. Tags are used to identify valid sources or targets for network firewalls. | `set(string)` | `[]` | no |
5392
| triggerer | Configuration for resources used by Airflow triggerer | <pre>object({<br> cpu = string<br> memory_gb = number<br> count = number<br> })</pre> | `null` | no |
54-
| use\_private\_environment | Enable private environment. | `bool` | `false` | no |
93+
| use\_private\_environment | Create a private environment. | `bool` | `false` | no |
5594
| web\_server | Configuration for resources used by Airflow web server. | <pre>object({<br> cpu = string<br> memory_gb = number<br> storage_gb = number<br> })</pre> | <pre>{<br> "cpu": 2,<br> "memory_gb": 7.5,<br> "storage_gb": 5<br>}</pre> | no |
5695
| worker | Configuration for resources used by Airflow workers. | <pre>object({<br> cpu = string<br> memory_gb = number<br> storage_gb = number<br> min_count = number<br> max_count = number<br> })</pre> | <pre>{<br> "cpu": 2,<br> "max_count": 6,<br> "memory_gb": 7.5,<br> "min_count": 2,<br> "storage_gb": 5<br>}</pre> | no |
5796

@@ -60,6 +99,7 @@ module "composer" {
6099
| Name | Description |
61100
|------|-------------|
62101
| airflow\_uri | URI of the Apache Airflow Web UI hosted within the Cloud Composer Environment. |
102+
| composer\_env | Cloud Composer Environment |
63103
| composer\_env\_id | ID of Cloud Composer Environment. |
64104
| composer\_env\_name | Name of the Cloud Composer Environment. |
65105
| gcs\_bucket | Google Cloud Storage bucket which hosts DAGs for the Cloud Composer Environment. |

modules/create_environment_v2/main.tf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,6 @@ resource "google_composer_environment" "composer_env" {
186186
}
187187
}
188188

189-
dynamic "maintenance_window" {
190-
for_each = var.maintenance_window != null ? [var.maintenance_window] : []
191-
content {
192-
start_time = maintenance_window.value["start_time"]
193-
end_time = maintenance_window.value["end_time"]
194-
recurrence = maintenance_window.value["recurrence"]
195-
}
196-
197-
}
198-
199189
}
200190

201191
depends_on = [google_project_iam_member.composer_agent_service_account]

modules/create_environment_v2/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ output "airflow_uri" {
3838
value = google_composer_environment.composer_env.config[0].airflow_uri
3939
description = "URI of the Apache Airflow Web UI hosted within the Cloud Composer Environment."
4040
}
41+
42+
output "composer_env" {
43+
value = google_composer_environment.composer_env
44+
description = "Cloud Composer Environment"
45+
}

0 commit comments

Comments
 (0)