Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timeframe attribute from azurerm_subscription_cost_management_view does not work properly #22933

Open
1 task done
JoelCanteroGCO opened this issue Aug 14, 2023 · 6 comments
Open
1 task done

Comments

@JoelCanteroGCO
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

I have the following code to create a subscription cost management view:
`resource "azurerm_subscription_cost_management_view" "subscription_cost_management_view" {
name = "costview-${var.subscription_name}"
display_name = "costview-${var.subscription_name}"
chart_type = "StackedColumn"
accumulated = false

subscription_id = "/subscriptions/${var.subscription_id}"

report_type = "Usage"
timeframe = "YearToDate"

dataset {
granularity = "Monthly"

aggregation {
  name        = "totalCost"
  column_name = "Cost"
}

}
pivot {
name = "ResourceId"
type = "Dimension"
}

pivot {
name = "ResourceGroupName"
type = "Dimension"
}

pivot {
name = "ServiceName"
type = "Dimension"
}
}`

But when I go to this view, the timeframe is not YearToDate:

image

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

1.5.5

AzureRM Provider Version

3.69.0

Affected Resource(s)/Data Source(s)

azurerm_subscription_cost_management_view

Terraform Configuration Files

variable "subscription_id" {
  type = string
}

variable "subscription_name" {
  type = string
}
# Configure the Azure Active Directory Provider
provider "azurerm" {
  features {}
  client_id     = ""
  client_secret = ""
  tenant_id     = ""
  subscription_id = var.subscription_id
}


resource "azurerm_subscription_cost_management_view" "subscription_cost_management_view" {
  name         = "costview-${var.subscription_name}"
  display_name = "costview-${var.subscription_name}"
  chart_type   = "StackedColumn"
  accumulated  = false

  subscription_id = "/subscriptions/${var.subscription_id}"

  report_type = "Usage"
  timeframe   = "YearToDate"

  dataset {
    granularity = "Monthly"

    aggregation {
      name        = "totalCost"
      column_name = "Cost"
    }
  }
  pivot {
       name = "ResourceId"
        type = "Dimension"
    }

  pivot {
       name = "ResourceGroupName"
       type = "Dimension"
    }

  pivot {
       name = "ServiceName"
       type = "Dimension"
    }
}

resource "azurerm_cost_management_scheduled_action" "example" {
  name         = "scheduledaction-${var.subscription_name}"
  display_name = "scheduledaction-${var.subscription_name}"

  view_id = azurerm_subscription_cost_management_view.subscription_cost_management_view.id

  email_address_sender = ""
  email_subject        = "Reporte de costes de la suscripción"
  email_addresses      = [""]
  message              = "Hi all, take a look at last 6 months spending!"

  frequency  = "Daily"
  start_date = "2023-01-02T00:00:00Z"
  end_date   = "2024-01-01T00:00:00Z"
}

Debug Output/Panic Output

Plan: 2 to add, 0 to change, 2 to destroy.
azurerm_cost_management_scheduled_action.example: Destroying... [id=/subscriptions/78cc28dc-d0c5-43b7-8352-965399361c04/providers/Microsoft.CostManagement/scheduledActions/scheduledaction-ds-sin013-dev]
azurerm_cost_management_scheduled_action.example: Destruction complete after 1s
azurerm_subscription_cost_management_view.subscription_cost_management_view: Destroying... [id=/subscriptions/78cc28dc-d0c5-43b7-8352-965399361c04/providers/Microsoft.CostManagement/views/costview-ds-sin013-dev]
azurerm_subscription_cost_management_view.subscription_cost_management_view: Destruction complete after 3s
azurerm_subscription_cost_management_view.subscription_cost_management_view: Creating...
azurerm_subscription_cost_management_view.subscription_cost_management_view: Creation complete after 6s [id=/subscriptions/78cc28dc-d0c5-43b7-8352-965399361c04/providers/Microsoft.CostManagement/views/costview-ds-sin013-dev]
azurerm_cost_management_scheduled_action.example: Creating...
azurerm_cost_management_scheduled_action.example: Creation complete after 3s [id=/subscriptions/78cc28dc-d0c5-43b7-8352-965399361c04/providers/Microsoft.CostManagement/scheduledActions/scheduledaction-ds-sin013-dev]

