Skip to content

Commit b6b655f

Browse files
committed
init/updateGCPTerraformModules: 1.3.0
Signed-off-by: FTNT-HQCM <hq-devops-admin@fortinet.com>
1 parent 737af88 commit b6b655f

File tree

19 files changed

+371
-29
lines changed

19 files changed

+371
-29
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 1.3.0 (2025)
2+
3+
FEATURES:
4+
* **New Module**: `modules/gcp/iam`. It helps you create a new service account with specified roles.
5+
6+
IMPROVEMENTS:
7+
* Document: Added image guide and cloud function guide.
8+
* Module `modules/fortigate/fgt_asg_with_function`:
9+
* Added a hash number to the `google_compute_region_instance_template` name. This enables the project to update the FGT image source without requiring a full deletion and redeployment. To upgrade the FGT version, simply change the `image_source`.
10+
* Added new variables `special_behavior.function_creation_wait_sec` and `special_behavior.function_destruction_wait_sec`. If set to a nonzero value, these variables make the project wait for the specified number of seconds after creating or before destroying the cloud function.
11+
* Supported FGTs connecting to FAZ. New function variables: `FAZ_IP`, `FAZ_ADOM`, `FAZ_USERNAME`, `FAZ_PASSWORD`.
12+
* The `"DEBUG"` log level has been further refined into `"DEBUG"` and `"TRACE"`. The `"TRACE"` level outputs more detailed and verbose log information.
13+
* Improved function logic and added `task_list` to support multi-threading related tasks.
14+
115
## 1.2.0 (January 31, 2025)
216

