diff --git a/modules/cloudsql-instance/README.md b/modules/cloudsql-instance/README.md
index b1c4db15d..f6f3f0533 100644
--- a/modules/cloudsql-instance/README.md
+++ b/modules/cloudsql-instance/README.md
@@ -77,6 +77,7 @@ module "db" {
tier = "db-g1-small"
gcp_deletion_protection = false
terraform_deletion_protection = false
+ data_api_access = "ALLOW_DATA_API"
}
# tftest modules=3 resources=16 inventory=simple.yaml isolated e2e
```
@@ -413,39 +414,40 @@ module "db" {
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
-| [database_version](variables.tf#L85) | Database type and version to create. | string | ✓ | |
-| [name](variables.tf#L201) | Name of primary instance. | string | ✓ | |
-| [network_config](variables.tf#L206) | Network configuration for the instance. Only one between private_network and psc_config can be used. | object({…}) | ✓ | |
-| [project_id](variables.tf#L249) | The ID of the project where this instances will be created. | string | ✓ | |
-| [region](variables.tf#L254) | Region of the primary instance. | string | ✓ | |
-| [tier](variables.tf#L306) | The machine type to use for the instances. | string | ✓ | |
+| [database_version](variables.tf#L96) | Database type and version to create. | string | ✓ | |
+| [name](variables.tf#L212) | Name of primary instance. | string | ✓ | |
+| [network_config](variables.tf#L217) | Network configuration for the instance. Only one between private_network and psc_config can be used. | object({…}) | ✓ | |
+| [project_id](variables.tf#L260) | The ID of the project where this instances will be created. | string | ✓ | |
+| [region](variables.tf#L265) | Region of the primary instance. | string | ✓ | |
+| [tier](variables.tf#L317) | The machine type to use for the instances. | string | ✓ | |
| [activation_policy](variables.tf#L17) | This variable specifies when the instance should be active. Can be either ALWAYS, NEVER or ON_DEMAND. Default is ALWAYS. | string | | "ALWAYS" |
| [availability_type](variables.tf#L28) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | string | | "ZONAL" |
| [backup_configuration](variables.tf#L34) | Backup settings for primary instance. Set to null to leave existing GCP backup settings unmanaged. When set, all fields are managed by Terraform including disabling backups when enabled=false. | object({…}) | | null |
| [collation](variables.tf#L54) | The name of server instance collation. | string | | null |
| [connector_enforcement](variables.tf#L60) | Specifies if connections must use Cloud SQL connectors. | string | | null |
| [context](variables.tf#L66) | Context-specific interpolations. | object({…}) | | {} |
-| [data_cache](variables.tf#L78) | Enable data cache. Only used for Enterprise MYSQL and PostgreSQL. | bool | | false |
-| [databases](variables.tf#L90) | Databases to create once the primary instance is created. | list(string) | | null |
-| [disk_autoresize_limit](variables.tf#L96) | The maximum size to which storage capacity can be automatically increased. The default value is 0, which specifies that there is no limit. | number | | 0 |
-| [disk_size](variables.tf#L102) | Disk size in GB. Set to null to enable autoresize. | number | | null |
-| [disk_type](variables.tf#L108) | The type of data disk: `PD_SSD` or `PD_HDD`. | string | | "PD_SSD" |
-| [edition](variables.tf#L114) | The edition of the instance, can be ENTERPRISE or ENTERPRISE_PLUS. | string | | "ENTERPRISE" |
-| [encryption_key_name](variables.tf#L120) | The full path to the encryption key used for the CMEK disk encryption of the primary instance. | string | | null |
-| [flags](variables.tf#L126) | Map FLAG_NAME=>VALUE for database-specific tuning. | map(string) | | null |
-| [gcp_deletion_protection](variables.tf#L132) | Set Google's deletion protection attribute which applies across all surfaces (UI, API, & Terraform). | bool | | true |
-| [insights_config](variables.tf#L139) | Query Insights configuration. Defaults to null which disables Query Insights. | object({…}) | | null |
-| [labels](variables.tf#L150) | Labels to be attached to all instances. | map(string) | | null |
-| [maintenance_config](variables.tf#L156) | Set maintenance window configuration and maintenance deny period (up to 90 days). Date format: 'yyyy-mm-dd'. | object({…}) | | {} |
-| [managed_connection_pooling_config](variables.tf#L191) | Configuration for Managed Connection Pooling. NOTE: This feature is only available for PostgreSQL on Enterprise Plus edition instances. | object({…}) | | {} |
-| [password_validation_policy](variables.tf#L225) | Password validation policy configuration for instances. | object({…}) | | null |
-| [prefix](variables.tf#L239) | Optional prefix used to generate instance names. | string | | null |
-| [replicas](variables.tf#L259) | Map of NAME=> {REGION, KMS_KEY, AVAILABILITY_TYPE} for additional read replicas. Set to null to disable replica creation. | map(object({…})) | | {} |
-| [root_password](variables.tf#L270) | Root password of the Cloud SQL instance, or flag to create a random password. Required for MS SQL Server. | object({…}) | | {} |
-| [ssl](variables.tf#L284) | Setting to enable SSL, set config and certificates. | object({…}) | | {} |
-| [terraform_deletion_protection](variables.tf#L299) | Prevent terraform from deleting instances. | bool | | true |
-| [time_zone](variables.tf#L311) | The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format. | string | | null |
-| [users](variables.tf#L317) | Map of users to create in the primary instance (and replicated to other replicas). For MySQL, anything after the first `@` (if present) will be used as the user's host. Set PASSWORD to null if you want to get an autogenerated password. The user types available are: 'BUILT_IN', 'CLOUD_IAM_USER' or 'CLOUD_IAM_SERVICE_ACCOUNT'. | map(object({…})) | | {} |
+| [data_api_access](variables.tf#L78) | Access to the Cloud SQL Data API. Either `ALLOW_DATA_API` or `DISALLOW_DATA_API`. | string | | null |
+| [data_cache](variables.tf#L89) | Enable data cache. Only used for Enterprise MYSQL and PostgreSQL. | bool | | false |
+| [databases](variables.tf#L101) | Databases to create once the primary instance is created. | list(string) | | null |
+| [disk_autoresize_limit](variables.tf#L107) | The maximum size to which storage capacity can be automatically increased. The default value is 0, which specifies that there is no limit. | number | | 0 |
+| [disk_size](variables.tf#L113) | Disk size in GB. Set to null to enable autoresize. | number | | null |
+| [disk_type](variables.tf#L119) | The type of data disk: `PD_SSD` or `PD_HDD`. | string | | "PD_SSD" |
+| [edition](variables.tf#L125) | The edition of the instance, can be ENTERPRISE or ENTERPRISE_PLUS. | string | | "ENTERPRISE" |
+| [encryption_key_name](variables.tf#L131) | The full path to the encryption key used for the CMEK disk encryption of the primary instance. | string | | null |
+| [flags](variables.tf#L137) | Map FLAG_NAME=>VALUE for database-specific tuning. | map(string) | | null |
+| [gcp_deletion_protection](variables.tf#L143) | Set Google's deletion protection attribute which applies across all surfaces (UI, API, & Terraform). | bool | | true |
+| [insights_config](variables.tf#L150) | Query Insights configuration. Defaults to null which disables Query Insights. | object({…}) | | null |
+| [labels](variables.tf#L161) | Labels to be attached to all instances. | map(string) | | null |
+| [maintenance_config](variables.tf#L167) | Set maintenance window configuration and maintenance deny period (up to 90 days). Date format: 'yyyy-mm-dd'. | object({…}) | | {} |
+| [managed_connection_pooling_config](variables.tf#L202) | Configuration for Managed Connection Pooling. NOTE: This feature is only available for PostgreSQL on Enterprise Plus edition instances. | object({…}) | | {} |
+| [password_validation_policy](variables.tf#L236) | Password validation policy configuration for instances. | object({…}) | | null |
+| [prefix](variables.tf#L250) | Optional prefix used to generate instance names. | string | | null |
+| [replicas](variables.tf#L270) | Map of NAME=> {REGION, KMS_KEY, AVAILABILITY_TYPE} for additional read replicas. Set to null to disable replica creation. | map(object({…})) | | {} |
+| [root_password](variables.tf#L281) | Root password of the Cloud SQL instance, or flag to create a random password. Required for MS SQL Server. | object({…}) | | {} |
+| [ssl](variables.tf#L295) | Setting to enable SSL, set config and certificates. | object({…}) | | {} |
+| [terraform_deletion_protection](variables.tf#L310) | Prevent terraform from deleting instances. | bool | | true |
+| [time_zone](variables.tf#L322) | The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format. | string | | null |
+| [users](variables.tf#L328) | Map of users to create in the primary instance (and replicated to other replicas). For MySQL, anything after the first `@` (if present) will be used as the user's host. Set PASSWORD to null if you want to get an autogenerated password. The user types available are: 'BUILT_IN', 'CLOUD_IAM_USER' or 'CLOUD_IAM_SERVICE_ACCOUNT'. | map(object({…})) | | {} |
## Outputs
diff --git a/modules/cloudsql-instance/main.tf b/modules/cloudsql-instance/main.tf
index f3bd8e6b4..e8bef40c1 100644
--- a/modules/cloudsql-instance/main.tf
+++ b/modules/cloudsql-instance/main.tf
@@ -83,6 +83,7 @@ resource "google_sql_database_instance" "primary" {
activation_policy = var.activation_policy
collation = var.collation
connector_enforcement = var.connector_enforcement
+ data_api_access = var.data_api_access
time_zone = var.time_zone
retain_backups_on_delete = try(var.backup_configuration.retain_backups_on_delete, null)
diff --git a/modules/cloudsql-instance/variables.tf b/modules/cloudsql-instance/variables.tf
index 64a1cd33e..ed507a930 100644
--- a/modules/cloudsql-instance/variables.tf
+++ b/modules/cloudsql-instance/variables.tf
@@ -75,6 +75,17 @@ variable "context" {
nullable = false
}
+variable "data_api_access" {
+ description = "Access to the Cloud SQL Data API. Either `ALLOW_DATA_API` or `DISALLOW_DATA_API`."
+ type = string
+ default = null
+ nullable = true
+ validation {
+ condition = var.data_api_access == null || contains(["ALLOW_DATA_API", "DISALLOW_DATA_API"], var.data_api_access)
+ error_message = "The data_api_access must be one of 'ALLOW_DATA_API' or 'DISALLOW_DATA_API'."
+ }
+}
+
variable "data_cache" {
description = "Enable data cache. Only used for Enterprise MYSQL and PostgreSQL."
type = bool
diff --git a/tests/modules/cloudsql_instance/examples/simple.yaml b/tests/modules/cloudsql_instance/examples/simple.yaml
index 9d7e2039e..12fe29672 100644
--- a/tests/modules/cloudsql_instance/examples/simple.yaml
+++ b/tests/modules/cloudsql_instance/examples/simple.yaml
@@ -28,6 +28,7 @@ values:
advanced_machine_features: []
availability_type: ZONAL
collation: null
+ data_api_access: "ALLOW_DATA_API"
database_flags: []
deletion_protection_enabled: false
deny_maintenance_period: []