訓練
認證
Microsoft Certified: Azure Database Administrator Associate - Certifications
使用 Microsoft PaaS 關聯式資料庫供應項目管理用於雲端、內部部署和混合關聯式資料庫的 SQL Server 資料庫基礎結構。
本文說明如何使用 Terraform 建立 Azure Analysis Services 伺服器。
在本文中,您將學會如何:
注意
本文中的範例程式碼位於 Azure Terraform GitHub 存放庫 (英文)。 您可以檢視記錄檔,內含目前和舊版 Terraform 的測試結果 (英文)。
建立目錄,然後在目錄中測試並執行範例 Terraform 程式碼,且設為目前的目錄。
建立名為 main.tf
的檔案,並插入下列程式碼:
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}
resource "azurerm_resource_group" "rg" {
name = random_pet.rg_name.id
location = var.resource_group_location
}
resource "random_string" "azurerm_analysis_services_server_name" {
length = 25
upper = false
numeric = false
special = false
}
resource "azurerm_analysis_services_server" "server" {
name = random_string.azurerm_analysis_services_server_name.result
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
sku = var.sku
backup_blob_container_uri = var.backup_blob_container_uri
ipv4_firewall_rule {
name = "AllowFromAll"
range_start = "0.0.0.0"
range_end = "255.255.255.255"
}
}
建立名為 outputs.tf
的檔案,並插入下列程式碼:
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "analysis_services_server_name" {
value = azurerm_analysis_services_server.server.name
}
建立名為 providers.tf
的檔案,並插入下列程式碼:
terraform {
required_version = ">=0.12"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}
provider "azurerm" {
features {}
}
建立名為 variables.tf
的檔案,並插入下列程式碼:
variable "resource_group_location" {
type = string
default = "eastus"
description = "Location for all resources."
}
variable "resource_group_name_prefix" {
type = string
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}
variable "sku" {
type = string
description = "The sku name of the Azure Analysis Services server to create. Choose from: B1, B2, D1, S0, S1, S2, S3, S4, S8, S9. Some skus are region specific. See https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-overview#availability-by-region"
default = "S0"
}
variable "backup_blob_container_uri" {
type = string
description = "The SAS URI to a private Azure Blob Storage container with read, write and list permissions. Required only if you intend to use the backup/restore functionality. See https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-backup"
default = null
}
執行 terraform init 來初始化 Terraform 部署。 此命令會下載管理 Azure 資源所需的 Azure 提供者。
terraform init -upgrade
重點︰
-upgrade
參數會將必要的提供者外掛程式升級至符合設定版本條件約束的最新版本。執行 terraform plan 以建立執行計畫。
terraform plan -out main.tfplan
重點︰
terraform plan
命令會建立執行計畫,但不會執行。 相反地,其會決定要在您指定的設定檔中建立設定所需的動作。 此模式可讓您在對實際資源進行任何變更之前,先確認執行方案是否符合您的預期。-out
參數可讓您指定計畫的輸出檔。 使用 -out
參數可確保您所檢閱的方案就是所套用的方案。執行 terraform apply 將執行計畫套用至您的雲端基礎結構。
terraform apply main.tfplan
重點︰
terraform apply
命令會假設您先前已執行 terraform plan -out main.tfplan
。-out
參數指定了不同的檔案名稱,請在呼叫 terraform apply
時使用該檔案名稱。-out
參數,請呼叫 terraform apply
,不需要使用參數。開啟 PowerShell 命令提示字元。
取得 Azure 資源群組名稱。
$resource_group_name=$(terraform output -raw resource_group_name)
取得伺服器名稱。
$analysis_services_server_name=$(terraform output -raw analysis_services_server_name)
執行 Get-AzAnalysisServicesServer 以顯示新伺服器的相關信息。
Get-AzAnalysisServicesServer -ResourceGroupName $resource_group_name `
-Name $analysis_services_server_name
當您不再需要透過 Terraform 建立的資源時,請執行下列步驟:
執行 terraform plan 並指定 destroy
旗標。
terraform plan -destroy -out main.destroy.tfplan
重點︰
terraform plan
命令會建立執行計畫,但不會執行。 相反地,其會決定要在您指定的設定檔中建立設定所需的動作。 此模式可讓您在對實際資源進行任何變更之前,先確認執行方案是否符合您的預期。-out
參數可讓您指定計畫的輸出檔。 使用 -out
參數可確保您所檢閱的方案就是所套用的方案。執行 terraform apply 以套用執行方案。
terraform apply main.destroy.tfplan
訓練
認證
Microsoft Certified: Azure Database Administrator Associate - Certifications
使用 Microsoft PaaS 關聯式資料庫供應項目管理用於雲端、內部部署和混合關聯式資料庫的 SQL Server 資料庫基礎結構。