Google Cloud Composer Environment
This page shows how to write Terraform for Cloud Composer Environment and write them securely.
google_composer_environment (Terraform)
The Environment in Cloud Composer can be configured in Terraform with the resource name google_composer_environment
. The following sections describe 4 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "google_composer_environment" "composer_env" {
name = var.composer_env_name
project = var.project_id
region = var.region
config {
resource "google_composer_environment" "main" {
provider = google-beta
name = var.config.name
region = var.region
labels = var.labels
resource "google_composer_environment" "composers_1" {
for_each = { for c in var.composers : c.name => c if substr(c.software_config.image_version, 9, 1) == "1" }
provider = google
name = each.value.name
region = var.region
labels = each.value.labels
resource "google_composer_environment" "procamp_env" {
provider = google-beta
name = "procamp-env"
region = var.region
labels = {
Parameters
User-defined labels for this environment. The labels map can contain no more than 64 entries. Entries of the labels map are UTF8 strings that comply with the following restrictions: Label keys must be between 1 and 63 characters long and must conform to the following regular expression: a-z?. Label values must be between 0 and 63 characters long and must conform to the regular expression (a-z?)?. No more than 64 labels can be associated with a given environment. Both keys and values must be <= 128 bytes in size.
-
name
required - string
Name of the environment.
-
project
optional computed - string
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
-
region
optional - string
The location or Compute Engine region for the environment.
-
config
list block-
airflow_uri
optional computed - string
The URI of the Apache Airflow Web UI hosted within this environment.
-
dag_gcs_prefix
optional computed - string
The Cloud Storage prefix of the DAGs for this environment. Although Cloud Storage objects reside in a flat namespace, a hierarchical file tree can be simulated using '/'-delimited object name prefixes. DAG objects for this environment reside in a simulated directory with this prefix.
-
gke_cluster
optional computed - string
The Kubernetes Engine cluster used to run this environment.
-
node_count
optional computed - number
The number of nodes in the Kubernetes Engine cluster that will be used to run this environment.
-
node_config
list block-
disk_size_gb
optional computed - number
The disk size in GB used for node VMs. Minimum size is 20GB. If unspecified, defaults to 100GB. Cannot be updated.
-
ip_allocation_policy
optional computed - list of object
Configuration for controlling how IPs are allocated in the GKE cluster. Cannot be updated.
-
cluster_ipv4_cidr_block
- string -
cluster_secondary_range_name
- string -
services_ipv4_cidr_block
- string -
services_secondary_range_name
- string -
use_ip_aliases
- bool -
machine_type
optional computed - string
The Compute Engine machine type used for cluster instances, specified as a name or relative resource name. For example: "projects/[project]/zones/[zone]/machineTypes/[machineType]". Must belong to the enclosing environment's project and region/zone.
-
network
optional computed - string
The Compute Engine machine type used for cluster instances, specified as a name or relative resource name. For example: "projects/[project]/zones/[zone]/machineTypes/[machineType]". Must belong to the enclosing environment's project and region/zone. The network must belong to the environment's project. If unspecified, the "default" network ID in the environment's project is used. If a Custom Subnet Network is provided, subnetwork must also be provided.
-
oauth_scopes
optional computed - set of string
The set of Google API scopes to be made available on all node VMs. Cannot be updated. If empty, defaults to ["https://www.googleapis.com/auth/cloud-platform"].
-
service_account
optional computed - string
The Google Cloud Platform Service Account to be used by the node VMs. If a service account is not specified, the "default" Compute Engine service account is used. Cannot be updated. If given, note that the service account must have roles/composer.worker for any GCP resources created under the Cloud Composer Environment.
-
subnetwork
optional - string
The Compute Engine subnetwork to be used for machine communications, , specified as a self-link, relative resource name (e.g. "projects/[project]/regions/[region]/subnetworks/[subnetwork]"), or by name. If subnetwork is provided, network must also be provided and the subnetwork must belong to the enclosing environment's project and region.
-
tags
optional - set of string
The list of instance tags applied to all node VMs. Tags are used to identify valid sources or targets for network firewalls. Each tag within the list must comply with RFC1035. Cannot be updated.
-
zone
required - string
The Compute Engine zone in which to deploy the VMs running the Apache Airflow software, specified as the zone name or relative resource name (e.g. "projects/[project]/zones/[zone]"). Must belong to the enclosing environment's project and region.
-
-
private_environment_config
list block-
cloud_sql_ipv4_cidr_block
optional computed - string
The CIDR block from which IP range in tenant project will be reserved for Cloud SQL. Needs to be disjoint from web_server_ipv4_cidr_block.
-
enable_private_endpoint
optional - bool
If true, access to the public endpoint of the GKE cluster is denied.
-
master_ipv4_cidr_block
optional - string
The IP range in CIDR notation to use for the hosted master network. This range is used for assigning internal IP addresses to the cluster master or set of masters and to the internal load balancer virtual IP. This range must not overlap with any other ranges in use within the cluster's network. If left blank, the default value of '172.16.0.0/28' is used.
-
web_server_ipv4_cidr_block
optional computed - string
The CIDR block from which IP range for web server will be reserved. Needs to be disjoint from master_ipv4_cidr_block and cloud_sql_ipv4_cidr_block.
-
-
software_config
list block-
airflow_config_overrides
optional - map from string to string
Apache 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". Section names must not contain hyphens ("-"), opening square brackets ("["), or closing square brackets ("]"). The property name must not be empty and cannot contain "=" or ";". Section and property names cannot contain characters: "." Apache Airflow configuration property names must be written in snake_case. Property values can contain any character, and can be written in any lower/upper case format. Certain Apache Airflow configuration property values are blacklisted, and cannot be overridden.
-
env_variables
optional - map from string to string
Additional environment variables to provide to the Apache Airflow scheduler, worker, and webserver processes. Environment variable names must match the regular expression [a-zA-Z_][a-za-z0-9_]*. They cannot specify Apache Airflow software configuration overrides (they cannot match the regular expression AIRFLOW[A-Z0-9_]+[A-Z0-9_]+), and they cannot match any of the following reserved names: AIRFLOW_HOME C_FORCE_ROOT CONTAINER_NAME DAGS_FOLDER GCP_PROJECT GCS_BUCKET GKE_CLUSTER_NAME SQL_DATABASE SQL_INSTANCE SQL_PASSWORD SQL_PROJECT SQL_REGION SQL_USER.
-
image_version
optional computed - string
The version of the software running in the environment. This encapsulates both the version of Cloud Composer functionality and the version of Apache Airflow. It must match the regular expression composer-[0-9]+.[0-9]+(.[0-9]+)?-airflow-[0-9]+.[0-9]+(.[0-9]+.*)?. The Cloud Composer portion of the version is a semantic version. The portion of the image version following 'airflow-' is an official Apache Airflow repository release name. See documentation for allowed release names.
-
pypi_packages
optional - map from string to string
Custom Python Package Index (PyPI) packages to be installed in the environment. Keys refer to the lowercase package name (e.g. "numpy"). Values are the lowercase extras and version specifier (e.g. "==1.12.0", "[devel,gcp_api]", "[devel]>=1.8.2, <1.9.2"). To specify a package without pinning it to a version specifier, use the empty string as the value.
-
python_version
optional computed - string
The major version of Python used to run the Apache Airflow scheduler, worker, and webserver processes. Can be set to '2' or '3'. If not specified, the default is '2'. Cannot be updated.
-
-
-
timeouts
single block
Explanation in Terraform Registry
An environment for running orchestration tasks. Environments run Apache Airflow software on Google infrastructure. To get more information about Environments, see:
- Cloud Composer documentation
- Cloud Composer API documentation
- How-to Guides (Cloud Composer 1)
- How-to Guides (Cloud Composer 2)
- Apache Airflow Documentation
Warning: We STRONGLY recommend you read the GCP guides as the Environment resource requires a long deployment process and involves several layers of GCP infrastructure, including a Kubernetes Engine cluster, Cloud Storage, and Compute networking resources. Due to limitations of the API, Terraform will not be able to automatically find or manage many of these underlying resources. In particular:
- It can take up to one hour to create or update an environment resource. In addition, GCP may only detect some errors in configuration when they are used (e.g. ~40-50 minutes into the creation process), and is prone to limited error reporting. If you encounter confusing or uninformative errors, please verify your configuration is valid against GCP Cloud Composer before filing bugs against the Terraform provider. > Environments create Google Cloud Storage buckets that do not get cleaned up automatically on environment deletion. More about Composer's use of Cloud Storage. Please review the known issues for Composer if you are having problems.
Frequently asked questions
What is Google Cloud Composer Environment?
Google Cloud Composer Environment is a resource for Cloud Composer of Google Cloud Platform. Settings can be wrote in Terraform.
Where can I find the example code for the Google Cloud Composer Environment?
For Terraform, the brodriguesmclara/desafio, AtsushiKitano/assets and ICTEAM-Test-AMPDWH/symphony_adp_infra_lib source code examples are useful. See the Terraform Example section for further details.