### Example Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_scrypt_base64 Demonstrates how to use the `hash_scrypt_base64` function within an OpenTofu configuration to generate a Scrypt hash. ```APIDOC ## Example Usage ```hcl output "hash_scrypt_base64" { value = provider::corefunc::hash_scrypt_base64("hello world", "somesaltvalue") } ``` # Expected Output: ``` xY40ROoFBE25zbFAasFDiEs1EQHD4jyV4BDsmUyNZd8= ``` ``` -------------------------------- ### corefunc_hash_scrypt Data Source Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_scrypt Example of how to use the corefunc_hash_scrypt data source to generate a hash for a given input string and salt. ```hcl data "corefunc_hash_scrypt" "hash_scrypt" { input = "hello world" salt = "somesaltvalue" } #=> c58e3444ea05044db9cdb1406ac143884b351101c3e23c95e010ec994c8d65df ``` -------------------------------- ### str_pascal Example Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_pascal Example of how to use the str_pascal function in OpenTofu to convert a string to PascalCase. ```APIDOC ## Example Usage ```hcl output "test_with_number" { value = provider::corefunc::str_pascal("test with number -123.456") } # Expected Output: # TestWithNumber123456 ``` ``` -------------------------------- ### Example Usage of hash_scrypt Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_scrypt Demonstrates how to use the hash_scrypt function within an OpenTofu output block to generate a Scrypt hash. ```hcl output "hash_scrypt" { value = provider::corefunc::hash_scrypt("hello world", "somesaltvalue") } ``` -------------------------------- ### Example Usage of corefunc_int_leftpad Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/int_leftpad Demonstrates how to use the corefunc_int_leftpad data source to pad an integer with leading zeros. The output is shown as a comment. ```terraform data "corefunc_int_leftpad" "leftpad" { num = 123 pad_width = 5 } #=> "00123" ``` -------------------------------- ### str_leftpad Function Signature and Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_leftpad Demonstrates the signature, arguments, and example usage of the str_leftpad function. ```APIDOC ## str_leftpad(str string, pad_width number, pad_char string...) string ### Description Pads a string with additional characters on the left. ### Arguments 1. `str` (String) - The string to pad with padding characters. 2. `pad_width` (Number) - The max number of padding characters to pad the string with. 3. `pad_char` (Variadic, String) - The padding character to use. Only supports a single byte. If more than one byte is provided, only the first byte will be used. The default value is a space character. ### Example Usage ```hcl output "leftpad" { value = provider::corefunc::str_leftpad("foo", 5, ".") } #=> ..foo ``` ``` -------------------------------- ### Example Usage of int_leftpad Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/int_leftpad Demonstrates how to use the int_leftpad function within a Terraform output block to pad an integer. ```terraform output "leftpad" { value = provider::corefunc::int_leftpad(123, 5) } #=> 00123 ``` -------------------------------- ### Example Usage of corefunc_hash_sha3x256_base64 Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_sha3x256_base64 Demonstrates how to use the `corefunc_hash_sha3x256_base64` data source to hash the string "hello world" and retrieve the Base64 encoded result. ```HCL data "corefunc_hash_sha3x256_base64" "hash_sha3x256_base64" { input = "hello world" } #=> ZEvMflZDcwQJmarInnYi88px+6HZcv2Uoxw7+/JOOTg= ``` -------------------------------- ### Example Usage of corefunc_hash_argon2id_base64 Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_argon2id_base64 Demonstrates how to use the corefunc_hash_argon2id_base64 data source to hash a string with a salt and retrieve the Base64 encoded value. ```hcl data "corefunc_hash_argon2id_base64" "hash_argon2id_base64" { input = "hello world" salt = "somesaltvalue" } #=> ZguOJZ3zSW6cQpvr2X611YqIzUaFHjDB3QO5RIwGbqQ= ``` -------------------------------- ### Example Usage of hash_sha3x384 Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_sha3x384 Demonstrates how to use the hash_sha3x384 function to generate a SHA-3/384 hash for the string 'hello world'. The output is a Base64 encoded string. ```hcl output "hash_sha3x384" { value = provider::corefunc::hash_sha3x384("hello world") } ``` -------------------------------- ### Example Usage of hash_sha3x384_base64 Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_sha3x384_base64 Demonstrates how to use the `hash_sha3x384_base64` function within an OpenTofu configuration to hash the string 'hello world'. The output will be the Base64 encoded SHA-3/384 hash. ```hcl output "hash_sha3x384_base64" { value = provider::corefunc::hash_sha3x384_base64("hello world") } #=> g7/yjd4bG/WBAHHGZDwI5bBb24Nu/9cLQD6o6gpjTcSZfrEFOqNZP1kPnGNjDdkL ``` -------------------------------- ### Example Usage of corefunc_hash_argon2id Data Source Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_argon2id Demonstrates how to use the corefunc_hash_argon2id data source to generate a hash for a given input string and salt. ```hcl data "corefunc_hash_argon2id" "hash_argon2id" { input = "hello world" salt = "somesaltvalue" } #=> 660b8e259df3496e9c429bebd97eb5d58a88cd46851e30c1dd03b9448c066ea4 ``` -------------------------------- ### Example Usage of hash_scrypt_base64 Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_scrypt_base64 Demonstrates how to use the `hash_scrypt_base64` function within an OpenTofu configuration to hash the string 'hello world' with the salt 'somesaltvalue'. The expected Base64 encoded hash is provided. ```hcl output "hash_scrypt_base64" { value = provider::corefunc::hash_scrypt_base64("hello world", "somesaltvalue") } #=> xY40ROoFBE25zbFAasFDiEs1EQHD4jyV4BDsmUyNZd8= ``` -------------------------------- ### Example Usage of hash_sha3x256_base64 Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_sha3x256_base64 Demonstrates how to use the `hash_sha3x256_base64` function within an OpenTofu configuration to hash the string "hello world". The output will be the Base64 encoded SHA-3/256 hash. ```hcl output "hash_sha3x256_base64" { value = provider::corefunc::hash_sha3x256_base64("hello world") } #=> ZEvMflZDcwQJmarInnYi88px+6HZcv2Uoxw7+/JOOTg= ``` -------------------------------- ### Example Usage of corefunc_hash_scrypt_base64 Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_scrypt_base64 Demonstrates how to use the `corefunc_hash_scrypt_base64` data source in Terraform to hash an input string with a salt and retrieve the Base64 encoded result. ```terraform data "corefunc_hash_scrypt_base64" "hash_scrypt_base64" { input = "hello world" salt = "somesaltvalue" } #=> xY40ROoFBE25zbFAasFDiEs1EQHD4jyV4BDsmUyNZd8= ``` -------------------------------- ### Get Runtime OS Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/runtime_os Retrieves the operating system for which the provider was compiled. This maps to the `runtime.GOOS` Go property. ```terraform data "corefunc_runtime_os" "os" {} #=> linux ``` -------------------------------- ### corefunc_str_base64_gunzip Data Source Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_base64_gunzip Example of how to use the corefunc_str_base64_gunzip data source to decode and decompress a gzipped Base64 string. ```APIDOC ## Data Source: corefunc_str_base64_gunzip ### Description Base64Gunzip is a function that decodes a Base64-encoded string, then decompresses the result with gzip. Supports both padded and non-padded Base64 strings. Uses the "standard" Base64 alphabet as defined in RFC 4648 §4. There is a data limit of 10 MiB (10485760 bytes) for the decompressed data. This is to avoid "decompression bomb" vulnerabilities. ### Example Usage ```hcl data "corefunc_str_base64_gunzip" "str" { gzipped_base64 = "H4sIAAAAAAAA/8pIrVTISK3UUShPVS9KVSjJSFXIzc/LTk0tBgQAAP//qz+dmhoAAAA" } #=> hey hey, we're the monkees ``` ### Schema #### Required * `gzipped_base64` (String) - A string of gzipped then Base64-encoded data. #### Read-Only * `value` (String) - The Base64-decoded, then un-gzipped data. ``` -------------------------------- ### Example Usage of str_contains Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_contains Demonstrates how to use the str_contains function within a Terraform configuration to check if a string contains a substring. This example shows a successful match. ```HCL output "str_contains" { value = provider::corefunc::str_contains("hello world", "ello") } #=> true ``` -------------------------------- ### Convert string to snake_case (complex example) Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_snake Converts a complex string with various non-alphanumeric characters to snake_case. This example demonstrates handling of spaces, brackets, braces, dollar signs, and periods. ```HCL data "corefunc_str_snake" "this_is_an_example" { string = "This is [an] {example}$${id32}" } #=> this_is_an_example_id_32 ``` -------------------------------- ### Example Usage of str_leftpad Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_leftpad Demonstrates how to use the str_leftpad function to pad a string. The padding character is a dot, and the target width is 5. ```terraform output "leftpad" { value = provider::corefunc::str_leftpad("foo", 5, ".") } #=> ..foo ``` -------------------------------- ### Example Usage of SHA-1 Base64 Hash Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_sha1_base64 Demonstrates how to use the `corefunc_hash_sha1_base64` data source to generate a Base64 encoded SHA-1 hash for the string 'hello world'. The expected output is provided as a comment. ```HCL data "corefunc_hash_sha1_base64" "sha1_base64" { string = "hello world" } #=> Kq5sNclPz7QV2+lfQIuc6R7oRu0= ``` -------------------------------- ### Example Usage of hash_argon2id_base64 Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_argon2id_base64 Demonstrates how to use the `hash_argon2id_base64` function within an OpenTofu configuration to hash a string with a salt and output the Base64 encoded result. ```hcl output "hash_argon2id_base64" { value = provider::corefunc::hash_argon2id_base64("hello world", "somesaltvalue") } #=> ZguOJZ3zSW6cQpvr2X611YqIzUaFHjDB3QO5RIwGbqQ= ``` -------------------------------- ### corefunc_str_endswith Data Source Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_endswith This example demonstrates how to use the `corefunc_str_endswith` data source to check if the string "hello world" ends with the suffix "world". The result is stored in the `value` attribute. ```HCL data "corefunc_str_endswith" "str_endswith" { input = "hello world" suffix = "world" } #=> true ``` -------------------------------- ### Example Usage of corefunc_str_leftpad Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_leftpad Demonstrates how to use the corefunc_str_leftpad data source to pad a string. The output shows the original string padded to a specified width with a given character. ```hcl data "corefunc_str_leftpad" "leftpad" { string = "abc" pad_width = 5 pad_char = "." } #=> ..abc ``` -------------------------------- ### Example Usage of json_to_toml Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/json_to_toml Demonstrates how to use the `json_to_toml` function within a Terraform configuration to read a JSON file and write its TOML equivalent. ```APIDOC ## Example Usage ```hcl locals { json_data = provider::corefunc::json_to_toml( file("${path.module}/hello.json") ) } resource "local_file" "toml_file" { content = local.json_data filename = "${path.module}/hello.toml" } ``` **Note:** Maps (like TOML, YAML, and JSON documents) do not maintain order by default. As such, there is no guarantee of order when converting between types. ``` -------------------------------- ### corefunc_str_startswith Data Source Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_startswith Demonstrates how to use the corefunc_str_startswith data source to check if a string begins with a given prefix. The `input` and `prefix` are required arguments, and the result is available in the `value` attribute. ```HCL data "corefunc_str_startswith" "str_startswith" { input = "hello world" prefix = "hello" } #=> true ``` -------------------------------- ### corefunc_homedir_get Data Source Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/homedir_get This data source retrieves the path to the current user's home directory. It maps to the `corefunc.Homedir()` Go method. ```terraform data "corefunc_homedir_get" "home" {} #=> /Users/me ``` -------------------------------- ### Install corefunc Provider for OpenTofu Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_sha1 This code block shows how to configure your OpenTofu project to use the corefunc provider. Ensure you run 'tofu init' after adding this to your configuration. ```terraform terraform { required_providers { corefunc = { source = "northwood-labs/corefunc" version = "2.3.0" } } } provider corefunc { # Configuration options } ``` -------------------------------- ### URL Decode Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/url_decode Use the data source to decode a URL-encoded string. The decoded value is available in the `value` attribute. ```HCL data "corefunc_url_decode" "url" { encoded_url = "mailto%3Aemail%3Fsubject%3Dthis%2Bis%2Bmy%2Bsubject" } #=> mailto:email?subject=this+is+my+subject ``` -------------------------------- ### Convert string to snake_case (version) Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_snake Converts a version string to snake_case. This example demonstrates handling of periods in the input string. ```HCL data "corefunc_str_snake" "v322" { string = "v3.2.2" } #=> v3_2_2 ``` -------------------------------- ### Example Usage of corefunc_json_to_toml Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/json_to_toml Demonstrates reading a JSON file and converting its content to TOML using the `corefunc_json_to_toml` data source, then writing the TOML content to a new file. ```HCL data "corefunc_json_to_toml" "json_to_toml" { json = file("${path.module}/hello.json") } resource "local_file" "toml_file" { content = data.corefunc_json_to_toml.json_to_toml.toml filename = "${path.module}/hello.toml" } ``` -------------------------------- ### str_base64_gunzip Function Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_base64_gunzip Example of how to use the str_base64_gunzip function within an OpenTofu output block to decode and decompress a gzipped Base64 string. ```hcl output "str" { value = provider::corefunc::str_base64_gunzip( "H4sIAAAAAAAA/8pIrVTISK3UUShPVS9KVSjJSFXIzc/LTk0tBgQAAP//qz+dmhoAAAA" ) } #=> hey hey, we're the monkees ``` -------------------------------- ### Get Home Directory Path Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/homedir_get Returns the path to the home directory of the current user. This function maps to the `corefunc.Homedir()` Go method. ```HCL output "homedir" { value = provider::corefunc::homedir_get() } ``` -------------------------------- ### SHA-512 Hash Generation Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_sha512 Demonstrates how to use the corefunc_hash_sha512 data source to generate the SHA-512 hash of the string 'hello world'. The resulting hash is then available in the `value` attribute. ```hcl data "corefunc_hash_sha512" "sha512" { input = "hello world" } #=> 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f ``` -------------------------------- ### Generate SHA-384 Hash Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_sha384 Example of using the hash_sha384 function to generate a SHA-384 hash for the string 'hello world'. The output shows the expected hash value. ```HCL output "sha384" { value = provider::corefunc::hash_sha384("hello world") } #=> fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd ``` -------------------------------- ### hash_sha3x512 Function Signature and Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_sha3x512 This snippet shows the signature of the hash_sha3x512 function and an example of how to use it to generate a SHA-3/512 hash. ```APIDOC ## hash_sha3x512(input string) string ### Description Generates the SHA-3/512-bit hash of a string. Returns a Base64 value instead of a hexadecimal string. ### Arguments * `input` (String) - Required - The string to generate a SHA-3/512-bit hash for. ### Example Usage ``` output "hash_sha3x512" { value = provider::corefunc::hash_sha3x512("hello world") } ``` ### Response Example ``` 840006653e9ac9e95117a15c915caab81662918e925de9e004f774ff82d7079a40d4d27b1b372657c61d46d470304c88c788b3a4527ad074d1dccbee5dbaa99a ``` ``` -------------------------------- ### Generate Platform-Compatible Lockfile Source: https://library.tf/providers/northwood-labs/corefunc/latest Use this command to create a lockfile compatible with multiple operating systems and architectures for team collaboration. Ensure Terraform or OpenTofu is installed. ```bash #!/usr/bin/env bash terraform providers lock \ -platform=darwin_amd64 \ -platform=darwin_arm64 \ -platform=linux_amd64 \ -platform=linux_arm \ -platform=linux_arm64 \ -platform=windows_amd64 \ ; ``` -------------------------------- ### str_byte_length Example Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_byte_length Demonstrates how to use the str_byte_length function with various string inputs, including single-byte, multi-byte UTF-8 characters, and mixed strings. ```APIDOC ## Example Usage ### Example 1: ASCII String ``` output "bytes1" { value = provider::corefunc::str_byte_length("abcde") } #=> 5 ``` ### Example 2: Single Multi-byte Character ``` output "bytes2" { value = provider::corefunc::str_byte_length("♫") } #=> 1 ``` ### Example 3: Single CJK Character ``` output "bytes3" { value = provider::corefunc::str_byte_length("界") } #=> 2 ``` ### Example 4: Mixed String with Japanese Characters and Symbol ``` output "bytes4" { value = provider::corefunc::str_byte_length("スター☆") } #=> 7 ``` ``` -------------------------------- ### Iterative String Replacements Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_iterative_replace Demonstrates how to use the corefunc_str_iterative_replace data source to perform multiple replacements on a string. The replacements are applied in the order they appear in the list. ```Terraform data "corefunc_str_iterative_replace" "replacements" { string = "This is a string for testing replacements. New Relic. Set-up." replacements = [ { old = "." new = "" }, { old = " " new = "_" }, { old = "-" new = "_" }, { old = "New Relic" new = "datadog" }, { old = "This" new = "this" }, { old = "Set-up" new = "setup" }, ] } #=> this_is_a_string_for_testing_replacements_datadog_setup ``` -------------------------------- ### Get Operating System with runtime_os Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/runtime_os Use the runtime_os function to output the operating system for which the provider was compiled. This can be useful for conditional logic or debugging. ```terraform output "os" { value = provider::corefunc::runtime_os() } #=> darwin #=> linux #=> windows ``` -------------------------------- ### hash_sha3x256 Function Signature and Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_sha3x256 This snippet shows the signature of the hash_sha3x256 function and an example of how to use it to generate a SHA-3/256-bit hash of a string in OpenTofu. ```APIDOC ## hash_sha3x256(input string) string ### Description Generates the SHA-3/256-bit hash of a string. This function maps to the `corefunc.HashSHA3x256()` Go method. ### Arguments #### Parameters - **input** (String) - Required - The string to generate an SHA-3/256-bit hash for. ### Example Usage ``` output "hash_sha3x256" { value = provider::corefunc::hash_sha3x256("hello world") } ``` ### Example Output ``` 644bcc7e564373040999aac89e7622f3ca71fba1d972fd94a31c3bfbf24e3938 ``` ``` -------------------------------- ### Iterative String Replacement Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_iterative_replace Demonstrates how to use the str_iterative_replace function to perform multiple replacements on a string, including changing punctuation, spaces, and specific words. ```HCL output "replacements" { value = provider::corefunc::str_iterative_replace( "This is a string for testing replacements. New Relic. Set-up.", [ { old = "." new = "" }, { old = " " new = "_" }, { old = "-" new = "_" }, { old = "New Relic" new = "datadog" }, { old = "This" new = "this" }, { old = "Set-up" new = "setup" }, ], ) } #=> this_is_a_string_for_testing_replacements_datadog_setup ``` -------------------------------- ### Example Usage of hash_argon2id Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_argon2id Demonstrates how to use the hash_argon2id function within an OpenTofu output block to generate and display an Argon2id hash for a given input and salt. ```hcl output "hash_argon2id" { value = provider::corefunc::hash_argon2id("hello world", "somesaltvalue") } ``` -------------------------------- ### Example plan output with errors Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/env_ensure This shows the expected output during a Terraform plan when environment variables fail the `corefunc_env_ensure` checks, either by being undefined or not matching the specified pattern. ```shell AWS_DEFAULT_REGION="us-east-1" AWS_VAULT="dev" terraform plan ``` ```log data.corefunc_env_ensure.aws_vault: Reading... data.corefunc_env_ensure.aws_pager: Reading... data.corefunc_env_ensure.aws_default_region: Reading... data.corefunc_env_ensure.aws_default_region: Read complete after 0s [name=AWS_DEFAULT_REGION] Changes to Outputs: + aws_default_region_value = "us-east-1" You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure. ╵ │ Error: Problem with Environment Variable │ │ with data.corefunc_env_ensure.aws_pager, │ on data-source-AWS_PAGER.tf line 4, in data "corefunc_env_ensure" "aws_pager": │ 4: data "corefunc_env_ensure" "aws_pager" { │ │ environment variable AWS_PAGER is not defined ╵ ╵ │ Error: Problem with Environment Variable │ │ with data.corefunc_env_ensure.aws_vault, │ on data-source-AWS_VAULT.tf line 4, in data "corefunc_env_ensure" "aws_vault": │ 4: data "corefunc_env_ensure" "aws_vault" { │ │ environment variable AWS_VAULT does not match pattern (non)?prod$ ╵ ``` -------------------------------- ### Generate MD5 Hash Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_md5 Use the hash_md5 function to generate an MD5 hash for a string. This example demonstrates its usage within an OpenTofu output block. ```terraform output "md5" { value = provider::corefunc::hash_md5("hello world") } #=> 5eb63bbbe01eeed093cb22bb8f5acdc3 ``` -------------------------------- ### Compare Two Specific Timestamps Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/time_compare This example demonstrates comparing two fixed timestamp strings using the time_compare function and outputs the numerical result. ```HCL output "timecmp1" { value = provider::corefunc::time_compare("2006-01-02T15:04:05Z", "2007-01-02T15:04:05Z") } ``` -------------------------------- ### Get CPU Architecture Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/runtime_cpuarch Use this data source to retrieve the CPU architecture. This is useful for conditional logic or dynamic configuration based on the execution environment. ```HCL data "corefunc_runtime_cpuarch" "arch" {} #=> arm64 ``` -------------------------------- ### time_compare Usage Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/time_compare Demonstrates how to use the time_compare function within a Terraform lifecycle postcondition to check if a certificate will expire within 30 days, and also shows a direct usage for outputting comparison results. ```APIDOC lifecycle { postcondition { condition = provider::corefunc::time_compare( timestamp(), timeadd(self.expiration_timestamp, "-720h") ) < 0 error_message = "Certificate will expire in less than 30 days." } } output "timecmp1" { value = provider::corefunc::time_compare("2006-01-02T15:04:05Z", "2007-01-02T15:04:05Z") } ``` -------------------------------- ### Generate SHA-1 Hash using hash_sha1 Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_sha1 This example demonstrates how to use the `hash_sha1` function from the corefunc provider to generate a SHA-1 hash of a given string. The output will be the SHA-1 hash value. ```terraform output "sha1" { value = provider::corefunc::hash_sha1("hello world") } #=> 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed ``` -------------------------------- ### Convert string already in camelCase Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_camel This example shows that the data source correctly handles strings that are already in camelCase format, returning them unchanged. ```terraform data "corefunc_str_camel" "test_from_camel" { string = "TestFromCamel" } #=> testFromCamel ``` -------------------------------- ### Example Usage of Base64Gunzip Data Source Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_base64_gunzip Use this data source to decode a gzipped Base64 string. The input is the `gzipped_base64` string, and the output is available in the `value` attribute after decompression. ```terraform data "corefunc_str_base64_gunzip" "str" { gzipped_base64 = "H4sIAAAAAAAA/8pIrVTISK3UUShPVS9KVSjJSFXIzc/LTk0tBgQAAP//qz+dmhoAAAA" } #=> hey hey, we're the monkees ``` -------------------------------- ### Get Number of CPU Cores Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/runtime_numcpus This snippet demonstrates how to use the runtime_numcpus function to retrieve the number of logical CPU cores and output it. It maps to the runtime.NumCPU() Go method. ```terraform output "nproc" { value = provider::corefunc::runtime_numcpus() } ``` -------------------------------- ### corefunc_str_contains Data Source Example Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_contains Demonstrates how to use the corefunc_str_contains data source to check if 'hello world' contains the substring 'ello'. The result is a boolean value. ```terraform data "corefunc_str_contains" "str_contains" { input = "hello world" substr = "ello" } #=> true ``` -------------------------------- ### Generate MD5 Hash (Base64) Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_md5_base64 Use this data source to compute the MD5 hash of a string and get the result as a Base64 encoded string. The input string is provided via the `input` argument. ```hcl data "corefunc_hash_md5_base64" "md5_base64" { input = "hello world" } #=> XrY7u+Ae7tCTyyK7j1rNww== ``` -------------------------------- ### Convert complex string to CONSTANT_CASE Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_constant Illustrates the conversion of a complex string with various punctuation and symbols, such as 'This is [an] {example}$${id32}.', to 'THIS_IS_AN_EXAMPLE_ID_32' using the `corefunc_str_constant` data source. This handles a wide range of special characters. ```HCL data "corefunc_str_constant" "this_is_an_example" { string = "This is [an] {example}$${id32}." } #=> THIS_IS_AN_EXAMPLE_ID_32 ``` -------------------------------- ### hash_sha384 Function Signature and Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_sha384 The hash_sha384 function takes a single string argument and returns its SHA-2/384-bit hash. The example demonstrates how to use this function within an OpenTofu configuration to output the hash of a given string. ```APIDOC ## hash_sha384(input string) string ### Description Generates the SHA-2/384-bit hash of a string. This function maps to the `corefunc.HashSHA384()` Go method. ### Arguments #### Path Parameters - **input** (String) - Required - The string to generate a SHA-2/384-bit hash for. ### Example Usage ```hcl output "sha384" { value = provider::corefunc::hash_sha384("hello world") } # Expected Output: fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd ``` ``` -------------------------------- ### Convert TOML file to JSON file Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/toml_to_json Reads a TOML file and converts its content to a JSON string, which is then written to a new JSON file. This example demonstrates reading a TOML file using `file()` and converting it with `toml_to_json`. ```terraform locals { toml_data = provider::corefunc::toml_to_json( file("${path.module}/hello.toml") ) } resource "local_file" "json_file" { content = local.toml_data filename = "${path.module}/hello.json" } ``` -------------------------------- ### str_contains Function Signature and Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_contains This snippet details the signature, arguments, and an example of how to use the str_contains function in a Terraform configuration. ```APIDOC ## str_contains ### Description Checks if a string contains a given substring. This function is identical to the built-in `strcontains` function available since Terraform 1.3 and can be used with OpenTofu and Terraform versions 1.0 and later. ### Signature ``` str_contains(input string, substr string) bool ``` ### Arguments #### Parameters - **input** (String) - Required - The string to check. - **substr** (String) - Required - The substring to look for. ### Example Usage ``` output "str_contains" { value = provider::corefunc::str_contains("hello world", "ello") } #=> true ``` ``` -------------------------------- ### str_endswith Function Signature and Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_endswith This snippet details the signature of the `str_endswith` function and provides an example of its usage within a Terraform configuration. ```APIDOC ## str_endswith(input string, suffix string) bool ### Description Takes a string to check and a suffix string, and returns true if the string ends with that exact suffix. This is identical to the built-in `endswith` function which was added in Terraform 1.3. ### Arguments - `input` (String) - Required - The string to check. - `suffix` (String) - Required - The suffix to check for. ### Example Usage ``` output "str_endswith" { value = provider::corefunc::str_endswith("hello world", "world") } #=> true ``` ``` -------------------------------- ### Configure corefunc Provider for OpenTofu Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_hmac_sha256 This snippet shows how to configure the `corefunc` provider in your OpenTofu configuration. Run `tofu init` after adding this to your configuration. ```hcl terraform { required_providers { corefunc = { source = "northwood-labs/corefunc" version = "2.3.0" } } } provider corefunc { # Configuration options } ``` -------------------------------- ### hash_hmac_base64sha256 Function Signature and Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_hmac_base64sha256 This snippet shows the signature of the hash_hmac_base64sha256 function and an example of how to use it to generate a Base64 encoded HMAC hash. ```APIDOC ## hash_hmac_base64sha256(input string, key string) string ### Description Generates the SHA-2/256-bit HMAC hash of a string with its associated key value. Returns a Base64 value instead of a hexadecimal string. ### Arguments * `input` (String) - Required - The string to generate the SHA-2/256-bit HMAC hash for. * `key` (String) - Required - A secret value to provide additional entropy in the calculation. ### Example Usage ```terraform output "hash_hmac_base64sha256" { value = provider::corefunc::hash_hmac_base64sha256("hello world", "secretkey") } ``` ### Example Output ``` rmzSYF1iIxZWTR92v8DAT4nZ+vsU9Fs+GMKj4ove8p0= ``` ``` -------------------------------- ### Generate Base64 SHA-512 Hash Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_sha512_base64 This snippet demonstrates how to use the hash_sha512_base64 function within an OpenTofu configuration to generate a Base64 encoded SHA-512 hash of the string 'hello world'. ```hcl output "sha512_base64" { value = provider::corefunc::hash_sha512_base64("hello world") } #=> MJ7MSJwS1utMxA9QyQLytNDtd+5RGnx6m808qG1M2G+YndNbxf9JlnDaNCVbRbDP2DDoH2Bdz33FVC6TrpzXbw== ``` -------------------------------- ### Convert string to snake_case (camel case) Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/str_snake Converts a camelCase string to snake_case. This example shows the transformation of uppercase letters to lowercase with underscores. ```HCL data "corefunc_str_snake" "test_from_camel" { string = "TestFromCamel" } #=> test_from_camel ``` -------------------------------- ### corefunc_runtime_os Data Source Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/runtime_os Returns the operating system for which the provider was compiled. This data source maps to the `runtime.GOOS` Go property. ```APIDOC ## corefunc_runtime_os (Data Source) ### Description Returns the operating system for which the provider was compiled. Generally, this represents the current system. Maps to the `runtime.GOOS` Go property, which can be used in Terratest. ### Example Usage ``` data "corefunc_runtime_os" "os" {} #=> linux ``` ### Schema #### Read-Only * `value` (String) - Returns the operating system for which the provider was compiled. ``` -------------------------------- ### str_startswith function usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_startswith Demonstrates how to use the str_startswith function to check if a string begins with a prefix. Returns true if the condition is met. ```HCL output "str_startswith" { value = provider::corefunc::str_startswith("hello world", "hello") } #=> true ``` -------------------------------- ### Generate Base64 MD5 Hash Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/hash_md5_base64 Demonstrates how to use the hash_md5_base64 function to generate a Base64 encoded MD5 hash for the string 'hello world'. The output is captured in a Terraform output variable. ```terraform output "md5_base64" { value = provider::corefunc::hash_md5_base64("hello world") } #=> XrY7u+Ae7tCTyyK7j1rNww== ``` -------------------------------- ### runtime_os() string Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/runtime_os Returns the operating system for which the provider was compiled. This function maps to the `runtime.GOOS` Go property and can be utilized within Terratest for environment-specific logic. ```APIDOC ## runtime_os() ### Description Returns the operating system for which the provider was compiled. Generally, this represents the current system. Maps to the `runtime.GOOS` Go property, which can be used in Terratest. ### Signature ``` string ``` ### Example Usage ``` output "os" { value = provider::corefunc::runtime_os() } #=> darwin #=> linux #=> windows ``` ``` -------------------------------- ### Convert String to PascalCase Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_pascal Demonstrates converting a string with numbers and special characters to PascalCase. The `use_acronym_caps` argument is not explicitly set, defaulting to its behavior. ```HCL output "test_with_number" { value = provider::corefunc::str_pascal("test with number -123.456") } #=> TestWithNumber123456 ``` -------------------------------- ### Generate SHA-384 Base64 Hash Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_sha384_base64 Use this data source to compute the SHA-384 hash of a string and get the result in Base64 format. The `input` argument is required. ```terraform data "corefunc_hash_sha384_base64" "sha384_base64" { input = "hello world" } #=> /b2OdaZ/KfcBpOBAOF4uI5hjA+oQI5IRr5B/y7g1eLPkF8txzmRu/QgZ3YwIjeG9 ``` -------------------------------- ### corefunc_homedir_get Data Source Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/homedir_get Returns the path to the home directory of the current user. This data source maps to the `corefunc.Homedir()` Go method, making it usable within Terratest. ```APIDOC ## corefunc_homedir_get (Data Source) Returns the path to the home directory of the current user. Maps to the `corefunc.Homedir()` Go method, which can be used in Terratest. ### Example Usage ```hcl data "corefunc_homedir_get" "home" {} # Output: /Users/me output "home_dir" { value = data.corefunc_homedir_get.home.value } ``` ### Schema #### Read-Only Attributes * **value** (String) - The value of the home directory. ``` -------------------------------- ### net_cidr_contains Function Signature and Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/net_cidr_contains This snippet shows the signature of the net_cidr_contains function and an example of its usage in an output block. It demonstrates how to check if '192.168.2.1' is contained within '192.168.2.0/20'. ```APIDOC ## net_cidr_contains(containing_cidr string, contained_ip_or_cidr string) bool ### Description Determines whether or not a given IP address, or an address prefix given in CIDR notation, is within a given IP network address prefix. Both arguments must belong to the same address family, either IPv4 or IPv6. A family mismatch will result in an error. ### Arguments 1. `containing_cidr` (String) - A CIDR range to check as a containing range. 2. `contained_ip_or_cidr` (String) - An IP address or CIDR range to check as a contained range. ### Example Usage ``` output "cidr" { value = provider::corefunc::net_cidr_contains("192.168.2.0/20", "192.168.2.1") } #=> true ``` ``` -------------------------------- ### Convert JSON file to TOML file using json_to_toml Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/json_to_toml This snippet demonstrates how to read a JSON file and convert its content to a TOML string using the json_to_toml function. The resulting TOML string is then written to a new file. This requires the corefunc provider to be configured. ```terraform locals { json_data = provider::corefunc::json_to_toml( file("${path.module}/hello.json") ) } resource "local_file" "toml_file" { content = local.json_data filename = "${path.module}/hello.toml" } ``` -------------------------------- ### Scrypt Hashing Parameters Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_scrypt_base64 Configuration parameters for the Scrypt algorithm, balancing security and performance. These include CPU/memory cost (N), block size (r), parallelization (p), and key length. ```plaintext N = 32768 (CPU/memory cost parameter) r = 8 (block size parameter) p = 1 (parallelization parameter) Key Length = 32 bytes ``` -------------------------------- ### homedir_expand Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/homedir_expand Replaces the '~' character in a path with the current user's home directory. This function maps to the `corefunc.HomedirExpand()` Go method. ```APIDOC ## homedir_expand (function) Replaces the ~ character in a path with the current user's home directory. Maps to the `corefunc.HomedirExpand()` Go method, which can be used in Terratest. ### Signature ``` Copy homedir_expand(path string) string ``` ### Arguments 1. `path` (String) - The path to expand. ### Example Usage ``` Copy output "homedir" { value = provider::corefunc::homedir_expand("~/.aws") } ``` ``` -------------------------------- ### str_iterative_replace Function Signature and Usage Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_iterative_replace This snippet details the signature of the str_iterative_replace function and provides an example of its usage within a Terraform configuration, demonstrating how to perform a series of replacements on a string. ```APIDOC ## str_iterative_replace(str string, replacements list of map of string) string ### Description Performs a series of replacements against a string. Allows a Terraform module to accept a set of replacements from a user. Maps to the `corefunc.StrIterativeReplace()` Go method. ### Arguments * **str** (String) - Required - The string upon which replacements should be applied. * **replacements** (List of Map of String) - Required - A list of maps. Each map has an `old` and `new` key. `old` represents the existing string to be replaced, and `new` represents the replacement string. ### Example Usage ```terraform output "replacements" { value = provider::corefunc::str_iterative_replace( "This is a string for testing replacements. New Relic. Set-up.", [ { old = "." new = "" }, { old = " " new = "_" }, { old = "-" new = "_" }, { old = "New Relic" new = "datadog" }, { old = "This" new = "this" }, { old = "Set-up" new = "setup" }, ], ) } # Expected Output: # this_is_a_string_for_testing_replacements_datadog_setup ``` ``` -------------------------------- ### Generate Bcrypt Hash Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_bcrypt Use this data source to generate a Bcrypt hash for a given input string. Specify the 'cost' parameter to control the computational effort. The default cost is 10. ```HCL data "corefunc_hash_bcrypt" "hash_bcrypt" { input = "hello world" cost = 10 } #=> $2a$10$SOMESALTVALUEu1pYx0pG7xO6dXJv1bG8y9qzE6jFzW8u9K5eV6Zy ``` -------------------------------- ### homedir_get Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/homedir_get Returns the path to the home directory of the current user. Maps to the `corefunc.Homedir()` Go method, which can be used in Terratest. ```APIDOC ## homedir_get (function) ### Description Returns the path to the home directory of the current user. ### Signature ``` homedir_get() string ``` ### Example Usage ``` output "homedir" { value = provider::corefunc::homedir_get() } ``` ``` -------------------------------- ### Get Number of CPU Cores Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/runtime_numcpus Use this data source to retrieve the number of logical CPU cores. This value can be used to dynamically configure resources based on available processing power. ```terraform data "corefunc_runtime_numcpus" "count" {} #=> 12 ``` -------------------------------- ### Argon2id Hashing Configuration Parameters Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/data-sources/hash_argon2id These are the recommended configuration parameters for the Argon2id algorithm, balancing security and performance. ```plaintext Time = 1 Memory = 64 MB Threads = All Key Length = 32 bytes ``` -------------------------------- ### Count Bytes in ASCII String Source: https://library.tf/providers/northwood-labs/corefunc/latest/docs/functions/str_byte_length Demonstrates counting bytes for a simple ASCII string. ```HCL output "bytes1" { value = provider::corefunc::str_byte_length("abcde") } #=> 5 ```