1

I encounter the error when I deploy Traffic manager. It might be very basic configuration. However, it says Unknow service error I have no clue to fix this.

Terraform Version

Terraform v0.10.0

# Service Principle

variable "subscription_id" {}

variable "client_id" {}

variable "client_secret" {}        

variable "tenant_id" {}    

Resource Group

variable "resource_group" {}

variable "location" {}

variable "environment" {}

Actual script

  # Service Principle
    provider "azurerm" {
      subscription_id = "${var.subscription_id}"
      client_id       = "${var.client_id}"
      client_secret   = "${var.client_secret}"
      tenant_id       = "${var.tenant_id}"
    }

    # Traffic Manager Profile

    resource "azurerm_traffic_manager_profile" "profile" {
  name                   = "trafficmanagerprofile"
  resource_group_name    = "production"
  traffic_routing_method = "Weighted"

  dns_config {
    relative_name = "production"
    ttl           = 30
  }

  monitor_config {
    protocol = "http"
    port     = 80
    path     = "/"
  }
}

resource "azurerm_public_ip" "pip" {
  name                         = "ip${count.index}"
  location                     = "${var.azure_region}"
  resource_group_name          = "production"
  public_ip_address_allocation = "dynamic"
  domain_name_label            = "${var.dns_name}${count.index}"
  count                        = "${var.num_vms}"
}

resource "azurerm_traffic_manager_endpoint" "endpoint" {
  name                = "endpoint${count.index}"
  resource_group_name = "production"
  profile_name        = "${azurerm_traffic_manager_profile.profile.name}"
  target_resource_id  = "${element(azurerm_public_ip.pip.*.id, count.index)}"
  type                = "azureEndpoints"
  weight              = 1
  count               = "${var.num_vms}"
}

Debug Output

Error: autorest/azure: Service returned an error. Status=400 Code="Unknown" Message="Unknown service error"

Expected Behavior

It should be create a Traffic Manager Profile instance on Azure

Actual Behavior

Resource Group created but traffic manager profile throws error.

I am struggling with this from long time can anybody help me out here?
Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
Bhushan Gholave
  • 157
  • 2
  • 9

1 Answers1

0

Please use the following script, it works for me.

  resource "azurerm_traffic_manager_profile" "profile" {
  name                   = "trafficmanagerprofile"
  resource_group_name    = "shuioracle"
  traffic_routing_method = "Weighted"

  dns_config {
    relative_name = "shuioracle"
    ttl           = 30
  }

  monitor_config {
    protocol = "http"
    port     = 80
    path     = "/"
  }
}

resource "azurerm_public_ip" "pip" {
  name                         = "ip${count.index}"
  location                     = "South Central US"
  resource_group_name          = "shuioracle"
  public_ip_address_allocation = "static"
  domain_name_label            = "shuilinux5${count.index}"
  count                        = "3"
}

resource "azurerm_traffic_manager_endpoint" "endpoint" {
  name                = "endpoint${count.index}"
  resource_group_name = "shuioracle"
  profile_name        = "${azurerm_traffic_manager_profile.profile.name}"
  target_resource_id  = "${element(azurerm_public_ip.pip.*.id, count.index)}"
  type                = "azureEndpoints"
  weight              = 1
  count               = "3"
}

In you script , modify public_ip_address_allocation = "dynamic" to static.

Use static, then your script will success. When you create public IP, if you use dynamic, it will not associate IP address, if you use static, it will associate IP.

You could check this example and this example.

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
  • I am using the azurerm_traffic_manager_endpoint and traffic manager profile together still getting the same error:( are you able to run on your lab successfully – Bhushan Gholave Oct 31 '17 at 06:06
  • @BhushanGholave I test your script on my lab, I get same error log with you. Now, I will test add `azurerm_traffic_manager_endpoint `. Could you share you full script? – Shui shengbao Oct 31 '17 at 06:10
  • no Sir its still dosen't work after adding azurerm_traffic_manager_endpoint and also i have updated my script in question as well. – Bhushan Gholave Oct 31 '17 at 13:23
  • Hey @Walter Thanks for the reply but this is not what I am trying. Consider I have created VM,Vnet,Subnet,Security group, NICs etc in different module, Here I just want to add traffic manager profile with endpoint using existing resource group,vnet and my example shows public ip's created with traffic manager profile and endpoint. But error persist. – Bhushan Gholave Nov 01 '17 at 05:20
  • Do you mean you have create VM, and want to add your VMs to new traffic manager? I will test it. – Shui shengbao Nov 01 '17 at 05:26
  • @BhushanGholave I test in my lab, if you use static public IP, I test in my lab, your script works for me. – Shui shengbao Nov 01 '17 at 05:57
  • @BhushanGholave This is my [tf file](https://gist.githubusercontent.com/Walter-Shui/7537ea7282220cf4494382313391b41a/raw/a04d02f4dca2d6716e13629e9969342d3ecd2690/trafficmanager.tf), it works for me. – Shui shengbao Nov 01 '17 at 06:00
  • @BhushanGholave Does it work for you? If it does not work, could you `export TF_LOG=DEBUG` check more detailed log. I think it should work for you. – Shui shengbao Nov 01 '17 at 06:28
  • Hey @Walter thanks for trying out this for me. Your script works for me as well if I try creating static public ip on existing rg. But why it dosen't work for the dynamic one. Error should describe us whats wrong with the script. I am trying different things to get root cause for this. – Bhushan Gholave Nov 01 '17 at 06:41
  • @BhushanGholave If you just use your script, dynamic public IP is not associated, it does not have IP address, it could not add to traffic manager. – Shui shengbao Nov 01 '17 at 06:44
  • @BhushanGholave It is yes, terraform does not give enough error log. If you check this [example](https://github.com/terraform-providers/terraform-provider-azurerm/blob/master/examples/traffic-manager-vm/main.tf). The example uses dynamic public IP but it associated to VM. Also, when VM is created successful and public IP have IP address it could add to traffic manager. – Shui shengbao Nov 01 '17 at 06:46
  • 1
    Please update your answer with your script and I will mark it as answer. It might be helpful for others like me. I am trying something related to this dynamic and static public ip addresses. will post comment on this. – Bhushan Gholave Nov 01 '17 at 07:17
  • @BhushanGholave Yes, you are right, I update my answer. you could check it. – Shui shengbao Nov 01 '17 at 07:21
  • try using resource group and location in your script as variable. It fails for me. – Bhushan Gholave Nov 01 '17 at 08:24