https://pulumi.com logo
#golang
Title
# golang
e

echoing-librarian-76448

06/24/2020, 7:50 PM
Hey, first time posting. I'm running into an issue when trying to create an Azure SQL Server resource in Go. When I run
pulumi preview
it gives me the following error message:
Copy code
.\main.go:153:30: undefined: mssql.ServerAzureadAdministratorPtr
.\main.go:154:4: undefined: mssql.ServerAzureadAdministratorArgs
.\main.go:161:27: undefined: mssql.NewServer
.\main.go:162:4: undefined: mssql.ServerArgs
Here's the code I'm using:
Copy code
// SQLServerInput is a struct to define required Sql Server properties
// <https://www.pulumi.com/docs/reference/pkg/azure/mssql/server/#inputs>
type SQLServerInput struct {
	AdministratorLogin         string
	AdministratorLoginPassword string
	Location                   string
	Name                       string
	ResourceGroupName          string
	Version                    string
}

// SQLServerAzureADAdministrator is a struct to define Sql Server Azure AD Administrator properties
// <https://www.pulumi.com/docs/reference/pkg/azure/mssql/server/#serverazureadadministrator>
type SQLServerAzureADAdministrator struct {
	LoginUsername string
	ObjectID      string
	TenantID      string
}    

    // Validate and load SQL Server config from Stack yaml file
    sqlServerInput := []*SQLServerInput{}
    if err := cfg.TryObject("sqlServers", &sqlServerInput); err != nil {
        return err
    }

    // Validate and load ServerAzureADAdministrator Args
    azureADAdministratorInput := []*SQLServerAzureADAdministrator{}
    if err := cfg.TryObject("azureAdAdministrator", &azureADAdministratorInput); err != nil {
        return err
    }

    // Convert ServerAzureadAdministratorArgs into ServerAzureadAdministratorPtrInput per
    // <https://pkg.go.dev/github.com/pulumi/pulumi-azure/sdk/v3@v3.9.3/go/azure/mssql?tab=doc#ServerArgs>
    azureADAdministratorArgs := mssql.ServerAzureadAdministratorPtr(
        &mssql.ServerAzureadAdministratorArgs{
            LoginUsername: pulumi.String(azureADAdministratorInput[0].LoginUsername),
            ObjectId:      pulumi.String(azureADAdministratorInput[0].ObjectID),
            TenantId:      pulumi.StringPtr(azureADAdministratorInput[0].TenantID),
        })

    // Create the SQL Server
    preprodSQLServer, err := mssql.NewServer(ctx, sqlServerInput[0].Name,
        &mssql.ServerArgs{
            Name:                       pulumi.StringPtr(sqlServerInput[0].Name),
            ResourceGroupName:          pulumi.String(sqlServerInput[0].ResourceGroupName),
            AdministratorLogin:         pulumi.String(sqlServerInput[0].AdministratorLogin),
            AdministratorLoginPassword: pulumi.String(sqlServerInput[0].AdministratorLoginPassword),
            AzureadAdministrator:       azureADAdministratorArgs,
            Location:                   pulumi.StringPtr(sqlServerInput[0].Location),
            Version:                    pulumi.String(sqlServerInput[0].Version),
            Tags:                       tags,
        })
    if err != nil {
        return err
    }
g

gentle-diamond-70147

06/24/2020, 8:21 PM
I think your
import
statements might be incorrect given the
undefined
errors. Beyond that, you shouldn't be instantiating any
*Ptr
objects. Instead you should use
ServerAzureadAdministratorArgs
directly. So your code should look like this instead:
Copy code
azureADAdministratorArgs := &mssql.ServerAzureadAdministratorArgs{
            LoginUsername: pulumi.String(azureADAdministratorInput[0].LoginUsername),
            ObjectId:      pulumi.String(azureADAdministratorInput[0].ObjectID),
            TenantId:      pulumi.StringPtr(azureADAdministratorInput[0].TenantID),
        }
e

echoing-librarian-76448

06/24/2020, 9:04 PM
Thanks for the info on instantiating
*Ptr
objects. I have some other objects from
mssql
like
mssql.NewElasticPool
that aren't giving that same error. I noticed that Azure SQL Servers were migrated to
mssql
from
sql
. Should I be using the old version? Here's my import statement:
Copy code
import (
	"<http://github.com/pulumi/pulumi-azure/sdk/v3/go/azure/dns|github.com/pulumi/pulumi-azure/sdk/v3/go/azure/dns>"
	"<http://github.com/pulumi/pulumi-azure/sdk/v3/go/azure/mssql|github.com/pulumi/pulumi-azure/sdk/v3/go/azure/mssql>"
	"<http://github.com/pulumi/pulumi/sdk/v2/go/pulumi|github.com/pulumi/pulumi/sdk/v2/go/pulumi>"
	"<http://github.com/pulumi/pulumi/sdk/v2/go/pulumi/config|github.com/pulumi/pulumi/sdk/v2/go/pulumi/config>"
)
I think I see what happened. My
go.mod
file had
v3.0.0
listed for
<http://github.com/pulumi/pulumi-azure/sdk/v3|github.com/pulumi/pulumi-azure/sdk/v3>
. I ran
go get <http://github.com/pulumi/pulumi-azure/sdk/v3|github.com/pulumi/pulumi-azure/sdk/v3>
and it's getting past that issue
Thanks for your help @gentle-diamond-70147!
g

gentle-diamond-70147

06/24/2020, 10:11 PM
You’re welcome!
3 Views