Skip to content

Commit

Permalink
Force cost-center label (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcurtis authored Dec 11, 2023
1 parent c3966d5 commit c3ef017
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 20 deletions.
30 changes: 27 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,43 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-symlinks
- id: no-commit-to-branch

- repo: local
hooks:
- id: infracost_generate_config
name: Infracost generate config
entry: bash -c 'infracost generate config --repo-path=. --template-path=infracost.yml.tmpl --out-file=infracost.yml'
language: system
files: ^infracost\.yml\.tmpl$
verbose: false

- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.77.2
rev: v1.83.6
hooks:
- id: terraform_fmt
- id: terraform_docs

# To speed up local validation add the following to your ~/.zshrc:
# export TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache

- id: terraform_validate
args:
- --hook-config=--retry-once-with-cleanup=true
- --tf-init-args=-upgrade
exclude: test/fixtures/shared

# Always run after terraform_validate

- id: terraform_docs

- id: infracost_breakdown
args:
- --args=--config-file=infracost.yml
- --args=--sync-usage-file
verbose: false
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

**[Infracost](https://www.infracost.io):**

[![infracost](https://img.shields.io/endpoint?label=Default%20Bucket&url=https://dashboard.api.infracost.io/shields/json/cbeecfe3-576f-4553-984c-e451a575ee47/repos/00c5bd62-c59f-44f6-8583-5632a43182fd/branch/65062ab7-4e16-4e82-ba22-22c03a84f6fc)](https://dashboard.infracost.io/org/osinfra-io/repos/00c5bd62-c59f-44f6-8583-5632a43182fd)
[![infracost](https://img.shields.io/endpoint?label=default_bucket&url=https://dashboard.api.infracost.io/shields/json/cbeecfe3-576f-4553-984c-e451a575ee47/repos/00c5bd62-c59f-44f6-8583-5632a43182fd/branch/65062ab7-4e16-4e82-ba22-22c03a84f6fc/default_bucket)](https://dashboard.infracost.io/org/osinfra-io/repos/00c5bd62-c59f-44f6-8583-5632a43182fd?tab=settings)

Monthly cost estimates for this module based on these usage values: [Default Bucket](test/fixtures/default_bucket/infracost-usage.yml)
Monthly cost estimates for this module based on these usage values:

- [default_bucket](test/fixtures/default_bucket/infracost-usage.yml)

## Repository Description

Expand All @@ -26,9 +28,10 @@ Here is an example of a basic configuration:
module "storage_bucket" {
source = "github.com/osinfra-io/terraform-google-storage-bucket?ref=v0.0.0"
location = "us-east1"
name = "example-tf34k"
project_id = "example-project"
cost_center = "x000"
location = "us-east1"
name = "example-tf34k"
project_id = "example-project"
}
```

Expand Down Expand Up @@ -80,7 +83,7 @@ A child module automatically inherits its parent's default (un-aliased) provider

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider_google) | 4.62.1 |
| <a name="provider_google"></a> [google](#provider_google) | 5.8.0 |

### Resources

Expand All @@ -92,12 +95,13 @@ A child module automatically inherits its parent's default (un-aliased) provider

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_cost_center"></a> [cost_center](#input_cost_center) | The cost center to use for resource labels | `string` | n/a | yes |
| <a name="input_location"></a> [location](#input_location) | The location the storage bucket will be created in | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input_name) | The name of the storage bucket | `any` | n/a | yes |
| <a name="input_project"></a> [project](#input_project) | The ID of the project in which the resource belongs | `string` | n/a | yes |
| <a name="input_default_kms_key_name"></a> [default_kms_key_name](#input_default_kms_key_name) | The name of the Cloud KMS key that will be used to encrypt objects inserted into this bucket | `string` | `null` | no |
| <a name="input_force_destroy"></a> [force_destroy](#input_force_destroy) | When deleting a bucket, this boolean option will delete all contained objects | `bool` | `false` | no |
| <a name="input_labels"></a> [labels](#input_labels) | A map of labels to add to all resources | `map(string)` | `null` | no |
| <a name="input_labels"></a> [labels](#input_labels) | A map of key/value pairs to assign to the resources being created | `map(string)` | `{}` | no |
| <a name="input_storage_class"></a> [storage_class](#input_storage_class) | The Storage Class of the new bucket. Supported values include: STANDARD, MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, ARCHIVE | `string` | `"STANDARD"` | no |
| <a name="input_versioning"></a> [versioning](#input_versioning) | The bucket's Versioning configuration | `bool` | `true` | no |

Expand Down
14 changes: 8 additions & 6 deletions infracost.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Infracost Config File
# https://www.infracost.io/docs/features/config_file

version: 0.1
# Infracost Configuration
# https://www.infracost.io/docs/config_file

# This file is manged by the infracost.yml.tmpl file, do not edit infracost.yml directly.

version: 0.1
projects:
- name: "terraform-google-storage-bucket - Default Bucket"
path: test/fixtures/default_bucket
usage_file: test/fixtures/default_bucket/infracost-usage.yml
- path: test/fixtures/default_bucket
name: "default_bucket"
usage_file: test/fixtures/default_bucket/infracost-usage.yml
16 changes: 16 additions & 0 deletions infracost.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{/* Infracost Template: https://www.infracost.io/docs/features/config_file/#template-syntax */}}
# Infracost Configuration
# https://www.infracost.io/docs/config_file

# This file is manged by the infracost.yml.tmpl file, do not edit infracost.yml directly.

version: 0.1
projects:

{{- range $project := matchPaths "test/fixtures/:name" }}
{{- if ne $project.name "shared"}}
- path: {{ print $project._dir "/" $project.name }}
name: "{{ $project.name }}"
usage_file: {{ print $project._dir "/" $project.name "/infracost-usage.yml" }}
{{- end }}
{{- end}}
11 changes: 11 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Terraform Local Values
# https://www.terraform.io/docs/language/values/locals.html

locals {
labels = merge(
{
cost-center = var.cost_center
},
var.labels
)
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resource "google_storage_bucket" "this" {
}

force_destroy = var.force_destroy
labels = var.labels
labels = local.labels
location = var.location
name = var.name
project = var.project
Expand Down
9 changes: 8 additions & 1 deletion test/fixtures/default_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ module "storage_bucket" {

source = "../../../"

cost_center = "x000"

labels = {
env = "sb"
team = "testing"
}

location = "US"
name = random_id.bucket_name.hex
project = "testing-kitchen-tf11-sb"
project = "testing-kitchen-tfbd-sb"
}

resource "random_id" "bucket_name" {
Expand Down
9 changes: 7 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Input Variables
# https://www.terraform.io/language/values/variables

variable "cost_center" {
description = "The cost center to use for resource labels"
type = string
}

variable "default_kms_key_name" {
description = "The name of the Cloud KMS key that will be used to encrypt objects inserted into this bucket"
type = string
Expand All @@ -14,9 +19,9 @@ variable "force_destroy" {
}

variable "labels" {
description = "A map of labels to add to all resources"
description = "A map of key/value pairs to assign to the resources being created"
type = map(string)
default = null
default = {}
}

variable "location" {
Expand Down

0 comments on commit c3ef017

Please sign in to comment.