Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

Why terraform generate the same timestamp by using `formatdate` function?

https://www.terraform.io/docs/configuration/functions/formatdate.html Th above is the doc of this function, I used this to append a timestamp on a name of the SageMaker batch transform job, which will be triggered from a stepfunction state machine:

locals {
  timestamp = formatdate("YYYYMMDDhhmmss", timestamp())
}

in stepfunction terraform file:

  definition = templatefile("stepfuntion.json",
    {
      xxx
      timestamp      = local.timestamp
)

in the "stepfuntion.json":

{...
          "TransformJobName": "jobname-${timestamp}",
  
          }
      },
        "End": true
      }
    }
  }

Specifically, the jobname is defined in "TransformJobName": "jobname-${timestamp}", I applied terraform twice, 10am and 11am, but the second time it generated the same timestamp as the first time, am I missing something here? I thought this function will generate the real-time timestamp. I've been struggling for a whole morning now, many thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

works perfectly fine, I used your code as described in the question with the template file stepfuction.json

        # main.tf
        locals {
        current  = formatdate("YYYYMMDDhhmmss",timestamp())
    }
    output "tempasda"{
    value = templatefile("task.json", {timestamp = local.current, model_name="mymodel"})
    }

and the corresponding output

    $ terraform  apply -auto-approve |grep TransformJobName
            "TransformJobName": "jobname-20210106134614",

    $ terraform  apply -auto-approve |grep TransformJobName
            "TransformJobName": "jobname-20210106134615",

    $ terraform  apply -auto-approve |grep TransformJobName
            "TransformJobName": "jobname-20210106134617",
            
    $ terraform  apply -auto-approve |grep TransformJobName
            "TransformJobName": "jobname-20210106134618",

terrform version tested with 0.13.x and 0.14.x


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...