-
Notifications
You must be signed in to change notification settings - Fork 31
STACKITRCO-186 - Add flag: iaas API param agent #1213
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
base: main
Are you sure you want to change the base?
STACKITRCO-186 - Add flag: iaas API param agent #1213
Conversation
Adds a cli flag for the iaas ( _create server_ ) API param:
`"agent": {"provisioned": true}`
ref STACKITRCO-186
---
Tests:
* ran `make fmt`, `make generate-docs`
* unit tests
```
[~/stackit-cli] go test internal/cmd/server/create/*
ok command-line-arguments 0.006s
[~/stackit-cli]
[~/stackit-cli] make test
>> Running tests for the CLI application
...
ok github.com/stackitcloud/stackit-cli/internal/cmd/server/create 0.006s coverage: 69.7% of statements
...
```
* ran without specifying the new flag (default is agent-provisioned=false) - no change, same behavior as before
```
[~/stackit-cli] stackit -y --project-id c904f41c-2f8c-4edb-b966-e87d65f10b64 server create --name server1 --machine-type t1.1 --network-id 97c5dde4-cb9d-49b8-be55-9cdf0c3795e1 --boot-volume-source-type image --boot-volume-source-id 21466190-b904-4267-8bf3-1be4323f4ffb --boot-volume-size 20 --boot-volume-delete-on-termination=true
...
Server ID: 71785201-d749-4449-99b2-6dc23f406133
[~/stackit-cli] stackit -y server command create --server-id=71785201-d749-4449-99b2-6dc23f406133 --project-id=c904f41c-2f8c-4edb-b966-e87d65f10b64 --template-name=RunShellScript --params script='echo hello'
Error: create Server Command: 404 Not Found, status code 404, Body: {"status":"Not Found","message":"agent not found"}
[~/stackit-cli] stackit -y --project-id c904f41c-2f8c-4edb-b966-e87d65f10b64 server delete 71785201-d749-4449-99b2-6dc23f406133
Deleting server ✓
Deleted server "server1"
```
* ran with specifying flag agent-provisioned=true - the server was created with a provisioned agent, it was possible to set commands
```
[~/stackit-cli] stackit -y --project-id c904f41c-2f8c-4edb-b966-e87d65f10b64 server create --name server1 --machine-type t1.1 --network-id 97c5dde4-cb9d-49b8-be55-9cdf0c3795e1 --boot-volume-source-type image --boot-volume-source-id 21466190-b904-4267-8bf3-1be4323f4ffb --boot-volume-size 20 --boot-volume-delete-on-termination=true --agent-provisioned=true
...
Server ID: ed3086ff-a1ef-44ec-b2f7-08775611dc4e
[~/stackit-cli] stackit -y server command create --server-id=ed3086ff-a1ef-44ec-b2f7-08775611dc4e --project-id=c904f41c-2f8c-4edb-b966-e87d65f10b64 --template-name=RunShellScript --params script='echo hello'
Created server command for server server1. Command ID: 263667
[~/stackit-cli] stackit -y --project-id c904f41c-2f8c-4edb-b966-e87d65f10b64 server delete ed3086ff-a1ef-44ec-b2f7-08775611dc4e
Deleting server ✓
Deleted server "server1"
```
Signed-off-by: Adrian Nackov <[email protected]>
Adds a terraform `stackit_server` option for the iaas ( _create server_ ) API param:
`"agent": {"provisioned": true}`
ref STACKITRCO-187
ref: stackitcloud/stackit-cli#1213
---
Tests:
* ran `make fmt`, `make generate-docs`
* ran unit tests
```
[~/terraform-provider-stackit] go test stackit/internal/services/iaas/server/*
ok command-line-arguments 15.005s
[~/terraform-provider-stackit] make test
...
ok github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/server 15.006s coverage: 33.0% of statements
...
[~/terraform-provider-stackit]
```
* Tested: with a locally-configured terraform - tested by adding, changing, deleting `agent`-related parts of the below main.tf
** Tested without providing agent inside main.tf (the result had `"agent" = null /* object */`)
** Tested with setting `agent = { provisioning = true }` (and then ran the `stackit-cli` command for checking if the agent was created successfully and able to run commands, `stackit -y server command create --server-id=3fdac6ea-3885-441c-b473-bc94ca570ca8 --project-id=c904f41c-2f8c-4edb-b966-e87d65f10b64 --template-name=RunShellScript --params script='echo hello'`).
** Tested when setting `agent = { provisioning = true }` and then set it to false - verified the server was deleted and recreated again with the new value.
```
[~] cat main.tf
provider "stackit" {
# Configuration options
service_account_key_path = "/home/debian/terraform_dev/.terraform_key.json"
default_region = "eu01"
}
resource "stackit_network_interface" "server_nic" {
project_id = "c904f41c-2f8c-4edb-b966-e87d65f10b64"
network_id = "97c5dde4-cb9d-49b8-be55-9cdf0c3795e1"
}
resource "stackit_server" "myserver1" {
project_id = "c904f41c-2f8c-4edb-b966-e87d65f10b64"
name = "terraformtestserver1"
boot_volume = {
size = 64
source_type = "image"
source_id = "21466190-b904-4267-8bf3-1be4323f4ffb"
delete_on_termination = true
}
availability_zone = "eu01-1"
agent = {
provisioned = true
}
machine_type = "t1.1"
network_interfaces = [ stackit_network_interface.server_nic.network_interface_id ]
}
data "stackit_server" "myserver1_data" {
project_id = "c904f41c-2f8c-4edb-b966-e87d65f10b64"
server_id = stackit_server.myserver1.server_id
}
output "server_info_from_data" {
value = data.stackit_server.myserver1_data
}
```
```
[~] terraform apply -auto-approve ## this is without `agent` set in the config
...
server_info_from_data = {
"affinity_group" = tostring(null)
"agent" = null /* object */
"availability_zone" = "eu01-1"
...
}
...
```
```
[~] terraform apply -auto-approve ## this is with `agent = { provisioned = true }` set in the config
...
server_info_from_data = {
"affinity_group" = tostring(null)
"agent" = {
"provisioned" = true
}
"availability_zone" = "eu01-1"
"boot_volume" = {
"delete_on_termination" = true
"id" = "673021e5-2a90-4482-8ffa-e0485c7588bd"
}
...
}
```
Signed-off-by: Adrian Nackov <[email protected]>
Adds a terraform `stackit_server` option for the iaas ( _create server_ ) API param:
`"agent": {"provisioned": true}`
ref STACKITRCO-187
ref: stackitcloud/stackit-cli#1213
---
Tests:
* ran `make fmt`, `make generate-docs`
* ran unit tests
```
[~/terraform-provider-stackit] go test stackit/internal/services/iaas/server/*
ok command-line-arguments 15.005s
[~/terraform-provider-stackit] make test
...
ok github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/server 15.006s coverage: 33.0% of statements
...
[~/terraform-provider-stackit]
```
* Tested: with a locally-configured terraform - tested by adding, changing, deleting `agent`-related parts of the below main.tf
** Tested without providing agent inside main.tf (the result had `"agent" = null /* object */`)
** Tested with setting `agent = { provisioning = true }` (and then ran the `stackit-cli` command for checking if the agent was created successfully and able to run commands, `stackit -y server command create --server-id=3fdac6ea-3885-441c-b473-bc94ca570ca8 --project-id=c904f41c-2f8c-4edb-b966-e87d65f10b64 --template-name=RunShellScript --params script='echo hello'`).
** Tested when setting `agent = { provisioning = true }` and then set it to false - verified the server was deleted and recreated again with the new value.
```
[~] cat main.tf
provider "stackit" {
# Configuration options
service_account_key_path = "/home/debian/terraform_dev/.terraform_key.json"
default_region = "eu01"
}
resource "stackit_network_interface" "server_nic" {
project_id = "c904f41c-2f8c-4edb-b966-e87d65f10b64"
network_id = "97c5dde4-cb9d-49b8-be55-9cdf0c3795e1"
}
resource "stackit_server" "myserver1" {
project_id = "c904f41c-2f8c-4edb-b966-e87d65f10b64"
name = "terraformtestserver1"
boot_volume = {
size = 64
source_type = "image"
source_id = "21466190-b904-4267-8bf3-1be4323f4ffb"
delete_on_termination = true
}
availability_zone = "eu01-1"
agent = {
provisioned = true
}
machine_type = "t1.1"
network_interfaces = [ stackit_network_interface.server_nic.network_interface_id ]
}
data "stackit_server" "myserver1_data" {
project_id = "c904f41c-2f8c-4edb-b966-e87d65f10b64"
server_id = stackit_server.myserver1.server_id
}
output "server_info_from_data" {
value = data.stackit_server.myserver1_data
}
```
```
[~] terraform apply -auto-approve ## this is without `agent` set in the config
...
server_info_from_data = {
"affinity_group" = tostring(null)
"agent" = null /* object */
"availability_zone" = "eu01-1"
...
}
...
```
```
[~] terraform apply -auto-approve ## this is with `agent = { provisioned = true }` set in the config
...
server_info_from_data = {
"affinity_group" = tostring(null)
"agent" = {
"provisioned" = true
}
"availability_zone" = "eu01-1"
"boot_volume" = {
"delete_on_termination" = true
"id" = "673021e5-2a90-4482-8ffa-e0485c7588bd"
}
...
}
```
Signed-off-by: Adrian Nackov <[email protected]>
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
cgoetz-inovex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution, looks good, but an additional test with agent-provisioned true would be nice.
| expectedModel: fixtureInputModel(func(model *inputModel) { | ||
| model.AgentProvisioned = nil | ||
| }), | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| }, | |
| }, | |
| { | |
| description: "valid with agent-provisioned=true", | |
| flagValues: fixtureFlagValues(func(flagValues map[string]string) { | |
| flagValues[agentProvisionedFlag] = "true" | |
| }), | |
| isValid: true, | |
| expectedModel: fixtureInputModel(func(model *inputModel) { | |
| model.AgentProvisioned = true | |
| }), | |
| }, |
marceljk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks overall good! Can you extend the pretty output for the describe command? So that customers can easily check with the CLI if either the Agent is enabled or disabled
stackit-cli/internal/cmd/server/describe/describe.go
Lines 159 to 169 in fb6cfca
| if server.KeypairName != nil { | |
| table.AddRow("KEYPAIR", *server.KeypairName) | |
| table.AddSeparator() | |
| } | |
| if server.MachineType != nil { | |
| table.AddRow("MACHINE TYPE", *server.MachineType) | |
| table.AddSeparator() | |
| } | |
| if server.Labels != nil && len(*server.Labels) > 0 { |
Something like this should be fine
if server.Agent != nil && server.Agent.Provisioned != nil {
table.AddRow("AGENT", *server.Agent.Provisioned)
table.AddSeparator()
}
Adds a cli flag for the iaas ( create server ) API param:
"agent": {"provisioned": true}ref STACKITRCO-186
Tests:
ran
make fmt,make generate-docsunit tests
Description
relates to STACKITRCO-186
Checklist
make fmtmake generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)