自动使用Terraform扩展Azure Spring应用程序的URI。

huangapple go评论56阅读模式
英文:

auto scale azure spring app URI with terraform

问题

I need enable auto scale for an spring app hosted by spring app services. I am used below terraform code.

resource "azurerm_monitor_autoscale_setting" "spring_apps_app_carrier_events" {
  name                = "default_auto_scale"
  enabled             = true
  resource_group_name = module.rg.resource_group_name
  location            = module.rg.resource_group_location
  target_resource_id  = module.spring_apps_app_carrier_events.app_identities[0].principal_id

  profile {
    name = "defaultProfile"

    capacity {
      default = 1
      minimum = 1
      maximum = 2
    }

It return errors:

Error: Can not parse "target_resource_id" as a resource id: Cannot parse Azure ID: parse "290dc6bd-1895-4e52-bac2-a34e63a138a9": invalid URI for request

It seems it need a uri. May u know how can I get the uri of a spring app?

Thanks in advance

英文:

I need enable auto scale for an spring app hosted by spring app services.I am used below terraform code.

resource "azurerm_monitor_autoscale_setting" "spring_apps_app_carrier_events" {
  name                = "default_auto_scale"
  enabled             = true
  resource_group_name = module.rg.resource_group_name
  location            = module.rg.resource_group_location
  target_resource_id  = module.spring_apps_app_carrier_events.app_identities[0].principal_id

  profile {
    name = "defaultProfile"

    capacity {
      default = 1
      minimum = 1
      maximum = 2
    }

It return errors:

Error: Can not parse "target_resource_id" as a resource id: Cannot parse Azure ID: parse "290dc6bd-1895-4e52-bac2-a34e63a138a9": invalid URI for request

It seems it need a uri. May u know how can I get the uri of a spring app?

Thanks in advance

答案1

得分: 1

I tried to reproduce the same in my environment.

Received the same error:

│ Error: Can not parse "target_resource_id" as a resource id: Cannot parse Azure ID: parse "xxxxx": invalid URI for request
│ with azurerm_monitor_autoscale_setting.spring_apps_app_carrier_events,

The target_resource_id should not be in just number id form,

It has to be something like /subscriptions/xxxxxc/resourceGroups/<myrg>/providers/Microsoft.xxx/xx/sxx

In your case,

target_resource_id = module.spring_apps_app_carrier_events.app_identities[0].principal_id

gives the principal Id which is in “23434354544466” format which is not correct.

I tried below code with targetid being, resourceId : /subscriptions/xxx/resourceGroups/ <myrg>/providers/Microsoft.AppPlatform/spring/springcloudappkavya/apps/kaexamplspringcloudapp/deployments/kavyadeploy1

Code:

resource "azurerm_spring_cloud_service" "example" {
  name                = "springcloudappkavya"
  location            = data.azurerm_resource_group.example.location
  resource_group_name = data.azurerm_resource_group.example.name
  sku_name            = "S0"

  config_server_git_setting {
    uri          = "https://github.com/Azure-Samples/piggymetrics"
    label        = "config"
    search_paths = ["dir1", "dir2"]
  }

  trace {
    connection_string = azurerm_application_insights.example.connection_string
    sample_rate       = 10.0
  }

  tags = {
    Env = "staging"
  }
}

resource "azurerm_spring_cloud_app" "example" {
  name                = "kaexamplspringcloudapp"
  resource_group_name = data.azurerm_resource_group.example.name
  service_name        = azurerm_spring_cloud_service.example.name

  identity {
    type = "SystemAssigned"
  }
}

resource "azurerm_spring_cloud_java_deployment" "test" {
  name                = "kavyadeploy1"
  spring_cloud_app_id = azurerm_spring_cloud_app.example.id
  instance_count      = 2
  jvm_options         = "-XX:+PrintGC"

  quota {
    cpu    = "2"
    memory = "4Gi"
  }

  runtime_version = "Java_11"

  environment_variables = {
    "Foo" : "Bar"
    "Env" : "Staging"
  }
}

resource "azurerm_monitor_autoscale_setting" "spring_apps_app_carrier_events" {
  name                = "default_auto_scale"
  enabled             = true
  resource_group_name = data.azurerm_resource_group.example.name
  location            = data.azurerm_resource_group.example.location
  target_resource_id  = azurerm_spring_cloud_java_deployment.test.id

 // target_resource_id  = .spring_apps_app_carrier_events.app_identities[0].principal_id
 // target_resource_id  = "18xxxxxe2"

profile {
    name = "metricRules"
    capacity {
      default = 1
      minimum = 1
      maximum = 2
    }
    rule {
      metric_trigger {
        dimensions {
          name     = "AppName"
          operator = "Equals"
          values   = [azurerm_spring_cloud_app.example.name]
        }

        dimensions {
          name     = "Deployment"
          operator = "Equals"
          values   = [azurerm_spring_cloud_java_deployment.test.name]
        }

        metric_name        = "AppCpuUsage"
        metric_namespace   = "microsoft.appplatform/spring"
        metric_resource_id = azurerm_spring_cloud_service.example.id
        time_grain         = "PT1M"
        statistic          = "Average"
        time_window        = "PT5M"
        time_aggregation   = "Average"
        operator           = "GreaterThan"
        threshold          = 75
      }
      scale_action {
        direction = "Increase"
        type      = "ChangeCount"
        value     = 1
        cooldown  = "PT1M"
      }
    }
  }
}

Could execute without errors.

Portal view of Autoscale settings for spring apps.

Reference: An Azure Spring Cloud Update: Managed Virtual Network and Autoscale are now generally available in Azure Spring Cloud

英文:

I tried to reproduce the same in my environment.

Received the same error:

│ Error: Can not parse &quot;target_resource_id&quot; as a resource id: Cannot parse Azure ID: parse &quot;xxxxx&quot;: invalid URI for request
│   with azurerm_monitor_autoscale_setting.spring_apps_app_carrier_events,

自动使用Terraform扩展Azure Spring应用程序的URI。

The target_resource_id should not be in just number id form,

It has to be something like /subscriptions/xxxxxc/resourceGroups/&lt;myrg&gt;/providers/Microsoft.xxx/xx/sxx

In your case,

target_resource_id  = module.spring_apps_app_carrier_events.app_identities[0].principal_id

gives the principal Id which is in “23434354544466” format which is not correct.

I tried below code with targetid being, resourceId : /subscriptions/xxx/resourceGroups/ &lt;myrg&gt;/providers/Microsoft.AppPlatform/spring/springcloudappkavya/apps/kaexamplspringcloudapp/deployments/kavyadeploy1

自动使用Terraform扩展Azure Spring应用程序的URI。

Code:

resource &quot;azurerm_spring_cloud_service&quot; &quot;example&quot; {
name                = &quot;springcloudappkavya&quot;
location            =data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
sku_name            = &quot;S0&quot;
config_server_git_setting {
uri          = &quot;https://github.com/Azure-Samples/piggymetrics&quot;
label        = &quot;config&quot;
search_paths = [&quot;dir1&quot;, &quot;dir2&quot;]
}
trace {
connection_string = azurerm_application_insights.example.connection_string
sample_rate       = 10.0
}
tags = {
Env = &quot;staging&quot;
}
}
resource &quot;azurerm_spring_cloud_app&quot; &quot;example&quot; {
name                = &quot;kaexamplspringcloudapp&quot;
resource_group_name = data.azurerm_resource_group.example.name
service_name        = azurerm_spring_cloud_service.example.name
identity {
type = &quot;SystemAssigned&quot;
}
}
resource &quot;azurerm_spring_cloud_java_deployment&quot; &quot;test&quot; {
name                = &quot;kavyadeploy1&quot;
spring_cloud_app_id = azurerm_spring_cloud_app.example.id
instance_count      = 2
jvm_options         = &quot;-XX:+PrintGC&quot;
quota {
cpu    = &quot;2&quot;
memory = &quot;4Gi&quot;
}
runtime_version = &quot;Java_11&quot;
environment_variables = {
&quot;Foo&quot; : &quot;Bar&quot;
&quot;Env&quot; : &quot;Staging&quot;
}
}
resource &quot;azurerm_monitor_autoscale_setting&quot; &quot;spring_apps_app_carrier_events&quot; {
name                = &quot;default_auto_scale&quot;
enabled             = true
resource_group_name = data.azurerm_resource_group.example.name
location            = data.azurerm_resource_group.example.location
target_resource_id  = azurerm_spring_cloud_java_deployment.test.id
// target_resource_id  = .spring_apps_app_carrier_events.app_identities[0].principal_id
// target_resource_id  =  &quot;18xxxxxe2&quot;
profile {
name = &quot;metricRules&quot;
capacity {
default = 1
minimum = 1
maximum = 2
}
rule {
metric_trigger {
dimensions {
name     = &quot;AppName&quot;
operator = &quot;Equals&quot;
values   = [azurerm_spring_cloud_app.example.name]
}
dimensions {
name     = &quot;Deployment&quot;
operator = &quot;Equals&quot;
values   = [azurerm_spring_cloud_java_deployment.test.name]
}
metric_name        = &quot;AppCpuUsage&quot;
metric_namespace   = &quot;microsoft.appplatform/spring&quot;
metric_resource_id = azurerm_spring_cloud_service.example.id
time_grain         = &quot;PT1M&quot;
statistic          = &quot;Average&quot;
time_window        = &quot;PT5M&quot;
time_aggregation   = &quot;Average&quot;
operator           = &quot;GreaterThan&quot;
threshold          = 75
}
scale_action {
direction = &quot;Increase&quot;
type      = &quot;ChangeCount&quot;
value     = 1
cooldown  = &quot;PT1M&quot;
}
}
}
}

Could execute without errors.

自动使用Terraform扩展Azure Spring应用程序的URI。

Portal view of Autoscale settings for spring apps.

自动使用Terraform扩展Azure Spring应用程序的URI。

Reference : An Azure Spring Cloud Update: Managed Virtual Network and Autoscale are now generally available in Azure Spring Cloud

huangapple
  • 本文由 发表于 2023年2月8日 19:44:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385329.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定