mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
* Don't Base64-encode EC2 userdata if it is already Base64 encoded The user data may be Base64 encoded already - for example, if it has been generated by a template_cloudinit_config resource. * Add encoded user_data to aws_instance acceptance test
This commit is contained in:
parent
c86c594b23
commit
1c662c2bc4
@ -964,8 +964,16 @@ func buildAwsInstanceOpts(
|
|||||||
Name: aws.String(d.Get("iam_instance_profile").(string)),
|
Name: aws.String(d.Get("iam_instance_profile").(string)),
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.UserData64 = aws.String(
|
user_data := d.Get("user_data").(string)
|
||||||
base64.StdEncoding.EncodeToString([]byte(d.Get("user_data").(string))))
|
|
||||||
|
// Check whether the user_data is already Base64 encoded; don't double-encode
|
||||||
|
_, base64DecodeError := base64.StdEncoding.DecodeString(user_data)
|
||||||
|
|
||||||
|
if base64DecodeError == nil {
|
||||||
|
opts.UserData64 = aws.String(user_data)
|
||||||
|
} else {
|
||||||
|
opts.UserData64 = aws.String(base64.StdEncoding.EncodeToString([]byte(user_data)))
|
||||||
|
}
|
||||||
|
|
||||||
// check for non-default Subnet, and cast it to a String
|
// check for non-default Subnet, and cast it to a String
|
||||||
subnet, hasSubnet := d.GetOk("subnet_id")
|
subnet, hasSubnet := d.GetOk("subnet_id")
|
||||||
|
@ -825,6 +825,7 @@ resource "aws_instance" "foo" {
|
|||||||
subnet_id = "${aws_subnet.foo.id}"
|
subnet_id = "${aws_subnet.foo.id}"
|
||||||
associate_public_ip_address = true
|
associate_public_ip_address = true
|
||||||
tenancy = "dedicated"
|
tenancy = "dedicated"
|
||||||
|
user_data = "3dc39dda39be1205215e776bad998da361a5955d"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user