Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
After installing the Google Cloud CLI, initialize it by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloudinit
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
After installing the Google Cloud CLI, initialize it by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
To create a SQL Server instance, specify the image family for the specific version of SQL Server that you need. For a list of the SQL Server image families, see Operating system details.
For optimal performance, database server platforms require machine types with more virtual CPUs and larger amounts of memory. Google recommends that you use machine types with at least 2 vCPUs and at least 4 GB of memory when you run SQL Server instances. You can use custom machine types to configure SQL Server instances to match the performance requirements for your workload. Additionally, you can use larger persistent disks and faster SSD persistent disks to improve the performance of your applications.
Additionally, you must set specific firewall rules to allow SQL Server traffic on the VPC network or subnet that your VM is a part of. For more information see Best practices for SQL Server.
To create a SQL Server instance, follow these steps:
In the Google Cloud console, go to the Create an instance page.
Specify the VM details.
In the Boot disk section, click Change, and then do the following:
Click Create.
After you create the VM, create a firewall rule to allow access to SQL Server on your VM. The default SQL Server port is 1433.
In the Google Cloud console, go to the Firewall Rules page.
At the top of the page, click Create firewall rule to start creating a firewall rule.
Specify the details for this firewall rule.
1433
, which is the default port.Click Create to create this firewall rule and allow access to your SQL Server instance over port 1433.
If you need to add additional firewall rules to your VM, see the firewall rules documentation.
Use the compute images list
command to see a list of available SQL Server images:
gcloud compute images list --project windows-sql-cloud --no-standard-images
Use the compute instances create
command to create a new VM and specify the image family for one of the Windows Server or SQL Server public images.
gcloud compute instances create VM_NAME \ --image-project windows-sql-cloud \ --image-family IMAGE_FAMILY \ --machine-type MACHINE_TYPE \ --boot-disk-size BOOT_DISK_SIZE \ --boot-disk-type BOOT_DISK_TYPE
Replace the following:
pd-balanced
.After you create the VM, create a firewall rule to allow access to SQL Server on your VM. The default SQL Server port is 1433.
gcloud compute firewall-rules create sql-server-1433 \ --description "Allow SQL Server access from all sources on port 1433." \ --allow tcp:1433 --network NETWORK
where NETWORK is the name of the VPC network where your VM is located.
If you need to add additional firewall rules to your VM, see the firewall rules documentation.
To create the SQL Server VM instances, use the google_compute_instance
resource.
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
To create a VM with the API, include the initializeParams
property in your VM creation request and specify a Windows image.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances instance = { "name": "VM_NAME", "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE", "disks": [{ "boot": "true", "type": "PERSISTENT", "initializeParams": { "diskName": "DISK_NAME", "sourceImage": "projects/IMAGE_PROJECT/global/images/family/IMAGE_FAMILY", "diskSizeGb": "BOOT_DISK_SIZE", "diskType": "BOOT_DISK_TYPE", } }], "networkInterfaces": [{ "accessConfigs": [{ "type": "ONE_TO_ONE_NAT", "name": "External NAT" }], "network": "global/networks/default" }], "serviceAccounts": [{ "email": DEFAULT_SERVICE_EMAIL, "scopes": DEFAULT_SCOPES }] }
Replace the following:
windows-cloud
for Windows Server images or windows-sql-cloud
for Windows Server images with SQL Server preinstalled.pd-ssd
.After you create the VM, use the firewalls.insert
method to create a firewall rule that allows access to SQL Server on your VM. The default SQL Server port is 1433
.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/firewalls { "name": "sql-server-1433", "network": "global/networks/NETWORK", "allowed": [ { "IPProtocol": "tcp", "ports": [ "1433" ] } ] }
Replace the following:
After you create your SQL Server instance, set the initial password for the VM so that you can connect to the VM through RDP. Then, run the SQL Server Management Studio as an administrator to manage databases on your SQL Server instance.
Additionally, you can enhance the SQL Server installation with one or more of the following items:
c:\sql_server_install\setup.exe
.c:\sql_server_install\setup.exe
installer and select a new installation path on your secondary disk.Run the SQL Server Management Studio as an administrator to configure SQL Server databases. You can download and install the SQL Server Management Studio on your local workstation, and use it to remotely connect to the database engine on your VM.
If you can't install the Management Studio on your local workstation, connect to the VM through RDP and run the Management Studio on the VM itself. SQL Server 2012 and SQL Server 2014 both include the SQL Server Management Studio by default. For SQL Server 2016, you must download the SQL Server Management Studio from the Microsoft website and install it on the VM.
By default, SQL Server uses Windows Authentication mode to control remote access to SQL Server itself. If you need to use SQL Server Authentication mode, change the authentication mode.
If you rename a VM that hosts SQL Server, you must update the SQL Server instance name. For more information, see Rename a computer that hosts a stand-alone instance of SQL Server.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-22 UTC.