@@ -21,6 +21,7 @@ package cloudstack
2121
2222import (
2323 "fmt"
24+ "regexp"
2425 "testing"
2526
2627 "github.com/apache/cloudstack-go/v2/cloudstack"
@@ -274,6 +275,26 @@ func TestAccCloudStackInstance_importProject(t *testing.T) {
274275 })
275276}
276277
278+ func TestAccCloudStackInstance_userData (t * testing.T ) {
279+ resource .Test (t , resource.TestCase {
280+ PreCheck : func () { testAccPreCheck (t ) },
281+ Providers : testAccProviders ,
282+ CheckDestroy : testAccCheckCloudStackInstanceDestroy ,
283+ ExternalProviders : map [string ]resource.ExternalProvider {
284+ "random" : {
285+ VersionConstraint : ">= 3.6.0" ,
286+ Source : "hashicorp/random" ,
287+ },
288+ },
289+ Steps : []resource.TestStep {
290+ {
291+ Config : testAccCloudStackInstance_userData ,
292+ ExpectError : regexp .MustCompile ("User data has exceeded configurable max length" ),
293+ },
294+ },
295+ })
296+ }
297+
277298func testAccCheckCloudStackInstanceExists (
278299 n string , instance * cloudstack.VirtualMachine ) resource.TestCheckFunc {
279300 return func (s * terraform.State ) error {
@@ -525,3 +546,33 @@ resource "cloudstack_instance" "foobar" {
525546 zone = cloudstack_network.foo.zone
526547 expunge = true
527548}`
549+
550+ const testAccCloudStackInstance_userData = `
551+ resource "random_bytes" "string" {
552+ length = 32768
553+ }
554+
555+ resource "cloudstack_network" "foo" {
556+ name = "terraform-network"
557+ display_text = "terraform-network"
558+ cidr = "10.1.1.0/24"
559+ network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
560+ zone = "Sandbox-simulator"
561+ }
562+
563+ resource "cloudstack_instance" "foobar" {
564+ name = "terraform-test"
565+ display_name = "terraform-test"
566+ service_offering= "Small Instance"
567+ network_id = cloudstack_network.foo.id
568+ template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
569+ zone = cloudstack_network.foo.zone
570+ expunge = true
571+ user_data = <<-EOFTF
572+ #!/bin/bash
573+
574+ echo <<EOF
575+ ${random_bytes.string.base64}
576+ EOF
577+ EOFTF
578+ }`
0 commit comments