Skip to content

Commit d349d07

Browse files
authored
feat: add submodule to manage storage (#28)
* feat: add storage management module * fix: rename to make it consistent with others * feat: added storage module * fix: cleanup
1 parent 8b03071 commit d349d07

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-0
lines changed

modules/airflow_storage/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Module Cloud Composer Storage
2+
3+
This optional module is used to configure Airflow objects like dags, plugins and data.
4+
5+
Unfortunately this capability is not exposed via the Composer API so we need to use `gcloud`
6+
7+
```hcl
8+
module "my-dag" {
9+
source = "terraform-google-modules/composer/google//modules/airflow_storage"
10+
project_id = "project-123"
11+
environment = "Composer-Prod-Env"
12+
location = "us-central1"
13+
type = "dag"
14+
source_path = "${path.root}/dags/my-dag"
15+
}
16+
```
17+
18+
See the examples for cloudsql support.
19+
20+
```
21+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
22+
## Inputs
23+
24+
| Name | Description | Type | Default | Required |
25+
|------|-------------|------|---------|:--------:|
26+
| destination\_path | The optional destination path | `string` | `null` | no |
27+
| environment | n/a | `string` | n/a | yes |
28+
| location | n/a | `string` | n/a | yes |
29+
| project\_id | n/a | `string` | n/a | yes |
30+
| source\_path | The source on the local file system | `string` | n/a | yes |
31+
| type | The type of resource to upload. Either dag, plugin or data | `string` | n/a | yes |
32+
33+
## Outputs
34+
35+
No output.
36+
37+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/airflow_storage/main.tf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
locals {
18+
# Emulate the default behaviour when --destination isn't set otherwise we don't know how to run the destroy command
19+
implied_destination = coalesce(var.destination_path, basename(var.source_path))
20+
create_parameters = {
21+
"--project" = var.project_id
22+
"--location" = var.location
23+
"--environment" = var.environment
24+
"--source" = var.source_path
25+
"--destination" = var.destination_path
26+
}
27+
destroy_parameters = {
28+
"--project" = var.project_id
29+
"--location" = var.location
30+
"--environment" = var.environment
31+
}
32+
33+
gcloud_cmd_body = "composer environments storage ${var.type}"
34+
create_cmd_body = "${local.gcloud_cmd_body} import ${join(" ", [for k, v in local.create_parameters : "${k}=${v}" if v != null])}"
35+
destroy_cmd_body = "${local.gcloud_cmd_body} delete ${join(" ", [for k, v in local.destroy_parameters : "${k}=${v}"])} ${local.implied_destination}"
36+
}
37+
38+
39+
module "gcloud" {
40+
source = "terraform-google-modules/gcloud/google"
41+
version = "~> 3.1"
42+
platform = "linux"
43+
create_cmd_body = local.create_cmd_body
44+
destroy_cmd_body = local.destroy_cmd_body
45+
46+
create_cmd_triggers = {
47+
filesha1 = join(",", [
48+
for f in fileset(var.source_path, "**") : "${f}:${filesha1("${var.source_path}/${f}")}"
49+
])
50+
}
51+
}

modules/airflow_storage/outputs.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
variable "project_id" {
18+
type = string
19+
}
20+
21+
variable "location" {
22+
type = string
23+
}
24+
25+
variable "environment" {
26+
type = string
27+
}
28+
29+
variable "type" {
30+
description = "The type of resource to upload. Either dag, plugin or data"
31+
type = string
32+
}
33+
34+
variable "source_path" {
35+
description = "The source on the local file system"
36+
type = string
37+
}
38+
39+
variable "destination_path" {
40+
description = "The optional destination path"
41+
type = string
42+
default = null
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2021 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+
terraform {
18+
required_version = ">= 0.14"
19+
required_providers {
20+
21+
google = {
22+
source = "hashicorp/google"
23+
version = "~> 3.53"
24+
}
25+
}
26+
27+
provider_meta "google" {
28+
module_name = "blueprints/terraform/terraform-google-composer:airflow_storage/v2.1.0"
29+
}
30+
}

0 commit comments

Comments
 (0)