Apply complete! Resources: 2 added, 0 changed, 2 destroyed.

Expected Behaviour

To see the costview with YearToDate timeframe

Actual Behaviour

The costview is just for the actual month

Steps to Reproduce

terraform apply

Important Factoids

No response

References

No response

@neil-yechenwei
Copy link
Contributor

Thanks for raising this issue. Seems "granularity" needs to be set to "Daily".

@cerocool1203
Copy link

I do encounter the same issue while trying to replicate the view below. Additionally, it seems like we cannot set the report type as ActualCost only Usage is valid and for the timeframe the value Last12months is not valid neither but it is available via API.

 "value": [
   {
     "id": "/subscriptions/dhfksdfhksdhkhkshf/providers/Microsoft.CostManagement/views/yearlyview",
     "name": "yearlyview",
     "type": "Microsoft.CostManagement/Views",
     "eTag": "\"dsadsadd\"",
     "properties": {
       "displayName": "Yearly View",
       "scope": "subscriptions/kjsdfksdfhdghdoghdo",
       "createdOn": "2023-08-15T12:12:02.5352058Z",
       "modifiedOn": "2023-08-15T12:12:02.5352058Z",
       "query": {
         "type": "ActualCost",
         "timeframe": "None",
         "dataSet": {
           "granularity": "Monthly",
           "aggregation": {
             "totalCost": {
               "name": "Cost",
               "function": "Sum"
             },
             "totalCostUSD": {
               "name": "CostUSD",
               "function": "Sum"
             }
           },
           "grouping": [
             {
               "type": "Dimension",
               "name": "ServiceName"
             }
           ],
           "sorting": [
             {
               "direction": "Ascending",
               "name": "BillingMonth"
             }
           ]
         },
         "includeMonetaryCommitment": false
       },
       "dateRange": "Last12Months",
       "currency": "USD",
       "chart": "StackedColumn",
       "accumulated": "False",
       "metric": "ActualCost",
       "kpis": [
         {
           "type": "Budget",
           "id": "COST_NAVIGATOR.BUDGET_OPTIONS.NONE",
           "enabled": true
         },
         {
           "type": "Forecast",
           "id": null,
           "enabled": true
         }
       ],
       "pivots": [
         {
           "type": "Dimension",
           "name": "ServiceName"
         },
         {
           "type": "Dimension",
           "name": "ResourceLocation"
         },
         {
           "type": "Dimension",
           "name": "ResourceGroupName"
         }
       ]
     }
   },```

@JoelCanteroGCO
Copy link
Author

Contributor

I have tried to set the granularity to Daily but the problem persists.

@cerocool1203
Copy link

cerocool1203 commented Aug 22, 2023

I manage to get the view I wanted by using the AzAPI resource as workaround

  type        = "Microsoft.CostManagement/views@2023-04-01-preview"
  resource_id = azurerm_subscription_cost_management_view.yearly.id
  body = jsonencode({
    properties = {
      dateRange = "Last12Months"
    }
  })
}

@JoelCantero
Copy link

I manage to get the view I wanted by using the AzAPI resource as workaround

  type        = "Microsoft.CostManagement/views@2023-04-01-preview"
  resource_id = azurerm_subscription_cost_management_view.yearly.id
  body = jsonencode({
    properties = {
      dateRange = "Last12Months"
    }
  })
}

Hello @cerocool1203,
I have tried:

resource "azapi_resource" "example" {
    name = "costview"
    type        = "Microsoft.CostManagement/views@2023-04-01-preview"
    parent_id = azurerm_subscription_cost_management_view.example.id
    body = jsonencode({
        properties = {
        dateRange = "Last12Months"
        }
    })

but it throws this error:

│ RESPONSE 404: 404 Not Found
│ ERROR CODE UNAVAILABLE
│ --------------------------------------------------------------------------------
│ The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
│ --------------------------------------------------------------------------------



@zincob
Copy link

zincob commented May 17, 2024

Is there any solution on the issue?
We are facing exactly the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants