Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mssql_script fails when GO statement is used #117

Open
ibuiltthis opened this issue Mar 1, 2023 · 2 comments
Open

mssql_script fails when GO statement is used #117

ibuiltthis opened this issue Mar 1, 2023 · 2 comments

Comments

@ibuiltthis
Copy link

When creating a mssql_script resource that uses 'GO' in the script the resource fails to create.

The error is:

mssql_script.ecamap_setup: Creating...
╷
│ Error: Failed to execute SQL script
│
│   with mssql_script.ecamap_setup,
│   on 05_sql_database_setup.tf line 62, in resource "mssql_script" "setup":
│   62: resource "mssql_script" "setup" {
│
│ mssql: Incorrect syntax near 'GO'.
╵

Any help?

@4iter4life
Copy link

4iter4life commented Mar 29, 2023

same here. I can confirm this behavior

tf plan to reproduce:

  + resource "mssql_script" "this" {
      + database_id   = "1"
      + delete_script = "ALTER DATABASE [lock] SET CHANGE_TRACKING = OFF"
      + id            = (known after apply)
      + read_script   = "SELECT COUNT(*) AS [is_enabled] FROM sys.change_tracking_databases WHERE database_id=8"
      + state         = {
          + "is_enabled" = "1"
        }
      + update_script = <<-EOT
            USE MASTER;
            
            DECLARE @database_name VARCHAR(256)
            DECLARE @sql_cmd VARCHAR(2000)
            
            SET @database_name = 'TEST'
            SET @sql_cmd = '
            CREATE DATABASE ' + @database_name + ' COLLATE Latin1_General_CI_AS
            '
            EXEC (@sql_cmd)
            GO
        EOT
    }

output:

│  203: resource "mssql_script" "this" {
│ 
│ mssql: Incorrect syntax near 'GO'.

@pregress
Copy link

GO is a batch separator and is not part of T-SQL, and is only interpreted by SSMS or other tools.
https://learn.microsoft.com/en-us/sql/t-sql/language-elements/sql-server-utilities-statements-go?view=sql-server-ver16&redirectedfrom=MSDN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants