aws-samples / aws-cudos-framework-deployment

Command Line Interface tool for Cloud Intelligence Dashboards deployment
https://catalog.workshops.aws/awscid
MIT No Attribution
408 stars 164 forks source link

Possibility of deploying SCAD dashboard as part of terraform code #928

Closed ivan-kovnatskyi-c54f97a closed 2 months ago

ivan-kovnatskyi-c54f97a commented 2 months ago

Forgive my laziness at this stage, I would dive deep trying to understand how would one do it, but until I'm there I would very happy to hear feedback on how easy it would be implement in in terraform.


# Updated console output below

☸ orbstack in management on  main [?] via 💠 management on ☁️  [redacted]-management took 1m17s 
❯ ./.venv/bin/cid-cmd deploy --dashboard-id scad-containers-cost-allocation
CLOUD INTELLIGENCE DASHBOARDS (CID) CLI 0.3.9 Beta

Loading plugins...
    Core loaded

Checking AWS environment...
    profile name: [redacted]-management
    accountId: [aws-account-id]
    AWS userId: [redacted]
    Region: us-east-1

Latest template: arn:aws:quicksight:us-east-1:223485597511:template/scad-containers-cost-allocation/version/2
Dashboard "scad-containers-cost-allocation" is not deployed

Required datasets: 
 - scad_cca_hourly_resource_view
 - scad_cca_summary_view

Looking by DataSetId defined in template...complete

There are still 2 datasets missing: scad_cca_hourly_resource_view, scad_cca_summary_view
Creating dataset: scad_cca_hourly_resource_view

? [athena-workgroup] Select Amazon Athena workgroup to use: primary

? [quicksight-datasource-id] Please choose DataSource (Select the first one if not sure): CID-CMD-Athena <CREATE NEW DATASOURCE>

? [quicksight-datasource-role] Please choose a QuickSight role. It must have access to Athena: aws-quicksight-service-role-v0
athena_datasource <cid.helpers.quicksight.datasource.Datasource object at 0x104f3bb90>                                                                                                                            

? [athena-database] Select AWS Athena database to use: athenacurcfn_default
Detected views: account_map
Missing views: scad_cca_hourly_resource_view
Checking if CUR is enabled and available...

? [cur-table-name] Please select CUR: default
    Athena table: default
    Resource IDs: yes
    SavingsPlans: yes
    Reserved Instances: yes

CRITICAL - Column 'split_line_item_net_split_cost' is not in (default). Cannot continue.
CRITICAL - Column 'split_line_item_net_unused_cost' is not in (default). Cannot continue.
CRITICAL - Column 'resource_tags_aws_eks_cluster_name' is not in (default). Cannot continue.
CRITICAL - Athena query failed: line 50:98: Column 't_scad_eks.split_line_item_net_split_cost' cannot be resolved
☸ orbstack in management on  main [?] via 💠 management on ☁️  [redacted]-management took 59s 
❯ ./.venv/bin/cid-cmd deploy --dashboard-id scad-containers-cost-allocation
CLOUD INTELLIGENCE DASHBOARDS (CID) CLI 0.3.9 Beta

Loading plugins...
    Core loaded

Checking AWS environment...
    profile name: [redacted]-management
    accountId: [aws-account-id]
    AWS userId: [redacted]
    Region: us-east-1

Latest template: arn:aws:quicksight:us-east-1:223485597511:template/scad-containers-cost-allocation/version/2
Dashboard "scad-containers-cost-allocation" is not deployed

Required datasets: 
 - scad_cca_hourly_resource_view
 - scad_cca_summary_view

Looking by DataSetId defined in template...complete

There are still 2 datasets missing: scad_cca_hourly_resource_view, scad_cca_summary_view
Creating dataset: scad_cca_hourly_resource_view

? [athena-workgroup] Select Amazon Athena workgroup to use: CID

? [quicksight-datasource-id] Please choose DataSource (Select the first one if not sure): CID-Athena CID-Athena (workgroup=CID)

? [athena-database] Select AWS Athena database to use: (Use arrow keys)                                                                                                                                           

Cancelled by user

☸ orbstack in management on  main [?] via 💠 management on ☁️  [redacted]-management took 2m55s 
❯ ./.venv/bin/cid-cmd deploy --dashboard-id scad-containers-cost-allocation
CLOUD INTELLIGENCE DASHBOARDS (CID) CLI 0.3.9 Beta

