Quickstart: Create an Azure confidential ledger using Terraform
Статия
In this quickstart, you create an Azure resource group and a confidential ledger using Terraform. Azure confidential ledger is a fully managed service that provides a tamper-proof register for storing sensitive data. It's built on Azure confidential computing, which uses hardware-based trusted execution environments to protect data from threats even when it's in use. This ledger is designed to maintain the confidentiality and integrity of the data it stores, making it ideal for use cases that require high levels of data protection. The resources created in this script include the Azure confidential ledger and an Azure resource group.
Terraform enables the definition, preview, and deployment of cloud infrastructure. Using Terraform, you create configuration files using HCL syntax. The HCL syntax allows you to specify the cloud provider - such as Azure - and the elements that make up your cloud infrastructure. After you create your configuration files, you create an execution plan that allows you to preview your infrastructure changes before they're deployed. Once you verify the changes, you apply the execution plan to deploy the infrastructure.
Generate a random pet name for the resource group.
Create an Azure resource group with the generated name.
Retrieve the current Azure client configuration.
Generate a random string for the Azure confidential ledger name.
Create an Azure confidential ledger with the generated name and assign it to the resource group.
Assign an Azure AD based service principal to the confidential ledger.
Tag the confidential ledger as an example.
Output the resource group name, confidential ledger name, confidential ledger type, and confidential ledger role name.
Specify the required version of Terraform and the required providers.
Define the Azure provider with no additional features.
Define variables for the resource group name prefix, resource group location, confidential ledger name, confidential ledger type, and confidential ledger role name.
Create a file named outputs.tf, and insert the following code:
Terraform
output"resource_group_name" {
value = azurerm_resource_group.rg.name
}
output"confidential_ledger_name" {
value = azurerm_confidential_ledger.example.name
}
output"confidential_ledger_type" {
value = azurerm_confidential_ledger.example.ledger_type
}
output"confidential_ledger_role_name" {
value = azurerm_confidential_ledger.example.azuread_based_service_principal[0].ledger_role_name
}
Create a file named providers.tf, and insert the following code:
Terraform
terraform {
required_version = ">=1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}
provider"azurerm" {
features {}
}
Create a file named variables.tf, and insert the following code:
Terraform
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"resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}
variable"confidential_ledger_name" {
type = string
description = "The name of the confidential ledger resource. The value will be randomly generated if blank."
default = ""
}
variable"confidential_ledger_type" {
type = string
default = "Public"
validation {
condition = contains(["Public", "Private"], var.confidential_ledger_type)
error_message = "The confidential ledger type value must be one of the following: Public, Private."
}
description = "Type of the confidential ledger."
}
variable"confidential_ledger_role_name" {
type = string
default = "Administrator"
description = "Role name for the confidential ledger."
}
Initialize Terraform
Run terraform init to initialize the Terraform deployment. This command downloads the Azure provider required to manage your Azure resources.
Console
terraform init -upgrade
Key points:
The -upgrade parameter upgrades the necessary provider plugins to the newest version that complies with the configuration's version constraints.
The terraform plan command creates an execution plan, but doesn't execute it. Instead, it determines what actions are necessary to create the configuration specified in your configuration files. This pattern allows you to verify whether the execution plan matches your expectations before making any changes to actual resources.
The optional -out parameter allows you to specify an output file for the plan. Using the -out parameter ensures that the plan you reviewed is exactly what is applied.
Apply a Terraform execution plan
Run terraform apply to apply the execution plan to your cloud infrastructure.
Console
terraform apply main.tfplan
Key points:
The example terraform apply command assumes you previously ran terraform plan -out main.tfplan.
If you specified a different filename for the -out parameter, use that same filename in the call to terraform apply.
If you didn't use the -out parameter, call terraform apply without any parameters.
The terraform plan command creates an execution plan, but doesn't execute it. Instead, it determines what actions are necessary to create the configuration specified in your configuration files. This pattern allows you to verify whether the execution plan matches your expectations before making any changes to actual resources.
The optional -out parameter allows you to specify an output file for the plan. Using the -out parameter ensures that the plan you reviewed is exactly what is applied.