Terraform timestamp() to numbers only string

前端 未结 3 937
难免孤独
难免孤独 2021-02-08 12:29

The timestamp() function in the interpolation syntax will return an ISO 8601 formatted string, which looks like this 2019-02-06T23:22:28Z. However, I want to have a

3条回答
  •  生来不讨喜
    2021-02-08 13:03

    This answer just shows an example of @BMW's answer which wasn't obvious to someone that's new to Terraform.

    $ cat main.tf
    locals {
      timestamp = "${timestamp()}"
      timestamp_sanitized = "${replace("${local.timestamp}", "/[-| |T|Z|:]/", "")}"
    
    }
    
    output "timestamp" {
      value = "${local.timestamp_sanitized}"
    }
    

    Example runs

    Run #1:

    $ terraform apply
    
    Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
    
    Outputs:
    
    timestamp = 20190221205825
    

    Run #2:

    $ terraform apply
    
    Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
    
    Outputs:
    
    timestamp = 20190221205839
    

提交回复
热议问题