317
IMPROVEMENTS:

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![Fortinet logo|](https://upload.wikimedia.org/wikipedia/commons/thumb/6/62/Fortinet_logo.svg/320px-Fortinet_logo.svg.png)
2+
13
## Terraform modules for Fortinet VM products on GCP
24

35
Terraform modules for deploying Fortinet VM products (e.g. FortiGate VM) on GCP.
@@ -29,25 +31,29 @@ Please click the following links for visual diagrams, requirements, example depl
2931

3032
**Use it as a Terraform project (Examples only)**
3133

32-
1. Navigate to the example folder (e.g., "examples/autoscale_fgt_lb_sandwich").
33-
2. Edit the file "terraform.tfvars.template" and rename it to "terraform.tfvars".
34-
3. Execute the commands `terraform init` and `terraform apply`.
34+
1. Clone the module to your environment.
35+
2. Navigate to the example folder (e.g., "examples/autoscale_fgt_lb_sandwich").
36+
3. Edit the file "terraform.tfvars.template" and rename it to "terraform.tfvars".
37+
4. Execute the commands `terraform init` and `terraform apply`.
3538

3639
**Use it as a module (Examples and Modules)**
3740

38-
1. Create a new folder and add a file named "main.tf" within this folder.
39-
2. In "main.tf", specify the module with the necessary parameters.
41+
1. Create a new folder and add a file named "main.tf" within this folder.
42+
2. In "main.tf", specify the source to the target example, for instance: `"fortinetdev/cloud-modules/google//examples/autoscale_fgt_lb_sandwich"`. Provide your own values for necessary parameters of the module. There is a file named `terraform.tfvars.template` on each example, which could be a reference.
4043

41-
```
42-
module "your_module_name" {
43-
source = "fortinetdev/cloud-modules/google//examples/<example_name>"
44-
# source = "fortinetdev/cloud-modules/google//modules/fortigate/<module_name>"
44+
```
45+
module "your_module_name" {
46+
source = "fortinetdev/cloud-modules/google//examples/<example_name>"
4547
46-
other_variable = "xxx"
47-
}
48-
```
48+
<Specify module variables>
49+
}
50+
```
4951
3. Execute the commands `terraform init` and `terraform apply`.
5052

53+
## FAQ
54+
- [How to Specify Image](https://github.com/fortinetdev/terraform-google-cloud-modules/blob/main/docs/guide_image.md)
55+
- [What is Cloud Function](https://github.com/fortinetdev/terraform-google-cloud-modules/blob/main/docs/guide_function.md)
56+
5157
## Request, Question or Issue
5258

5359
If there is a missing feature or a bug -- [open an issue](https://github.com/fortinetdev/terraform-google-cloud-modules/issues/new)

docs/autoscale_fgt_as_hub.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ The variable `image_type` and variable `image_source` are mutually exclusive, on
103103
- "fortigate-76-byol" means the FGT image is the latest patch of FGT 7.6, and you want to bring your own licenses (byol). You need to specify your FortiGate license source in `cloud_function -> license_source`.
104104
- "fortigate-76-byol" means the FGT image is the latest patch of FGT 7.6, and you want to [pay as you go (payg)](https://console.cloud.google.com/marketplace/product/fortigcp-project-001/fortigate-payg). You don't need to specify the FortiGate license source. However, you need to pay an additional license fee in GCP based on the number of CPU cores (vCPU) of the instance.
105105

106-
`image_source` is the source of the custom image. Example value: "projects/fortigcp-project-001/global/images/fortinet-fgt-760-20240726-001-w-license"
106+
`image_source` specifies the source of the custom image. Example value: "projects/fortigcp-project-001/global/images/fortinet-fgt-760-20240726-001-w-license"
107+
After deploying the project, modifying this variable only affects newly created FortiGate instances. The image of existing FortiGate instances remains unchanged.
108+
109+
Check [here](https://github.com/fortinetdev/terraform-google-cloud-modules/blob/main/docs/guide_image.md) for more information about image.
107110

108111
If `additional_disk` is specified, every FGT will have its own log disk, and the initialization time will increase by 1~2 minutes.
109112

@@ -200,7 +203,7 @@ cloud_function = {
200203
}
201204
```
202205

203-
Cloud function is used to manage FGT synchronization and inject license into FGT.
206+
Cloud Function is used to manage FGT synchronization and inject license into FGT. For more information about the Cloud Function, please check [here](https://github.com/fortinetdev/terraform-google-cloud-modules/blob/main/docs/guide_function.md).
204207

205208
`cloud_func_interface` is the interface of the FortiGates communicate with the Cloud Function. The default value is "port1".
206209
By default, this project assumes the Cloud Function connects to the first VPC you specified in `network_interfaces`, and configure your FGTs through "port1". You can also set it to "port2", "port3", ..., "port8" to force the Cloud Function to connect to other VPC and communicate with your FortiGates through that port.
@@ -415,4 +418,5 @@ module "example_vpc" {
415418
```
416419

417420
## Others
418-
**Even if `terraform apply` is complete, FortiGates require time to initialize, load licenses and synchronize within the auto-scaling group, which may take 5 to 10 minutes. During this period, the FortiGates will be unavailable.**
421+
- **Even if `terraform apply` is complete, FortiGates require time to initialize, load licenses and synchronize within the auto-scaling group, which may take 5 to 10 minutes. During this period, the FortiGates will be unavailable.**
422+
- After deploying the project, modifying variable `image_source` only affects newly created FortiGate instances. The image of existing FortiGate instances remains unchanged.

docs/autoscale_fgt_lb_sandwich.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ The variable `image_type` and variable `image_source` are mutually exclusive, on
104104
- "fortigate-76-byol" means the FGT image is the latest patch of FGT 7.6, and you want to bring your own licenses (byol). You need to specify your FortiGate license source in `cloud_function -> license_source`.
105105
- "fortigate-76-byol" means the FGT image is the latest patch of FGT 7.6, and you want to [pay as you go (payg)](https://console.cloud.google.com/marketplace/product/fortigcp-project-001/fortigate-payg). You don't need to specify the FortiGate license source. However, you need to pay an additional license fee in GCP based on the number of CPU cores (vCPU) of the instance.
106106

107-
`image_source` is the source of the custom image. Example value: "projects/fortigcp-project-001/global/images/fortinet-fgt-760-20240726-001-w-license"
107+
`image_source` specifies the source of the custom image. Example value: "projects/fortigcp-project-001/global/images/fortinet-fgt-760-20240726-001-w-license"
108+
After deploying the project, modifying this variable only affects newly created FortiGate instances. The image of existing FortiGate instances remains unchanged.
109+
110+
Check [here](https://github.com/fortinetdev/terraform-google-cloud-modules/blob/main/docs/guide_image.md) for more information about image.
108111

109112
If `additional_disk` is specified, every FGT will have its own log disk, and the initialization time will increase by 1~2 minutes.
110113

@@ -152,7 +155,7 @@ cloud_function = {
152155
# Possible value: "none", "fortiflex", "file", "file_fortiflex"
153156
license_file_folder = "./licenses" # The folder where all ".lic" license files are located.
154157
autoscale_psksecret = "<RANDOM-STRING>" # The secret key used to synchronize information between FortiGates. If not set, the module will randomly generate a 16-character secret key.
155-
logging_level = "NONE" # Verbosity of logs. Possible values include "NONE", "ERROR", "WARN", "INFO", "DEBUG", and "TRACE".
158+
logging_level = "INFO" # Verbosity of logs. Possible values include "NONE", "ERROR", "WARN", "INFO", "DEBUG", and "TRACE".
156159
# "fortiflex" parameters is required if license_source is "fortiflex" or "file_fortiflex"
157160
# fortiflex = {
158161
# retrieve_mode = "use_active" # How to retrieve an existing fortiflex license (entitlement)
@@ -175,7 +178,7 @@ cloud_function = {
175178
# additional_variables = {} # Additional Cloud Function Variables
176179
}
177180
```
178-
Cloud function is used to manage FGT synchronization and inject license into FGT.
181+
Cloud Function is used to manage FGT synchronization and inject license into FGT. For more information about the Cloud Function, please check [here](https://github.com/fortinetdev/terraform-google-cloud-modules/blob/main/docs/guide_function.md).
179182

180183
`function_ip_range` is used by cloud function. This IP range needs to end with "/28" and cannot be used by any other resources.
181184
A static route will be created in the FGT that routes data destined for `cloud_function.function_ip_range` to port1.
@@ -250,7 +253,7 @@ Autoscaler is used to control when to autoscale and control the number of FortiG
250253

251254
`scale_in_control_sec` can prevent the aggressive scale down. If `scale_in_control_sec` is not 0, when the group scales down, Google Cloud will delete at most one FGT every 'scale_in_control_sec' seconds. By default, its value is 300.
252255

253-
#### Additional FGT configuration script.
256+
#### Additional FGT configuration script:
254257

255258
**NOTE: After deploying this terraform project, changing the variable `config_script` (and contents in `config_file`) will not change the FortiGate configuration.**
256259

@@ -340,6 +343,6 @@ The default username is `"admin"`. You can get the password by using the command
340343

341344

342345
## Others
343-
**Even if `terraform apply` is complete, FortiGates require time to initialize, load licenses and synchronize within the auto-scaling group, which may take 5 to 10 minutes. During this period, the FortiGates will be unavailable.**
344-
345-
To reduce disruption to your VPCs, initially run `terraform apply` without defining `protected_vpc`. Once all FortiGates in the project are fully initialized, execute `terraform apply` again, this time specifying `protected_vpc`.
346+
- **Even if `terraform apply` is complete, FortiGates require time to initialize, load licenses and synchronize within the auto-scaling group, which may take 5 to 10 minutes. During this period, the FortiGates will be unavailable.**
347+
- After deploying the project, modifying variable `image_source` only affects newly created FortiGate instances. The image of existing FortiGate instances remains unchanged.
348+
- To reduce disruption to your VPCs, initially run `terraform apply` without defining `protected_vpc`. Once all FortiGates in the project are fully initialized, execute `terraform apply` again, this time specifying `protected_vpc`.

docs/guide_funtion.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Guide: Cloud Functions (Cloud Run Functions)
2+
3+
> This guide explains the functionality of Cloud Functions and how to control their behavior. While this knowledge is not required to deploy the FortiGate autoscale project, understanding it can help with debugging and customizing behaviors.
4+
5+
Google Cloud Functions (also known as Cloud Run Functions) is a serverless, event-driven computing service that allows you to run code without managing servers. This project uses Cloud Functions for FGT license management, configuration setup, and autoscaling.
6+
7+
The Google Cloud Functions is used by the `fgt_asg_with_function` module. Its script is stored in `/modules/fortigate/fgt_asg_with_function/cloud_function.zip`. You can download the latest file [here](https://github.com/fortinetdev/terraform-google-cloud-modules/blob/main/modules/fortigate/fgt_asg_with_function/cloud_function.zip).
8+
9+
10+
- [Guide: Cloud Functions (Cloud Run Functions)](#guide-cloud-functions-cloud-run-functions)
11+
- [Workflow](#workflow)
12+
- [Customize Function Behaviors](#customize-function-behaviors)
13+
- [Cloud Functions Service](#cloud-functions-service)
14+
- [Logging](#logging)
15+
16+
17+
18+
## Workflow
19+
![](./images/function_workflow.svg)
20+
21+
Google Cloud Functions is an event-driven computing service, typically triggered by the creation or deletion of FortiGate (FGT) instances.
22+
23+
When an FGT instance is created or deleted, a corresponding [log](https://console.cloud.google.com/logs/query) is generated. This Terraform project includes a [log router sink](https://console.cloud.google.com/logs/router) that continuously monitors Google Cloud Logs. When the log router sink detects an FGT creation or deletion event, it forwards a message to a [Pub/Sub topic](https://console.cloud.google.com/cloudpubsub/topic/list), which in turn triggers the execution of [Cloud Functions](https://console.cloud.google.com/run).
24+
25+
Cloud Functions operate as multi-threaded Python scripts, with each event triggering a separate thread. These scripts handle tasks such as FGT license management, configuration setup, and autoscaling. Cloud Functions interact with the [Firestroe database](https://console.cloud.google.com/firestore/databases) for data storage and retrieval. If a task cannot be completed within the current thread, the Cloud Function thread saves the task details to Firestore and publishes a message to the pub/sub topic. This triggers another Cloud Function thread to process the remaining tasks, ensuring seamless execution and scalability.
26+
27+
## Customize Function Behaviors
28+
29+
All examples (e.g., `"fortinetdev/cloud-modules/google//examples/autoscale_fgt_as_hub"`) and modules (e.g., `"fortinetdev/cloud-modules/google//modules/fortigate/fgt_asg_with_function"`) that rely on the Cloud Function include an input variable `cloud_function`, which defines its behavior.
30+
31+
32+
### Cloud Functions Service
33+
34+
Cloud Functions are running service with configurable parameters defined in `cloud_function->service_config`. Every example provides default values for `cloud_function->service_config`, which are typically sufficient for its specific use case. However, you can adjust these values to better fit your needs.
35+
36+
The following parameters can be customized:
37+
- `max_instance_count` – The maximum number of function instances that can run concurrently.
38+
- `max_instance_request_concurrency` – The maximum number of concurrent requests a single Cloud Function instance can handle.
39+
- `available_cpu` – The number of CPUs allocated per function instance.
40+
- `available_memory` – The amount of memory available for each function instance.
41+
- `timeout_seconds` – The maximum execution time for the function.
42+
43+
**Example Configuration:**
44+
```hcl
45+
cloud_function = {
46+
# <other parameters...>
47+
service_config = {
48+
max_instance_count = 1 # Maximum number of concurrent function instances.
49+
max_instance_request_concurrency = 3 # Maximum concurrent requests handled per instance.
50+
available_cpu = "1" # The number of CPUs used in a single container instance.
51+
available_memory = "1G" # The amount of memory available for a function.
52+
timeout_seconds = 420 # The function execution timeout.
53+
}
54+
}
55+
```
56+
57+
### Logging
58+
59+
This project categorizes logs into five levels: `"ERROR"`, `"WARN"`, `"INFO"`, `"DEBUG"`, and `"TRACE"`.
60+
61+
**Type of Log**
62+
- `"ERROR"`: A critical issue occurred in the Cloud Function that may impact functionality.
63+
- `"WARN"`: Unexpected behavior detected, but functionality remains unaffected.
64+
- `"INFO"`: General project progress updates, such as Cloud Function execution start and completion.
65+
- `"DEBUG"`: Debugging information, which may contain sensitive data.
66+
- `"TRACE"`: Highly detailed logs, capturing all available information, including sensitive data.
67+
68+
You can view logs in the [Log Explorer](https://console.cloud.google.com/logs/query).
69+
70+
**Configuring Log Levels**
71+
72+
The logging level is controlled by the `cloud_function->logging_level` parameter.
73+
- `"NONE"`: No logs recorded.
74+
- `"ERROR"`: Logs only "ERROR" events.
75+
- `"WARN"`: Logs "WARN" and "ERROR" events.
76+
- `"INFO"`: Logs "INFO", "WARN", and "ERROR" events.
77+
- `"DEBUG"`: Logs "DEBUG", "INFO", "WARN", and ERROR events.
78+
- `"TRACE"`: Logs all events ("ERROR", "WARN", "INFO", "DEBUG", and "TRACE").
79+
80+
**Example Configuration:**
81+
```hcl
82+
cloud_function = {
83+
# <other parameters...>
84+
service_config = {
85+
logging_level = "TRACE" # Verbosity of logs. Possible values include "NONE", "ERROR", "WARN", "INFO", "DEBUG", and "TRACE". You can find logs in Google Cloud Logs Explorer.
86+
}
87+
}
88+
```
89+
90+

0 commit comments

Comments
 (0)