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

fix(servergroup): anti_affinity_policy default value and description #410

Merged
merged 4 commits into from
Oct 9, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
### Changed
- kubernetes: remove node group maximum value validation. The maximum number of nodes (in the cluster) is determined by the cluster plan and the validation is done on the API side.

### Fixed
- servergroup: use valid value as default for `anti_affinity_policy`.

## [2.12.0] - 2023-07-21

### Added
Expand Down
43 changes: 25 additions & 18 deletions internal/service/servergroup/servergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

const (
titleDescription = "Title of your server group"
membersDescription = "UUIDs of the servers that are members of this group"
// Lines > 1 should have one level of indentation to keep them under the right list item
antiAffinityPolicyDescription = `Defines if a server group is an anti-affinity group. Setting this to ` + "`strict` or `yes`" + ` will
result in all servers in the group being placed on separate compute hosts. The value can be ` + "`strict`, `yes`, or `no`" + `.

* ` + "`strict`" + ` policy doesn't allow servers in the same server group to be on the same host
* ` + "`yes`" + ` refers to best-effort policy and tries to put servers on different hosts, but this is not guaranteed
* ` + "`no`" + ` refers to having no policy and thus no effect on server host affinity

To verify if the anti-affinity policies are met by requesting a server group details from API. For more information
please see UpCloud API documentation on server groups.

Plese also note that anti-affinity policies are only applied on server start. This means that if anti-affinity
policies in server group are not met, you need to manually restart the servers in said group,
for example via API, UpCloud Control Panel or upctl (UpCloud CLI)`
)

func ResourceServerGroup() *schema.Resource {
return &schema.Resource{
CreateContext: resourceServerGroupCreate,
Expand All @@ -24,36 +43,24 @@ func ResourceServerGroup() *schema.Resource {
},
Schema: map[string]*schema.Schema{
"title": {
Description: "Title of your server group",
Description: titleDescription,
Type: schema.TypeString,
Required: true,
},
"labels": utils.LabelsSchema("server group"),
"members": {
Description: "UUIDs of the servers that are members of this group",
Description: membersDescription,
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
"anti_affinity_policy": {
Description: `Defines if a server group is an anti-affinity group. Setting this to "strict" or yes" will
result in all servers in the group being placed on separate compute hosts. The value can be "strict", "yes" or "no".

* "strict" refers to strict policy doesn't allow servers in the same server group to be on the same host
* "yes" refers to best-effort policy and tries to put servers on different hosts, but this is not guaranteed
* "no" refers to having no policy and thus no affect server host affinity

To verify if the anti-affinity policies are met by requesting a server group details from API. For more information
please see UpCloud API documentation on server groups.

Plese also note that anti-affinity policies are only applied on server start. This means that if anti-affinity
policies in server group are not met, you need to manually restart the servers in said group,
for example via API, UpCloud Control Panel or upctl (UpCloud CLI)`,
Type: schema.TypeString,
Optional: true,
Default: false,
Description: antiAffinityPolicyDescription,
Type: schema.TypeString,
Optional: true,
Default: "no",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{
string(upcloud.ServerGroupAntiAffinityPolicyBestEffort),
string(upcloud.ServerGroupAntiAffinityPolicyOff),
Expand Down
2 changes: 1 addition & 1 deletion upcloud/datasource_upcloud_zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
availablePublicZones = 12
availablePublicZones = 13
allFilter = "all"
publicFilter = "public"
privateFilter = "private"
Expand Down
4 changes: 4 additions & 0 deletions upcloud/resource_upcloud_server_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestAccUpCloudServerGroup(t *testing.T) {
var providers []*schema.Provider

group1 := "upcloud_server_group.tf_test_1"
group2 := "upcloud_server_group.tf_test_2"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -27,6 +28,9 @@ func TestAccUpCloudServerGroup(t *testing.T) {
resource.TestCheckResourceAttr(group1, "members.#", "1"),
resource.TestCheckResourceAttr(group1, "labels.%", "3"),
resource.TestCheckResourceAttr(group1, "anti_affinity_policy", "no"),
resource.TestCheckResourceAttr(group2, "title", "tf_test_2"),
resource.TestCheckResourceAttr(group2, "members.#", "0"),
resource.TestCheckResourceAttr(group2, "anti_affinity_policy", "no"),
),
},
{
Expand Down
6 changes: 5 additions & 1 deletion upcloud/testdata/upcloud_server_group/step1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ resource "upcloud_server" "test" {
resource "upcloud_server_group" "tf_test_1" {
title = "tf_test_1"
anti_affinity_policy = "no"
labels = {
labels = {
"key1" = "val1"
"key2" = "val2"
"key3" = "val3"
}
members = [upcloud_server.test.id]
}

resource "upcloud_server_group" "tf_test_2" {
title = "tf_test_2"
}
6 changes: 5 additions & 1 deletion upcloud/testdata/upcloud_server_group/step2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ resource "upcloud_server" "test" {
resource "upcloud_server_group" "tf_test_1" {
title = "tf_test_1_updated"
anti_affinity_policy = "strict"
labels = {
labels = {
"key1" = "val1"
"key2" = "val2"
}
}

resource "upcloud_server_group" "tf_test_2" {
title = "tf_test_2"
}
Loading