此代码用于在 terraform 0.11 上运行没有任何问题。我之前多次使用它来创建 AWS EC2 实例。
以下是/data/CreateBasionHost.tf 文件的内容
Sub Coxxxxxxauto()
Dim MyPath As String
Dim MyPath2 As String
Dim MyFile As String
Dim LatestFile As String
Dim LatestDate As Date
Dim LMD As Date
Dim xWB As Workbook
Dim DateStamp As String
Dim FilePath1 As String
Dim Path1 As String
Dim vJc As Variant
Dim vItem As Variant
Dim Jc1 As String
Dim Jc2 As String
Jc1 = "\\C:\Documents\Newsletters\Eg1****2018"
Jc2 = "\\C:\Documents\Newsletters\Eg2****2018"
vJc = Array(Jc1, Jc2)
DateStamp = "US_" & Format(Date - 1, "YYYY-MM-DD")
For Each vItem In vJc
'Make sure that the path ends in a backslash
If Right(vItem, 1) <> "\" Then MyPath = vItem & "\"
'Get the first Excel file from the folder
MyFile = Dir(MyPath & "*.csv", vbNormal)
'If no files were found, exit the sub
If Len(MyFile) = 0 Then
MsgBox "No files were found...", vbExclamation
Exit Sub
End If
'Loop through each Excel file in the folder
Do While Len(MyFile) > 0
'Assign the date/time of the current file to a variable
LMD = FileDateTime(MyPath & MyFile)
'If the date/time of the current file is greater than the latest
'recorded date, assign its filename and date/time to variables
If LMD > LatestDate Then
LatestFile = MyFile
LatestDate = LMD
End If
'Get the next Excel file from the folder
MyFile = Dir
Loop
'Open the latest file
Workbooks.Open MyPath & LatestFile # Loop starts here on second run
Application.DisplayAlerts = False
Sheets(1).Select
Sheets(1).Copy
Application.DisplayAlerts = False
'On Error GoTo errHandler
ActiveWorkbook.SaveAs Filename:=vItem & "\" & _
Right(vItem, Len(vItem) - InStrRev(vItem, "_")) & "_" & _
DateStamp, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.ScreenUpdating = False
For Each xWB In Application.Workbooks
If Not (xWB Is Application.ThisWorkbook) Then
xWB.Close
End If
Next
Application.ScreenUpdating = True
'MsgBox "Files Published. Check for adjustments.", vbOKOnly, "Spot-On: Alert "
Next vItem
errHandler:
MsgBox "Existing file Found", vbCritical, "Wait a Minute...We've been here before"
For Each xWB In Application.Workbooks
If Not (xWB Is Application.ThisWorkbook) Then
xWB.Close
End If
Next
End Sub
我使用pain yum 命令来更新Linux 服务器。以下是内容 /data/BasionHost.tpl
data "template_file" "BasionHost_data" {
template = "${file("${path.module}/BasionHost.tpl")}"
}
resource "aws_instance" "BasionHost" {
depends_on = ["aws_vpc_dhcp_options_association.dns_resolver"]
depends_on = ["aws_directory_service_directory.MyActiveDirectory"]
depends_on = ["aws_vpc_dhcp_options.DhcpOptionforAD"]
depends_on = ["aws_iam_instance_profile.BackupInst_profile"]
ami = "${var.CENTOS7_CUSTOMIZED_AMI}"
instance_type = "${var.NAT_INST_TYPE}"
iam_instance_profile = "${aws_iam_instance_profile.BackupInst_profile.name}"
associate_public_ip_address = "true"
source_dest_check = "false"
disable_api_termination = "false"
subnet_id = "${aws_subnet.PublicSubnetB.id}"
availability_zone = "${var.AWS_REGION}b"
vpc_security_group_ids = ["${aws_default_security_group.default.id}"]
key_name = "${var.NAT_INST_KEY_NAME}"
private_ip = "${var.BASIONHOST_PRIVATE_IP}"
user_data = "${data.template_file.BasionHost_data.rendered}"
}
但现在此代码不适用于 terraform 0.14。 我试图阅读此 [Terraform 链接] (https://www.terraform.io/docs/configuration/functions/templatefile.html?_ga=2.248470019.549632933.1609205994-820700225.1609205994)
提到 terraform 网站使用 templatefile 功能。 但是我无法实现相同的目标,示例不是很清楚。 有人可以指导我吗?
答案 0 :(得分:1)
我尝试使用 Terraform v0.14.3 使用 official CentOS 7 AMI复制该问题。由于template_file
,没有任何问题。相反,在我的测试中,问题是由 #! /bin/bash
中的空间引起的,导致用户数据未执行。所以解决方案是将其删除:
#!/bin/bash
yum update -y
ln -s /usr/bin/clear /usr/bin/cls