Loading plugins...
    Core loaded

Checking AWS environment...
    profile name: [redacted]-management
    accountId: [aws-account-id]
    AWS userId: [redacted]
    Region: us-east-1

Latest template: arn:aws:quicksight:us-east-1:223485597511:template/scad-containers-cost-allocation/version/2
Dashboard "scad-containers-cost-allocation" is not deployed

Required datasets: 
 - scad_cca_summary_view
 - scad_cca_hourly_resource_view

Looking by DataSetId defined in template...complete

There are still 2 datasets missing: scad_cca_hourly_resource_view, scad_cca_summary_view
Creating dataset: scad_cca_hourly_resource_view

? [athena-workgroup] Select Amazon Athena workgroup to use: CID

? [quicksight-datasource-id] Please choose DataSource (Select the first one if not sure): CID-Athena CID-Athena (workgroup=CID)

? [athena-database] Select AWS Athena database to use: cid_cur
Detected views: account_map
Missing views: scad_cca_hourly_resource_view
Checking if CUR is enabled and available...

? [cur-table-name] Please select CUR: cur
    Athena table: cur
    Resource IDs: yes
    SavingsPlans: yes
    Reserved Instances: yes

^[[AColumn 'split_line_item_parent_resource_id' was added to CUR (cur).
Column 'split_line_item_reserved_usage' was added to CUR (cur).
Column 'split_line_item_actual_usage' was added to CUR (cur).
Column 'split_line_item_split_usage' was added to CUR (cur).
Column 'split_line_item_split_usage_ratio' was added to CUR (cur).
Column 'split_line_item_split_cost' was added to CUR (cur).
Column 'split_line_item_unused_cost' was added to CUR (cur).
Column 'split_line_item_net_split_cost' was added to CUR (cur).
Column 'split_line_item_net_unused_cost' was added to CUR (cur).
Column 'split_line_item_public_on_demand_split_cost' was added to CUR (cur).
Column 'split_line_item_public_on_demand_unused_cost' was added to CUR (cur).
Column 'resource_tags_aws_eks_cluster_name' was added to CUR (cur).
Column 'resource_tags_aws_eks_deployment' was added to CUR (cur).
Column 'resource_tags_aws_eks_namespace' was added to CUR (cur).
Column 'resource_tags_aws_eks_node' was added to CUR (cur).
Column 'resource_tags_aws_eks_workload_name' was added to CUR (cur).
Column 'resource_tags_aws_eks_workload_type' was added to CUR (cur).
CRITICAL - Athena query failed: line 77:16: Column 'product_instance_family' cannot be resolved
☸ orbstack in management on  main [?] via 💠 management on ☁️  [redacted]-management took 2m23s

# Updated console output above

☸ orbstack in management on  main [?] via 💠 management on ☁️  [redacted]-management took 2m23s 
❯ ./.venv/bin/cid-cmd deploy --dashboard-id scad-containers-cost-allocation
CLOUD INTELLIGENCE DASHBOARDS (CID) CLI 0.3.9 Beta

Loading plugins...
    Core loaded

Checking AWS environment...
    profile name: [redacted]-management
    accountId: [redacted]
    AWS userId: AWSReservedSSO_[redacted]/[redacted]@[redacted].com
    Region: us-east-1

Latest template: arn:aws:quicksight:us-east-1:223485597511:template/scad-containers-cost-allocation/version/2
Dashboard "scad-containers-cost-allocation" is not deployed

Required datasets: 
 - scad_cca_hourly_resource_view
 - scad_cca_summary_view

Looking by DataSetId defined in template...complete

There are still 2 datasets missing: scad_cca_hourly_resource_view, scad_cca_summary_view
Creating dataset: scad_cca_hourly_resource_view

? [athena-workgroup] Select Amazon Athena workgroup to use: CID

? [quicksight-datasource-id] Please choose DataSource (Select the first one if not sure): CID-Athena CID-Athena (workgroup=CID)

? [athena-database] Select AWS Athena database to use: cid_cur
Detected views: account_map
Missing views: scad_cca_hourly_resource_view
Checking if CUR is enabled and available...

? [cur-table-name] Please select CUR: cur
    Athena table: cur
    Resource IDs: yes
    SavingsPlans: yes
    Reserved Instances: yes

From the console output it looks like beside dashboard itself, I would need to make sure I have datasets all available.

iakov-aws commented 2 months ago

Please can you provide more output? it looks like it is truncated

ivan-kovnatskyi-c54f97a commented 2 months ago

Thanks for the quick reply. Don't want to overwhelm with the console output. Updated it in my initial message.

From my observation it's just:

  1. QuickSight dataset: scad_cca_hourly_resource_view
  2. Deployed Dashboard

? [quicksight-datasource-id] Please choose DataSource (Select the first one if not sure): CID-CMD-Athena This probably also meant new resource.

Yes, sorry for not mentionning that I have deployed some prerequisites with this code:

locals {
  aws_account_id = data.aws_caller_identity.current.id
}

# Provider alias for us-east-1 must be passed explicitly (required for CUR setup)
provider "aws" {
  region = "us-east-1"
  alias  = "useast1"
}

# Configure one or more source (payer) accounts
module "cur_source" {
  source = "github.com/aws-samples/aws-cudos-framework-deployment//terraform-modules/cur-setup-source?ref=0.3.9"

  destination_bucket_arn = module.cur_destination.cur_bucket_arn

  enable_split_cost_allocation_data = true

  # Provider alias for us-east-1 must be passed explicitly (required for CUR setup)
  providers = {
    aws.useast1 = aws.useast1
  }
}

module "cur_destination" {
  source = "github.com/aws-samples/aws-cudos-framework-deployment//terraform-modules/cur-setup-destination?ref=0.3.9"

  source_account_ids = ["${local.aws_account_id}"]
  create_cur         = false # Set to true to create an additional CUR in the aggregation account

  # Provider alias for us-east-1 must be passed explicitly (required for CUR setup)
  providers = {
    aws.useast1 = aws.useast1
  }
}

module "cid_dashboards" {
  source = "github.com/aws-samples/aws-cudos-framework-deployment//terraform-modules/cid-dashboards?ref=0.3.9"

  stack_name      = "Cloud-Intelligence-Dashboards"
  template_bucket = local.s3_bucket

  stack_parameters = {
    "PrerequisitesQuickSight"            = "yes"
    "PrerequisitesQuickSightPermissions" = "yes"
    "QuickSightUser"                     = "[redacted]"

    # This is required to deploy SCAD dashboard with cid-cmd tool.
    "DeployCUDOSDashboard"            = "yes"
    "DeployCostIntelligenceDashboard" = "yes"
    "DeployKPIDashboard"              = "yes"
  }
}

My thinking is that potentially we could add SCAD to dashboards module with changes of course, only I don't grasp them all yet.

--

Hm, let me try to do it, actually.

ivan-kovnatskyi-c54f97a commented 2 months ago

In my draft PR I've added dashboard deployment, using CFN already in place, when I clean up dashboard with cid-cmd tool using delete command it also deletes datasets, that is expected (now I know this 😄).

Hit deploy changed (with SCAD) terraform dashboard module, it does deploy the dashboard, but expectedly so does not configure datasets.

I tried to capture how dataset configured in dashboard would look like in terraform code and it's horrible, considering that dashboard's dataset config is the first source of truth, I presume. Add to that the fact that it will be updated from time to time, it does not make sense to codify/mimic that in another tool. Unless you guys do it in some other way.

I'm I spelling it correctly? Do I miss anything?

Basically currently dashboards module can only deploy dashboards that does not have datasets configuration.

Thankful for your input on this one.

ivan-kovnatskyi-c54f97a commented 2 months ago

Closing this, all in all CLI is the best choice to deploy the dashboard that has datasets defined, since terraform can't automagically parse it and configure it for us, we could of course parse yaml and form new dataset resource, but that would be a nightmare.

This options is the least distant:

resource "terraform_data" "cid_cmd_deploy" {
  provisioner "local-exec" {
    command = <<-EOT
      pip3 install --upgrade cid-cmd
      cid-cmd deploy
      cid-cmd deploy --dashboard-id scad-containers-cost-allocation
    EOT
  }

  provisioner "local-exec" {
    when    = destroy
    command = "cid-cmd delete --dashboard-id scad-containers-cost-allocation"
  }
}

Yet, many dislike arbitrary provider resources for their unpredictability.