Skip to content

Commit

Permalink
Adding extra-spec SSH Keys
Browse files Browse the repository at this point in the history
  • Loading branch information
fabi200123 committed Jun 19, 2024
1 parent bec8b51 commit e5ee6aa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ To this end, this provider supports the following extra specs schema:
"type": "string",
"description": "The source snapshot to create this disk."
},
"ssh_keys": {
"type": "array",
"description": "A list of SSH keys to be added to the instance. The format is USERNAME:SSH_KEY",
"items": {
"type": "string"
}
},
"enable_boot_debug": {
"type": "boolean",
"description": "Enable boot debug on the VM."
Expand All @@ -155,7 +162,7 @@ To this end, this provider supports the following extra specs schema:
}
}
},
"additionalProperties": false
"additionalProperties": false
}
```

Expand All @@ -169,7 +176,8 @@ An example of extra specs json would look like this:
"nic_type": "VIRTIO_NET",
"custom_labels": {"environment":"production","project":"myproject"},
"network_tags": ["web-server", "production"],
"source_snapshot": "projects/garm-testing/global/snapshots/garm-snapshot"
"source_snapshot": "projects/garm-testing/global/snapshots/garm-snapshot",
"ssh_keys": ["username1:ssh_key1", "username2:ssh_key2"]
}
```

Expand Down
4 changes: 4 additions & 0 deletions internal/client/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ func (g *GcpCli) CreateInstance(ctx context.Context, spec *spec.RunnerSpec) (*co
Key: proto.String("runner_name"),
Value: proto.String(spec.BootstrapParams.Name),
},
{
Key: proto.String("ssh-keys"),
Value: proto.String(spec.SSHKeys),
},
},
},
Labels: spec.CustomLabels,
Expand Down
14 changes: 14 additions & 0 deletions internal/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ const (
"type": "string",
"description": "The source snapshot to create this disk."
},
"ssh_keys": {
"type": "array",
"description": "A list of SSH keys to be added to the instance.",
"items": {
"type": "string"
}
},
"enable_boot_debug": {
"type": "boolean",
"description": "Enable boot debug on the VM."
Expand Down Expand Up @@ -181,6 +188,7 @@ type extraSpecs struct {
CustomLabels map[string]string `json:"custom_labels,omitempty"`
NetworkTags []string `json:"network_tags,omitempty"`
SourceSnapshot string `json:"source_snapshot,omitempty"`
SSHKeys []string `json:"ssh_keys,omitempty"`
EnableBootDebug *bool `json:"enable_boot_debug"`
}

Expand Down Expand Up @@ -230,6 +238,7 @@ type RunnerSpec struct {
CustomLabels map[string]string
NetworkTags []string
SourceSnapshot string
SSHKeys string
EnableBootDebug bool
}

Expand All @@ -255,6 +264,11 @@ func (r *RunnerSpec) MergeExtraSpecs(extraSpecs *extraSpecs) {
if extraSpecs.SourceSnapshot != "" {
r.SourceSnapshot = extraSpecs.SourceSnapshot
}
if len(extraSpecs.SSHKeys) > 0 {
for key := range extraSpecs.SSHKeys {
r.SSHKeys = r.SSHKeys + "\n" + extraSpecs.SSHKeys[key]
}
}
if extraSpecs.EnableBootDebug != nil {
r.EnableBootDebug = *extraSpecs.EnableBootDebug
}
Expand Down
2 changes: 2 additions & 0 deletions internal/spec/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestJsonSchemaValidation(t *testing.T) {
},
"network_tags": ["example_tag"],
"source_snapshot": "snapshot-id",
"ssh_keys": ["ssh-key", "ssh-key2"],
"enable_boot_debug": true,
"runner_install_template": "install-template",
"extra_context": {
Expand Down Expand Up @@ -99,6 +100,7 @@ func TestMergeExtraSpecs(t *testing.T) {
CustomLabels: map[string]string{"key1": "value1"},
NetworkTags: []string{"tag1", "tag2"},
SourceSnapshot: "projects/garm-testing/global/snapshots/garm-snapshot",
SSHKeys: []string{"ssh-key1", "ssh-key2"},
EnableBootDebug: &enable_boot_debug,
},
},
Expand Down

0 comments on commit e5ee6aa

Please sign in to comment.