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

Unable to create user: mssql: Incorrect syntax near the keyword 'with' #7

Closed
a7i opened this issue Apr 26, 2021 · 3 comments · Fixed by #17
Closed

Unable to create user: mssql: Incorrect syntax near the keyword 'with' #7

a7i opened this issue Apr 26, 2021 · 3 comments · Fixed by #17

Comments

@a7i
Copy link

a7i commented Apr 26, 2021

I am running into issues creating a mssql_user. I had no issues with creating the mssql_login.

Resource

variable "roles" {
  default = ["db_datawriter", "db_datareader"]
}

variable "databases" {
  default = ["master"]
}

resource "mssql_user" "user" {
  server {
    host = var.database_host
    port = var.database_port
    login {
      username = var.database_admin_username
      password = var.database_admin_password
    }
  }
  for_each = toset(var.databases)
  username = mssql_login.login.login_name
  roles    = coalesce(var.roles, [])
  database = each.key
}

Plan output

  # module.sqlserver_role.mssql_user.user["master"] will be created
  + resource "mssql_user" "user" {
      + authentication_type = (known after apply)
      + database            = "master"
      + default_schema      = "dbo"
      + id                  = (known after apply)
      + principal_id        = (known after apply)
      + roles               = [
          + "db_datawriter",
          + "db_datareader",
        ]
      + username            = "testuser"

      + server {
          + host = "REDACTED.us-east-1.rds.amazonaws.com"
          + port = "1433"

          + login {
              + password = (sensitive value)
              + username = "rdsuser"
            }
        }
    }

Error:

2021/04/25 22:53:36 [DEBUG] module.sqlserver_role.mssql_user.user["master"]: apply errored, but we're indicating that via the Error pointer rather than returning it: unable to create user [master].[testuser]: mssql: Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
2021/04/25 22:53:36 [ERROR] eval: *terraform.EvalApplyPost, err: unable to create user [master].[testuser]: mssql: Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
2021/04/25 22:53:36 [ERROR] eval: *terraform.EvalSequence, err: unable to create user [master].[testuser]: mssql: Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
@a7i
Copy link
Author

a7i commented Apr 26, 2021

Looks like I'm missing login_name.

Running into another issues but seems that it's related to SQL Server 2014

@a7i a7i closed this as completed Apr 26, 2021
@dmitry-mightydevops
Copy link

have you solved it @a7i ?

@a7i
Copy link
Author

a7i commented Apr 28, 2021

Hi @dmitry-mightydevops : I ended up using another provider for 2 reasons:

  1. 2014 doesn't support [String_Split](https://github.com/betr-io/terraform-provider-mssql/blob/master/sql/user.go#L124) and I did not want to raise the compatibility level
  2. This provider doesn't offer a Database resource (i.e. create database)

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

Successfully merging a pull request may close this issue.

2 participants