Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Step 3. Prepare your Azure environment

In this step we will set up the following in Azure:

  1. Storage account for Terraform states
  2. Storage account for function app code packages
  3. Registered providers needed for various services

This section will demonstrate how to set up Azure using Terraform.

1. Prepare

Login to your Azure subscription through the CLI.

$azlogin
Follow the prompts. On success, the CLI will respond with a JSON object of the subscriptions available to you.
Make sure the subscription you want to work in is set to default. If it is not, you can run

$azaccountset--subscription<nameorid>

2. Register providers

Make sure the following providers are registered on the subscription.

$azproviderregister--namespaceMicrosoft.Web$azproviderregister--namespaceMicrosoft.KeyVault$azproviderregister--namespaceMicrosoft.Storage$azproviderregister--namespaceMicrosoft.Insights

More info

https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/error-register-resource-provider

3. Terraform configuration

Setup your Terraform configuration.

In main.tf:

terraform{required_version=">= 0.14.0"}

In modules.tf:

module"shared_infra"{source="git@github.com:labd/terraform-azure-mach-shared.git"name_prefix="mach-shared-we"  # replace 'mach' with your desired prefixregion="westeurope"dns_zone_name="example.com"certificate_access_object_ids=[... # User, group or principle IDs that should have access to the resources]}

More info about the shared infra module.

4. Apply Terraform

  1. Run the following commands:
    $terraforminit$terraformapply
  2. For a new Terraform setup, initially it will store the Terraform state locally and should be namedterraform.tfstate.
    We'll move this state to the Storage Account that has been created by the shared infra module.
    To do this, add a backend setting to project like below
    terraform{required_version=">= 0.14.0"backend"azurerm"{}}
  3. Now run:
    $terraforminit-reconfigure
    Terraform will detect that you're trying to move your state into Azure and ask; "Do you want to copy existing state to the new backend?".
    Enter"yes".
    Now the state is stored in the Storage Account.
  4. Check ifterraform.tfstate is empty and remove it

Example

See theexamples directory for an example of a Terraform setup

Manual setup

See instructions on how toset up Azure manually.


[8]ページ先頭

©2009-2025 Movatter.jp