Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloud_init argument to image creation #188

Merged
merged 7 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .web-docs/components/builder/linode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ can also be supplied to override the typical auto-generated key:
Please note that when you create a new Linode instance with a private image, you will
be required to setup a new root password.

- `cloud_init` (bool) - Whether the newly created image supports cloud-init.

#### Interface

This section outlines the fields configurable for a single interface object.
Expand Down
5 changes: 3 additions & 2 deletions builder/linode/builder_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ const testBuilderAccBasic = `
"type": "linode",
"region": "us-ord",
"instance_type": "g6-nanode-1",
"image": "linode/alpine3.9",
"ssh_username": "root"
"image": "linode/debian11",
"ssh_username": "root",
"cloud_init": true
}]
}
`
40 changes: 39 additions & 1 deletion builder/linode/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func testConfig() map[string]interface{} {
"region": "us-ord",
"instance_type": "g6-nanode-1",
"ssh_username": "root",
"image": "linode/debian12",
"image": "linode/debian11",
}
}

Expand Down Expand Up @@ -509,3 +509,41 @@ func TestBuilderPrepare_NetworkInterfaces(t *testing.T) {
t.Errorf("got %v, expected %v", b.config.Interfaces, expectedInterfaces)
}
}

func TestBuilderPrepare_CloudInit(t *testing.T) {
var b Builder
config := testConfig()

// Test default
delete(config, "cloud_init")

_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Fatalf("should not have error; got %v", err)
}

if b.config.CloudInit {
t.Fatalf("expected default to be false; got true")
}

// Const to silence warnings
const expected = true

// Test set
config["cloud_init"] = expected
b = Builder{}
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}

if b.config.CloudInit != expected {
t.Errorf("found %s, expected %t", b.config.Region, expected)
}
}
1 change: 1 addition & 0 deletions builder/linode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Config struct {
StackScriptData map[string]string `mapstructure:"stackscript_data"`
StackScriptID int `mapstructure:"stackscript_id"`
ImageCreateTimeout time.Duration `mapstructure:"image_create_timeout" required:"false"`
CloudInit bool `mapstructure:"cloud_init" required:"false"`
}

func createRandomRootPassword() (string, error) {
Expand Down
2 changes: 2 additions & 0 deletions builder/linode/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions builder/linode/step_create_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
DiskID: disk.ID,
Label: c.ImageLabel,
Description: c.Description,
CloudInit: c.CloudInit,
})
if err != nil {
return handleError("Failed to create image", err)
Expand Down
2 changes: 2 additions & 0 deletions docs/builders/linode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ can also be supplied to override the typical auto-generated key:
Please note that when you create a new Linode instance with a private image, you will
be required to setup a new root password.

- `cloud_init` (bool) - Whether the newly created image supports cloud-init.

#### Interface

This section outlines the fields configurable for a single interface object.
Expand Down
Loading