Skip to content

Commit

Permalink
Remove custom workaround to validate resource_type (#27)
Browse files Browse the repository at this point in the history
* apply fix

* fix codeowners
  • Loading branch information
Rafi Kurnia Putra authored Jun 18, 2019
1 parent 3af6794 commit d6f091a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* traveloka/techops
* @traveloka/techops
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ Don't forget to also add the resource that you added to [Supported Resources lis

Terraform Version
-----------------
This module was created using Terraform 0.11.6.
So to be more safe, Terraform version 0.11.6 or newer is required to use this module.
This module was originally created using Terraform 0.11.6.
Terraform version 0.11.6 or newer is required to use this module.


Authors
Expand Down
2 changes: 1 addition & 1 deletion examples/autoscaling-policy-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module "this" {
source = "../../"

name_prefix = "${local.service_name}-${local.cluster_role}-${local.scaling_description}"
resource_type = "scaling_policy"
resource_type = "autoscaling_policy"

keepers = {
FirstKeeper = "TestValue"
Expand Down
19 changes: 7 additions & 12 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# This module was created using Terraform 0.11.6 on 2018/04/10
# Tested working on Terraform 0.12.0 on 2019/05/28
terraform {
required_version = ">= 0.11.6, < 0.13.0"
}

locals {
# Randomly generated hexadecimal value should not exceed 16 characters.
max_byte_length = 8
Expand All @@ -7,7 +13,7 @@ locals {
# * var.name_prefix = "txtdata-app" --> prefix = "txtdata-app-"
# * var.name_prefix = "txtdata-app-" --> prefix = "txtdata-app-"
# * var.name_prefix = "txtdata-app--" --> prefix = "txtdata-app--"
prefix = "${substr(var.name_prefix, -1, 1) == "-" ? substr(var.name_prefix, 0, length(var.name_prefix)-1) : var.name_prefix}-"
prefix = "${substr(var.name_prefix, -1, 1) == "-" ? substr(var.name_prefix, 0, length(var.name_prefix) - 1) : var.name_prefix}-"

prefix_length = "${length(local.prefix)}"
resource_max_character_length = "${lookup(local.max_character_length, var.resource_type, 0)}"
Expand All @@ -16,22 +22,11 @@ locals {
random_byte_length = "${min(local.max_byte_length, local.random_max_byte_length)}"
}

# Null Provider. This module was created on 2018/04/10
provider "null" {
version = ">= 1.0.0, < 3.0.0"
}

# Random Provider. This module was created on 2018/04/10
provider "random" {
version = ">= 1.2.0, < 3.0.0"
}

# Throws error when resource_type is not suppported by the module yet
resource "null_resource" "unsupported_resource_type" {
count = "${local.resource_max_character_length == 0 ? 1 : 0}"
"\n\nCurrently supported resource types: \n* ${join("\n* ", keys(local.max_character_length))}" = true
}

# Provides random id in hex format
resource "random_id" "this" {
prefix = "${local.prefix}"
Expand Down

0 comments on commit d6f091a

Please sign in to comment.