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

Allow backend to set hardware profile when hardware_profile is not set #191

Merged
merged 8 commits into from
Feb 9, 2022
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module github.com/terraform-providers/terraform-provider-gridscale

require (
github.com/google/uuid v1.3.0 // indirect
github.com/gridscale/gsclient-go/v3 v3.8.0
github.com/gridscale/gsclient-go/v3 v3.8.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
)

go 1.16
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gridscale/gsclient-go/v3 v3.8.0 h1:DZoYxhUQAoIeFkyl1cpH8e0m70WNEfG9G5ZaprpCIbg=
github.com/gridscale/gsclient-go/v3 v3.8.0/go.mod h1:A9+Af0aJL+uei0DwAEnZ3G6gZgdC5oOyw2ZUPxUfvTs=
github.com/gridscale/gsclient-go/v3 v3.8.1 h1:eKFhEM9Z+4tHQnVA5OM2sb8h4gA3bllcYSKyg32lPNk=
github.com/gridscale/gsclient-go/v3 v3.8.1/go.mod h1:A9+Af0aJL+uei0DwAEnZ3G6gZgdC5oOyw2ZUPxUfvTs=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
Expand Down Expand Up @@ -452,8 +452,8 @@ golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 h1:0jf+tOCoZ3LyutmCOWpVni1chK4VfFLhRsDK7MhqGRY=
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
2 changes: 1 addition & 1 deletion gridscale/relation-manager/serverRelationManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (c *ServerRelationManger) IsShutdownRequired(ctx context.Context) bool {
var shutdownRequired bool
d := c.getData()
hasServerNetListChange := c.hasServerNetworkListChanged(ctx)
if d.HasChanges("cores", "memory", "ipv4", "ipv6") || hasServerNetListChange {
if d.HasChanges("cores", "memory", "ipv4", "ipv6", "hardware_profile") || hasServerNetListChange {
shutdownRequired = true
}
return shutdownRequired
Expand Down
35 changes: 26 additions & 9 deletions gridscale/resource_gridscale_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func resourceGridscaleServer() *schema.Resource {
Type: schema.TypeString,
Description: "The number of server cores.",
Optional: true,
ForceNew: true,
Default: "default",
Computed: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
valid := false
for _, profile := range hardwareProfiles {
Expand Down Expand Up @@ -641,19 +640,20 @@ func resourceGridscaleServerCreate(d *schema.ResourceData, meta interface{}) err
}

profile := d.Get("hardware_profile").(string)
if profile == "legacy" {
switch profile {
case "legacy":
requestBody.HardwareProfile = gsclient.LegacyServerHardware
} else if profile == "nested" {
case "nested":
requestBody.HardwareProfile = gsclient.NestedServerHardware
} else if profile == "cisco_csr" {
case "cisco_csr":
requestBody.HardwareProfile = gsclient.CiscoCSRServerHardware
} else if profile == "sophos_utm" {
case "sophos_utm":
requestBody.HardwareProfile = gsclient.SophosUTMServerHardware
} else if profile == "f5_bigip" {
case "f5_bigip":
requestBody.HardwareProfile = gsclient.F5BigipServerHardware
} else if profile == "q35" {
case "q35":
requestBody.HardwareProfile = gsclient.Q35ServerHardware
} else {
case "default":
requestBody.HardwareProfile = gsclient.DefaultServerHardware
}

Expand Down Expand Up @@ -753,6 +753,23 @@ func resourceGridscaleServerUpdate(d *schema.ResourceData, meta interface{}) err
}

if shutdownRequired {
profile := d.Get("hardware_profile").(string)
switch profile {
case "legacy":
requestBody.HardwareProfile = gsclient.LegacyServerHardware
case "nested":
requestBody.HardwareProfile = gsclient.NestedServerHardware
case "cisco_csr":
requestBody.HardwareProfile = gsclient.CiscoCSRServerHardware
case "sophos_utm":
requestBody.HardwareProfile = gsclient.SophosUTMServerHardware
case "f5_bigip":
requestBody.HardwareProfile = gsclient.F5BigipServerHardware
case "q35":
requestBody.HardwareProfile = gsclient.Q35ServerHardware
case "default":
requestBody.HardwareProfile = gsclient.DefaultServerHardware
}
updateSequence := func(ctx context.Context) error {
//Execute the update request
err = gsc.UpdateServer(ctx, d.Id(), requestBody)
Expand Down
8 changes: 8 additions & 0 deletions vendor/github.com/gridscale/gsclient-go/v3/CHANGELOG.md

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

2 changes: 1 addition & 1 deletion vendor/github.com/gridscale/gsclient-go/v3/config.go

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

6 changes: 3 additions & 3 deletions vendor/github.com/gridscale/gsclient-go/v3/network.go

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

3 changes: 3 additions & 0 deletions vendor/github.com/gridscale/gsclient-go/v3/server.go

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

79 changes: 0 additions & 79 deletions vendor/github.com/klauspost/compress/fse/README.md

This file was deleted.

87 changes: 0 additions & 87 deletions vendor/github.com/klauspost/compress/huff0/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ github.com/google/go-cmp/cmp/internal/value
# github.com/google/uuid v1.3.0
## explicit
github.com/google/uuid
# github.com/gridscale/gsclient-go/v3 v3.8.0
# github.com/gridscale/gsclient-go/v3 v3.8.1
## explicit
github.com/gridscale/gsclient-go/v3
# github.com/hashicorp/errwrap v1.0.0
Expand Down Expand Up @@ -179,7 +179,7 @@ golang.org/x/net/http2/hpack
golang.org/x/net/idna
golang.org/x/net/internal/timeseries
golang.org/x/net/trace
# golang.org/x/sys v0.0.0-20220111092808-5a964db01320
# golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
## explicit
golang.org/x/sys/cpu
golang.org/x/sys/internal/unsafeheader
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/server.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The following arguments are supported:

* `auto_recovery` - (Optional) If the server should be auto-started in case of a failure (default=true).

* `hardware_profile` - (Optional, ForceNew) The hardware profile of the Server. Options are default, legacy, nested, cisco_csr, sophos_utm, f5_bigip and q35 at the moment of writing. Check [the official docs](https://gridscale.io/en/api-documentation/index.html#operation/createServer).
* `hardware_profile` - (Optional, Computed) The hardware profile of the Server. Options are default, legacy, nested, cisco_csr, sophos_utm, f5_bigip and q35 at the moment of writing. If it is not set, the backend will set it by default. Check [the official docs](https://gridscale.io/en/api-documentation/index.html#operation/createServer).

* `ipv4` - (Optional) The UUID of the IPv4 address of the server. (***NOTE: The server will NOT automatically be connected to the public network; to give it access to the internet, please add server to the public network.)

Expand Down