Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 在terraform中创建AWS实例时如何使用用户_数据url?_Amazon Web Services_Terraform_Instance_User Data - Fatal编程技术网

Amazon web services 在terraform中创建AWS实例时如何使用用户_数据url?

Amazon web services 在terraform中创建AWS实例时如何使用用户_数据url?,amazon-web-services,terraform,instance,user-data,Amazon Web Services,Terraform,Instance,User Data,地形版本=0.12 data "template_file" "user_data" { template = file("${path.module}/userdata.sh") } resource "aws_instance" "bespin-ec2-web-a" { ami = "ami-0bea7fd38fabe821a" instance_type = "t2.micro" vpc_security_group_ids = [aws_security_group.b

地形版本=0.12

data "template_file" "user_data" {
  template = file("${path.module}/userdata.sh")
}

resource "aws_instance" "bespin-ec2-web-a" {
  ami = "ami-0bea7fd38fabe821a"
  instance_type = "t2.micro"
  vpc_security_group_ids = [aws_security_group.bespin-sg.id]
  subnet_id = aws_subnet.bespin-subnet-public-a.id
  associate_public_ip_address = true
  tags = {
    Name = "bespin-ec2-web-a"
  }
  user_data = data.template_file.user_data.rendered
}
我想将用户_数据上传到S3,并通过调用URL来使用它。 我能做什么


但是,如果要为EC2实例指定要使用的用户数据,那么在S3中使用sh文件是不可能的,这还不是100%清楚要实现什么

需要将userdata内容直接指定给aws_实例地形资源

EC2/userdata 然后使用上传到S3

resource "aws_s3_bucket_object" "object" {
  bucket = "your_s3_bucket_name"
  key    = "userdata.sh"
  source = "your_local_userdata_sh_path"

  etag = "${filemd5("your_local_userdata_sh_path")}"
}
模板资源中的URL
这是不可能的。模板文件需要在本地计算机中。如果共享UsSerDAT.SH是目标,那么考虑使用S3保险丝在机器中安装S3。

不清楚你想要达到什么。是否要生成包含呈现的userdata.sh的文件并将其上载到S3?或者您想从terraform脚本引用S3中的模板文件?或者您只需要知道如何使用Terraform将文件上载到S3吗?将userdata.sh文件上载到S3。我想通过调用terraform上传的userdata.sh文件的URL来运行脚本。不清楚,我想通过调用terraform的URL来运行脚本。请明确谁在哪里。什么叫URL?无法直接调用或执行URL您的意思是下载URL指向的文件,然后运行它吗?请具体说明您想要实现的目标。我想将本地用户_数据文件上载到S3并使用它。
resource "aws_instance" "this" {
  ami = "${local.ami_this_id}"
  instance_type = "${var.instance_type}"
  subnet_id = "${var.subnet_id}"
  vpc_security_group_ids = "${var.security_group_ids}"
  key_name = "${aws_key_pair.this.key_name}"
  iam_instance_profile = "${var.ec2_instance_profile_id}"

  user_data = data.template_file.user_data.rendered   # <----- Specify userdata content

  root_block_device {
    volume_type = "${var.root_volume_type}"
    volume_size = "${var.root_volume_size}"
    delete_on_termination = true
  }
}
resource "local_file" "userdata_sh" {
  content  = data.template_file.user_data.rendered
  filename = "your_local_userdata_sh_path"
}
resource "aws_s3_bucket_object" "object" {
  bucket = "your_s3_bucket_name"
  key    = "userdata.sh"
  source = "your_local_userdata_sh_path"

  etag = "${filemd5("your_local_userdata_sh_path")}"
}