Skip to content
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

Adds functions for checking the type of variables #23195

Closed
wants to merge 3 commits into from

Conversation

udondan
Copy link
Contributor

@udondan udondan commented Oct 26, 2019

Fixes #23070 <- Description and use case can be found in that issue.

PR covers

  • Functionality (79 lines)
  • Tests (263 lines)
  • Documentation (441 lines)

My Terraform test code:

locals {
  bool   = false
  list   = list(1, 2, 3)
  map    = map("foo", 112)
  number = 6
  object = { foo : "bar" }
  set    = set(1, 2, 5)
  string = "foo"
  tuple  = [1, 2, 3]
}

output "type" {
  value = {
    bool   = type(local.bool)
    list   = type(local.list)
    map    = type(local.map)
    null   = type(null)
    number = type(local.number)
    object = type(local.object)
    set    = type(local.set)
    string = type(local.string)
    tuple  = type(local.tuple)
  }
}
output "is" {
  value = {
    bool   = isbool(local.bool)
    list   = islist(local.list)
    map    = ismap(local.map)
    null   = isnull(null)
    number = isnumber(local.number)
    object = isobject(local.object)
    set    = isset(local.set)
    string = isstring(local.string)
    tuple  = istuple(local.tuple)
  }
}

output "isNot" {
  value = {
    bool   = isbool(local.number)
    list   = islist(local.map)
    map    = ismap(local.list)
    null   = isnull(local.number)
    number = isnumber(null)
    object = isobject(local.set)
    set    = isset(local.object)
    string = isstring(local.tuple)
    tuple  = istuple(local.string)
  }
}

Applying above code results in this output:

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

is = {
  "bool" = true
  "list" = true
  "map" = true
  "null" = true
  "number" = true
  "object" = true
  "set" = true
  "string" = true
  "tuple" = true
}
isNot = {
  "bool" = false
  "list" = false
  "map" = false
  "null" = false
  "number" = false
  "object" = false
  "set" = false
  "string" = false
  "tuple" = false
}
type = {
  "bool" = "bool"
  "list" = "list"
  "map" = "map"
  "null" = "null"
  "number" = "number"
  "object" = "object"
  "set" = "set"
  "string" = "string"
  "tuple" = "tuple"
}

@ghost ghost added the sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK label Oct 26, 2019
@udondan udondan closed this Feb 26, 2020
@ghost
Copy link

ghost commented Apr 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@hashicorp hashicorp locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variable type detection
1 participant