0

I am creating a static web app via terraform, but I cannot reproduce the same result as I get when I create it manually via portal azure.

I want to connect my static web app to an azure DevOps project:

enter image description here

From the documentation is not clear how to do:

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/static_web_app

Can anyone help me please?

Thank you

EDIT:

That is how I create the static web app:

resource "azurerm_static_web_app" "admin_crm_app" {
  name                         = "${var.env_prefix}-crm-stapp-westeu"
  resource_group_name          = azurerm_resource_group.admin_rg.name
  location                     = azurerm_service_plan.admin_plan.location
  sku_tier                     = "Free"
  sku_size                     = "Free"

  preview_environments_enabled = false

  app_settings = {
    WEBSITE_TIME_ZONE                          = "Europe/Rome"
    ASPNETCORE_ENVIRONMENT                     = "${var.env}"
   # WEBSITE_WEBDEPLOY_USE_SCM                  = false

    APPINSIGHTS_INSTRUMENTATIONKEY             =  azurerm_application_insights.admin_appi.instrumentation_key
    APPLICATIONINSIGHTS_CONNECTION_STRING      =  azurerm_application_insights.admin_appi.connection_string
    ApplicationInsightsAgent_EXTENSION_VERSION = "~3"
  }

  tags = {
    Source = "${var.iac}"
  }
}

Here the template that has been generate when I create the static web app manually on portal azure:

enter image description here

That are properties that have been generate from terraform instead:

enter image description here

4
  • Have you tried any code so far? @Simone Commented May 15, 2024 at 11:34
  • @Jahnavi yes, sure... I added the code I am using... It is not much more different from the example in the documentation... I do not what I can use... I have also seen the template generated when I create the static web app manually on portal azure... but I do not understand how I can replicate it on terraform Commented May 16, 2024 at 9:43
  • To replicate it with Devops you are saying? @Simone Commented May 17, 2024 at 6:06
  • 1
    @Jahnavi I mean that I want to replicate on Terraform what I did via portal azure. On portal Azure I "connect" the static web app to a repositoy and a branch on DevOps. But I do not understand how to do the same with terraform. The first image I attached on the post is on Portal Azure, not on DevOps Commented May 17, 2024 at 14:39

1 Answer 1

1

Currently there is no argument available to add repositoryurl or other properties in azurerm_static_web_app.

If you want to use Terraform to perform action then you can use azurerm_resource_group_template_deployment to deploy a static website using ARM template.

This worked for me and I was able to deploy static website with source as AzureDevOps.

terraform {
  required_providers {
    azurerm ={
      source = "hashicorp/azurerm"
      version = "3.104.0"
    }
  }
}

provider "azurerm" {
  features {
    
  }
}


resource "azurerm_resource_group_template_deployment" "example" {
  name                = "acctesttemplate-01"
resource_group_name = "vshandilya"

  template_content = <<DEPLOY
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "name": {
        "type": "string"
    },
    "location": {
        "type": "string"
    },
    "sku": {
        "type": "string"
    },
    "skucode": {
        "type": "string"
    },
    "repositoryUrl": {
        "type": "string"
    },
    "branch": {
        "type": "string"
    },
    "repositoryToken": {
        "type": "string"
    },
    "appLocation": {
        "type": "string"
    },
    "apiLocation": {
        "type": "string"
    },
    "appArtifactLocation": {
        "type": "string"
    },
    "areStaticSitesDistributedBackendsEnabled": {
        "type": "bool"
    }
  },
  "resources": [
        {
            "apiVersion": "2022-09-01",
            "name": "[parameters('name')]",
            "type": "Microsoft.Web/staticSites",
            "location": "[parameters('location')]",
            "tags": {},
            "properties": {
                "repositoryUrl": "[parameters('repositoryUrl')]",
                "branch": "[parameters('branch')]",
                "repositoryToken": "[parameters('repositoryToken')]",
                "buildProperties": {
                    "appLocation": "[parameters('appLocation')]",
                    "apiLocation": "[parameters('apiLocation')]",
                    "appArtifactLocation": "[parameters('appArtifactLocation')]"
                },
                "areStaticSitesDistributedBackendsEnabled": "[parameters('areStaticSitesDistributedBackendsEnabled')]"
            },
            "sku": {
                "Tier": "[parameters('sku')]",
                "Name": "[parameters('skuCode')]"
            }
        }
    ]
} 
DEPLOY


  # these key-value pairs are passed into the ARM Template's `parameters` block
  parameters_content = jsonencode({
    "name"= {
        value = "terra-arm"
    },
    "location"= {
        value= "eastus2"
    },
    "sku"= {
        value= "Free"
    },
    "skucode"= {
        value= "Free"
    },
    "repositoryUrl"= {
        value= "https://dev.azure.com/xxxxxxxxxx/xxxxxx/_git/xxxxxx"
    },
    "branch"= {
        value= "main"
    },
    "repositoryToken"= {
        value= "xxxxxxxxxxxxxxxxxxx"
    },
    "appLocation"= {
        value= "/"
    },
    "apiLocation"= {
        value= ""
    },
    "appArtifactLocation"= {
        value= "build"
    },
    "areStaticSitesDistributedBackendsEnabled"= {
        value= false
    }
  })

  deployment_mode = "Incremental"
}

output "staticDevops" {
  value = azurerm_resource_group_template_deployment.example.output_content
}

OUTPUT:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.