Skip to content

Commit

Permalink
chore: updated naming
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswuerbach committed Feb 12, 2024
1 parent 80655ff commit 44d0af7
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 28 deletions.
3 changes: 2 additions & 1 deletion examples/s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ The workload service account will automatically be assigned the necessary AWS IA
| cluster\_name | Name of the EKS cluster | `string` | n/a | yes |
| region | AWS Region | `string` | n/a | yes |
| secret\_key | AWS Secret Key | `string` | n/a | yes |
| name | Name of the example application | `string` | `"s3-test"` | no |
| name | Name of the example application | `string` | `"hum-rp-s3-example"` | no |
| prefix | Name prefix | `string` | `"hum-rp-s3-ex-"` | no |
| resource\_packs\_aws\_rev | AWS Resource Pack git branch | `string` | `"refs/heads/main"` | no |
| resource\_packs\_aws\_url | AWS Resource Pack git url | `string` | `"https://github.com/humanitec-architecture/resource-packs-aws.git"` | no |
<!-- END_TF_DOCS -->
20 changes: 8 additions & 12 deletions examples/s3/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
locals {
res_def_prefix = "${var.name}-"
}

resource "humanitec_application" "example" {
id = var.name
name = var.name
Expand Down Expand Up @@ -32,7 +28,7 @@ module "s3_basic" {
secret_key = var.secret_key
region = var.region

prefix = local.res_def_prefix
prefix = var.prefix
}

resource "humanitec_resource_definition_criteria" "s3_basic" {
Expand All @@ -58,7 +54,7 @@ module "iam_policy_s3_admin" {

policy = "admin"

prefix = local.res_def_prefix
prefix = var.prefix

s3_resource_class = local.s3_basic_class
}
Expand All @@ -73,7 +69,7 @@ resource "humanitec_resource_definition_criteria" "iam_policy_s3_admin" {
module "s3_basic_admin" {
source = "../../humanitec-resource-defs/s3/passthrough"

prefix = local.res_def_prefix
prefix = var.prefix

s3_resource_class = local.s3_basic_class
policy_resource_class = local.s3_admin_policy_class
Expand Down Expand Up @@ -101,7 +97,7 @@ module "iam_policy_s3_read_only" {

policy = "read-only"

prefix = local.res_def_prefix
prefix = var.prefix

s3_resource_class = local.s3_basic_class
}
Expand All @@ -116,7 +112,7 @@ resource "humanitec_resource_definition_criteria" "iam_policy_s3_read_only" {
module "s3_basic_read_only" {
source = "../../humanitec-resource-defs/s3/passthrough"

prefix = local.res_def_prefix
prefix = var.prefix

s3_resource_class = local.s3_basic_class
policy_resource_class = local.s3_read_only_policy_class
Expand All @@ -134,7 +130,7 @@ resource "humanitec_resource_definition_criteria" "s3_basic_read_only" {
module "k8s_service_account" {
source = "../../humanitec-resource-defs/k8s/service-account"

prefix = local.res_def_prefix
prefix = var.prefix
}

resource "humanitec_resource_definition_criteria" "k8s_service_account" {
Expand All @@ -153,7 +149,7 @@ module "iam_role_service_account" {
region = var.region

cluster_name = var.cluster_name
prefix = local.res_def_prefix
prefix = var.prefix
}

resource "humanitec_resource_definition_criteria" "iam_role_service_account" {
Expand All @@ -164,7 +160,7 @@ resource "humanitec_resource_definition_criteria" "iam_role_service_account" {
module "workload" {
source = "../../humanitec-resource-defs/workload/service-account"

prefix = local.res_def_prefix
prefix = var.prefix
}

resource "humanitec_resource_definition_criteria" "workload" {
Expand Down
5 changes: 4 additions & 1 deletion examples/s3/terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ access_key = ""
cluster_name = ""

# Name of the example application
name = "s3-test"
name = "hum-rp-s3-example"

# Name prefix
prefix = "hum-rp-s3-ex-"

# AWS Region
region = ""
Expand Down
8 changes: 7 additions & 1 deletion examples/s3/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ variable "resource_packs_aws_rev" {
variable "name" {
description = "Name of the example application"
type = string
default = "s3-test"
default = "hum-rp-s3-example"
}

variable "prefix" {
description = "Name prefix"
type = string
default = "hum-rp-s3-ex-"
}
3 changes: 2 additions & 1 deletion humanitec-resource-defs/s3/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| access\_key | n/a | `string` | n/a | yes |
| prefix | n/a | `string` | n/a | yes |
| prefix | Name prefix | `string` | n/a | yes |
| region | n/a | `string` | n/a | yes |
| resource\_packs\_aws\_rev | AWS Resource Pack git branch | `string` | n/a | yes |
| secret\_key | n/a | `string` | n/a | yes |
| name | Resource name (can contain placeholders like ${context.app.id}) | `string` | `""` | no |
| resource\_packs\_aws\_url | AWS Resource Pack git url | `string` | `"https://github.com/humanitec-architecture/resource-packs-aws.git"` | no |

## Outputs
Expand Down
8 changes: 3 additions & 5 deletions humanitec-resource-defs/s3/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ resource "humanitec_resource_definition" "main" {
}

variables = {
region = var.region,
# TODO: How to template the bucket name?
# Name restrictions https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html
# prefix = "${var.prefix}$${context.res.id}"
prefix = "${var.prefix}basic-bucket"
region = var.region
prefix = var.prefix
name = var.name

res_id = "$${context.res.id}"
app_id = "$${context.app.id}"
Expand Down
10 changes: 8 additions & 2 deletions humanitec-resource-defs/s3/basic/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
access_key = ""
prefix = ""
region = ""

# Resource name (can contain placeholders like ${context.app.id})
name = ""

# Name prefix
prefix = ""

region = ""

# AWS Resource Pack git branch
resource_packs_aws_rev = ""
Expand Down
15 changes: 11 additions & 4 deletions humanitec-resource-defs/s3/basic/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
variable "prefix" {
type = string
}

variable "resource_packs_aws_url" {
description = "AWS Resource Pack git url"
type = string
Expand All @@ -24,3 +20,14 @@ variable "secret_key" {
variable "region" {
type = string
}

variable "prefix" {
type = string
description = "Name prefix"
}

variable "name" {
type = string
description = "Resource name (can contain placeholders like $${context.app.id})"
default = ""
}
1 change: 1 addition & 0 deletions modules/s3/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
| res\_id | n/a | `string` | n/a | yes |
| secret\_key | n/a | `string` | n/a | yes |
| force\_destroy | n/a | `bool` | `true` | no |
| name | n/a | `string` | `""` | no |

## Outputs

Expand Down
7 changes: 6 additions & 1 deletion modules/s3/basic/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
locals {
# Name restrictions https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html
default_name = substr("${var.prefix}${var.app_id}-${var.env_id}-${replace(var.res_id, ".", "-")}", 0, 63)
}

resource "aws_s3_bucket" "main" {
bucket_prefix = var.prefix
bucket = coalesce(var.name, local.default_name)
force_destroy = var.force_destroy
}

Expand Down
1 change: 1 addition & 0 deletions modules/s3/basic/terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ access_key = ""
app_id = ""
env_id = ""
force_destroy = true
name = ""
prefix = ""
region = ""
res_id = ""
Expand Down
5 changes: 5 additions & 0 deletions modules/s3/basic/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ variable "force_destroy" {
default = true
}

variable "name" {
type = string
default = ""
}

variable "app_id" {
type = string
}
Expand Down

0 comments on commit 44d0af7

Please sign in to comment.