8000 Add support for aws grafana by mohsenkhosroanjam · Pull Request #3396 · infracost/infracost · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for aws grafana #3396

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions internal/providers/terraform/aws/grafana_workspace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package aws

import (
"github.com/infracost/infracost/internal/resources/aws"
"github.com/infracost/infracost/internal/schema"
)

func getGrafanaWorkspaceRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "aws_grafana_workspace",
CoreRFunc: NewGrafanaWorkspace,
}
}

func NewGrafanaWorkspace(d *schema.ResourceData) schema.CoreResource {
r := &aws.GrafanaWorkspace{
Address: d.Address,
Region: d.Get("region").String(),
License: d.Get("license_type").String(),
}

// Set default license type if not specified
if r.License == "" {
r.License = "ENTERPRISE" // Default to ENTERPRISE as per AWS documentation
}

return r
}
16 changes: 16 additions & 0 deletions internal/providers/terraform/aws/grafana_workspace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package aws_test

import (
"testing"

"github.com/infracost/infracost/internal/providers/terraform/tftest"
)

func TestGrafanaWorkspace(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping test in short mode")
}

tftest.GoldenFileResourceTests(t, "grafana_workspace_test")
}
1 change: 1 addition & 0 deletions internal/providers/terraform/aws/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var ResourceRegistry []*schema.RegistryItem = []*schema.RegistryItem{
getElastiCacheClusterItem(),
getElastiCacheReplicationGroupItem(),
getElasticsearchDomainRegistryItem(),
getGrafanaWorkspaceRegistryItem(),
getOpensearchDomainRegistryItem(),
getELBRegistryItem(),
getFlowLogRegistryItem(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Name Monthly Qty Unit Monthly Cost

aws_grafana_workspace.default
└─ Enterprise license 730 hours not found

aws_grafana_workspace.enterprise
└─ Enterprise license 730 hours not found

aws_grafana_workspace.standard
└─ Enterprise license 730 hours not found

OVERALL TOTAL $0.00

*Usage costs can be estimated by updating Infracost Cloud settings, see docs for other options.

──────────────────────────────────
3 cloud resources were detected:
∙ 3 were estimated

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Project ┃ Baseline cost ┃ Usage cost* ┃ Total cost ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━┫
┃ main ┃ $0.00 ┃ - ┃ $0.00 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━┛
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
provider "aws" {
region = "us-east-1"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
skip_region_validation = true
access_key = "mock_access_key"
secret_key = "mock_secret_key"
}

resource "aws_grafana_workspace" "enterprise" {
name = "enterprise-workspace"
account_access_type = "CURRENT_ACCOUNT"
authentication_providers = ["AWS_SSO"]
permission_type = "SERVICE_MANAGED"
}

resource "aws_grafana_workspace" "standard" {
name = "standard-workspace"
account_access_type = "CURRENT_ACCOUNT"
authentication_providers = ["AWS_SSO"]
permission_type = "SERVICE_MANAGED"
}

resource "aws_grafana_workspace" "default" {
name = "default-workspace"
account_access_type = "CURRENT_ACCOUNT"
authentication_providers = ["AWS_SSO"]
permission_type = "SERVICE_MANAGED"
}
68 changes: 68 additions & 0 deletions internal/resources/aws/grafana_workspace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package aws

import (
"github.com/infracost/infracost/internal/schema"
"github.com/shopspring/decimal"
)

type GrafanaWorkspace struct {
Address string
Region string
License string
}

func (r *GrafanaWorkspace) CoreType() string {
return "GrafanaWorkspace"
}

func (r *GrafanaWorkspace) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{}
}

func (r *GrafanaWorkspace) PopulateUsage(u *schema.UsageData) {
// No usage data needed for Grafana workspace
}

func (r *GrafanaWorkspace) BuildResource() *schema.Resource {
costComponents := []*schema.CostComponent{}

// Add cost component based on license type
if r.License == "ENTERPRISE" {
costComponents = append(costComponents, &schema.CostComponent{
Name: "Enterprise license",
Unit: "hours",
UnitMultiplier: decimal.NewFromInt(1),
HourlyQuantity: decimalPtr(decimal.NewFromInt(1)),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonGrafana"),
ProductFamily: strPtr("Amazon Grafana"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "licenseModel", Value: strPtr("Enterprise")},
},
},
})
} else if r.License == "STANDARD" {
costComponents = append(costComponents, &schema.CostComponent{
Name: "Standard license",
Unit: "hours",
UnitMultiplier: decimal.NewFromInt(1),
HourlyQuantity: decimalPtr(decimal.NewFromInt(1)),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonGrafana"),
ProductFamily: strPtr("Amazon Grafana"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "licenseModel", Value: strPtr("Standard")},
},
},
})
}

return &schema.Resource{
Name: r.Address,
CostComponents: costComponents,
}
}
Loading
0