I use terraform scripts to create azure sql server resource, scripts seems ok because I can run terraform apply successful in my local PC, but when apply it by pipeline, it always get timeout error
module.sql.azurerm_mssql_server.sql_server: Still creating... [30m10s elapsed]
2023-06-08T07:59:30.903Z [ERROR] provider.terraform-provider-azurerm_v3.58.0_x5: Response contains error diagnostic: tf_rpc=ApplyResourceChange tf_req_id=741d1c06-f641-256b-eb93-421bb15a7eb5 diagnostic_detail= diagnostic_severity=ERROR diagnostic_summary="waiting for creation/update of Server: (Name "a250621-ds-sql-server-eu2-dev" / Resource Group "eastus2-250621-datasquad"): Code="OperationTimedOut" Message="The operation timed out and automatically rolled back. Please retry the operation."" tf_proto_version=5.3 tf_provider_addr=provider @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/diag/diagnostics.go:55 @module=sdk.proto tf_resource_type=azurerm_mssql_server timestamp=2023-06-08T07:59:30.903Z
2023-06-08T07:59:30.903Z [ERROR] vertex "module.sql.azurerm_mssql_server.sql_server" error: waiting for creation/update of Server: (Name "a250621-ds-sql-server-eu2-dev" / Resource Group "eastus2-250621-datasquad"): Code="OperationTimedOut" Message="The operation timed out and automatically rolled back. Please retry the operation."
╷
│ Error: waiting for creation/update of Server: (Name "a250621-ds-sql-server-eu2-dev" / Resource Group "eastus2-250621-datasquad"): Code="OperationTimedOut" Message="The operation timed out and automatically rolled back. Please retry the operation."
│
│ with module.sql.azurerm_mssql_server.sql_server,
│ on ../modules/sql/main.tf line 8, in resource "azurerm_mssql_server" "sql_server":
│ 8: resource "azurerm_mssql_server" "sql_server" {
the terraform version is
$ terraform --version
Terraform v1.2.2
azure provider version is 3.58.0, I tried 3.59.0(the newest one, still same issue)
$ terraform init -backend-config="../tfvars/tf-backend-dev.conf"
Initializing modules...
- sql in ../modules/sql
Initializing the backend...
Successfully configured the backend "azurerm"! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing provider plugins...
- Finding hashicorp/random versions matching "~> 3.0"...
- Finding hashicorp/azurerm versions matching "3.58.0"...
- Installing hashicorp/random v3.5.1...
- Installed hashicorp/random v3.5.1 (signed by HashiCorp)
- Installing hashicorp/azurerm v3.58.0...
- Installed hashicorp/azurerm v3.58.0 (signed by HashiCorp)
but in my local running, the sql server can be created in a very shot time, always less than 2mins, could someone help on this issue?
1条答案
按热度按时间5t7ly7z51#
I created one Project in gitlab and added the Terraform files to deploy Azure SQL like below:-
I referred the terraform files from this Quickstart and just added the extra code below in providers.tf from the Quickstart:-
Added Variables like below:-
But we have also provided the service principal settings in providers.tf file as mentioned above.
Added the below code in the pipeline above:-
.gitlab-ci.yml
After the validate and plan stage, I manually started the Apply stage by clicking on it. Make sure to click on apply stage manually to start the deployment if it does not start by itself.
Output:-
I ran the pipeline again and it created another resource with unique name as the code files in the Quickstart creates a unique string for Azure SQL resources, This time the apply stage ran by itself without the need to manually start it:-
Reference:- Using GitLab To Deploy Terraform Code in Azure | by Rafael Medeiros | Medium