hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.5k stars 4.59k forks source link

Support ICP_Number field for azurerm_cdn_endpoint china deployment #5193

Open pjeannet-dior opened 4 years ago

pjeannet-dior commented 4 years ago

Community Note

Description

When deploying CDN in china region, and creating endpoints, we are asked for the ICP number (https://en.wikipedia.org/wiki/ICP_license). I could not find it in the current terraform config.

image

New or Affected Resource(s)

Potential Terraform Configuration

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.

References

romeomorcia-wipro commented 3 years ago

Hello, any news regarding this?

favoretti commented 3 years ago

Since this issue has been reported a long time ago and relates to the version of provider we no longer support - I'm going to close it. Please open a new updated bug report on current versions of terraform and provider if this is still relevant. Thank you.

romeomorcia-wipro commented 2 years ago

@favoretti this is not correct, there is no version of azurerm_cdn_endpoint written in any part of the issue. Could you please reopen the issue and extend the functionalities to allow icp license?

favoretti commented 2 years ago

Reopened as requested.

Izual750 commented 2 years ago

Hey there, maybe it can help (even if it's a bit late :D ), but you "can" deploy a CDN endpoint with ICP like below:

I/ First, create a Terraform template file containing your parameters json:

-> _templates/cdn_endpointparameters.json.tftpl

{
  "name": {
    "value": "${parameters_name_value}"
  },
  "location": {
    "value": "${parameters_location_value}"
  },
  "properties": {
    "value": {
      "originHostHeader": "${parameters_properties_value_originHostHeader}",
      "optimizationType": "${parameters_properties_value_optimizationType}",
      "origins": [
        {
          "name": "${parameters_properties_value_origins_name}",
          "properties": {
            "hostName": "${parameters_properties_value_origins_properties}"
          }
        }
      ],
      "customdomains": [
        {
          "name": "${parameters_properties_value_customdomains_name}",
          "properties": {
            "hostName": "${parameters_properties_value_customdomains_properties_hostName}",
            "validationData": "${parameters_properties_value_customdomains_properties_validationData}"
          }
        }
      ]
    }
  }
}

II/ Create a static json file containing your endpoint in Azure template deployment format:

-> _files/cdn_endpointtemplate.json

{
    "$schema": "http://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "properties": {
            "type": "object"
        }
    },
    "resources": [
        {
            "apiVersion": "2017-04-02",
            "name": "[parameters('name')]",
            "location": "[parameters('location')]",
            "properties": "[parameters('properties')]",
            "type": "microsoft.cdn/profiles/endpoints"
        }
    ]
}

III/ On a .tf file, create azurerm_resource_group_template_deployment resource

-> _cdnendpoint.tf

resource "azurerm_resource_group_template_deployment" "customer-cn-website-cdn-endpoint" {
  name                = "customer-cn-website-cdn-endpoint"
  resource_group_name = azurerm_resource_group.customer-cn-website.name
  deployment_mode     = "Incremental"
  template_content    = file("${path.module}/files/cdn_endpoint_template.json")
  parameters_content = templatefile("${path.module}/templates/cdn_endpoint_parameters.json.tftpl",
    {
      parameters_name_value                                               = "customer-cn-website/${replace(var.cdn_customdomains, ".", "-")}",
      parameters_location_value                                           = "ChinaNorth",
      parameters_properties_value_originHostHeader                        = azurerm_storage_account.customer-cn-website.primary_blob_host,
      parameters_properties_value_optimizationType                        = var.cdn_type,
      parameters_properties_value_origins_name                            = replace(azurerm_storage_account.customer-cn-website.primary_blob_host, ".", "-"),
      parameters_properties_value_origins_properties                      = azurerm_storage_account.customer-cn-website.primary_blob_host,
      parameters_properties_value_customdomains_name                      = replace(var.cdn_customdomains, ".", "-"),
      parameters_properties_value_customdomains_properties_hostName       = var.cdn_customdomains,
      parameters_properties_value_customdomains_properties_validationData = var.cdn_icp
  })
}

IV/ On the same or another .tf file, create the needed variable:

-> vars.tf

variable "cloud_environment" {
  type    = string
  default = "china"
}

variable "cdn_customdomains" {
  type    = string
  default = "www.customer.sh.cn"
}

variable "cdn_icp" {
  type    = string
  default = "沪ICP备20002487号-2"
}

variable "cdn_type" {
  type    = string
  default = "Web"
}

It tooks around 6 minutes to validate the endpoint deployment: deployment

But in the end, the endpoint with ICP is properly deployed on Azure console ! cdnendpoint