Terraform:如何创建一个S3 bucket,其中包含代码执行时间戳的对象



伙计们。

我正在尝试创建一个S3 bucket,其中包含代码执行时间戳的对象。换句话说,代码必须创建一个S3桶,在S3桶中创建对象,并创建代码在对象中执行的时间戳。对象必须包含时间戳。

我的代码是这样的:

resource "aws_s3_bucket" "my_terraform_bucket" {
bucket = "shaanu-bucket234589545"
acl    = "private"

provisioner "remote-exec" {
inline = [
" echo timestamp(%Y-%m-%d %H:%M:%S) > /home/shaanu/remote-exec/file12.txt 
/home/shaanu/remote-exec/file22.txt" 
]
}
connection {
type = "ssh"
user = "ubuntu"
host = "self.public_ip"
}

}

但我得到了这个结果:

aws_s3_bucket.my_terraform_bucket: Creating...
aws_s3_bucket.my_terraform_bucket: Provisioning with 'remote-exec'...
aws_s3_bucket.my_terraform_bucket (remote-exec): Connecting to remote host via SSH...
aws_s3_bucket.my_terraform_bucket (remote-exec):   Host: self.public_ip
aws_s3_bucket.my_terraform_bucket (remote-exec):   User: ubuntu
aws_s3_bucket.my_terraform_bucket (remote-exec):   Password: false
aws_s3_bucket.my_terraform_bucket (remote-exec):   Private key: false
aws_s3_bucket.my_terraform_bucket (remote-exec):   Certificate: false
aws_s3_bucket.my_terraform_bucket (remote-exec):   SSH Agent: false
aws_s3_bucket.my_terraform_bucket (remote-exec):   Checking Host Key: false
aws_s3_bucket.my_terraform_bucket (remote-exec):   Target Platform: unix
aws_s3_bucket.my_terraform_bucket (remote-exec): Connecting to remote host via SSH...
aws_s3_bucket.my_terraform_bucket (remote-exec):   Target Platform: unix
aws_s3_bucket.my_terraform_bucket (remote-exec): Connecting to remote host via SSH...Error: remote-exec provisioner error
│
│   with aws_s3_bucket.my_terraform_bucket,
│   on remote-exec-provisioner.tf line 6, in resource "aws_s3_bucket" "my_terraform_bucket":
│    6:   provisioner "remote-exec" {
│
│ timeout - last error: dial tcp: lookup self.public_ip on XXX.XXX.1.1:XX: no such host

我确信我有几件事做得不对。有人能帮帮我吗?

谢谢。

您应该使用aws_s3_bucket_object将文件上传到新创建的对象。CCD_ 1不适用于此。

相关内容

  • 没有找到相关文章

最新更新