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

feat(cluster): add autoupgrade support #59

Merged
merged 4 commits into from
Sep 26, 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: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NAMESPACE=ame
NAME=acloud
BINARY=terraform-provider-${NAME}
VERSION=0.2
OS_ARCH=darwin_amd64
OS_ARCH=darwin_arm64

default: install

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,21 @@ Avisi Cloud Platform Terraform Provider for managing your Avisi Cloud resources
## License

[Apache 2.0 License 2.0](lICENSE)

## Contributing

Set up the provider locally and make sure to change the variables if needed:
```bash
make install NAMESPACE=local HOSTNAME=terraform.local OS_ARCH=darwin_arm64
```

Use the locally installed provider in your Terraform configuration:
```hcl
terraform {
required_providers {
acloud = {
source = "terraform.local/local/acloud"
}
}
}
```
6 changes: 6 additions & 0 deletions acloud/data_source_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func dataSourceCluster() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"maintenance_schedule_id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the maintenance schedule for the cluster",
},
},
}
}
Expand Down Expand Up @@ -118,6 +123,7 @@ func dataClusterRead(ctx context.Context, d *schema.ResourceData, m interface{})
d.Set("version", cluster.Version)
d.Set("update_channel", cluster.UpdateChannel)
d.Set("status", cluster.Status)
d.Set("maintenance_schedule_id", cluster.MaintenanceSchedule.Identity)

return nil
}
74 changes: 74 additions & 0 deletions acloud/data_source_maintenance_schedule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package acloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceMaintenanceSchedule() *schema.Resource {
return &schema.Resource{
ReadContext: dataMaintenanceScheduleRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
},
"organisation": {
Type: schema.TypeString,
Required: true,
Description: "Slug of the Organisation. Can only be set on creation.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the maintenance schedule",
},
"windows": {
Type: schema.TypeList,
Computed: true,
Description: "List of maintenance windows for the schedule",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"day": {
Type: schema.TypeString,
Required: true,
Description: "Day of the maintenance window",
},
"start_time": {
Type: schema.TypeString,
Required: true,
Description: "Start time of the maintenance window",
},
"duration": {
Type: schema.TypeInt,
Required: true,
Description: "Duration in minutes of the maintenance window",
},
},
},
},
},
}
}

func dataMaintenanceScheduleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
provider := getProvider(m)
client := provider.Client
org, err := getOrganisation(provider, d)
if err != nil {
return diag.FromErr(err)
}

maintenanceSchedule, err := client.GetMaintenanceSchedule(ctx, org, d.Get("id").(string))
if err != nil {
return diag.FromErr(err)
}

d.SetId(maintenanceSchedule.Identity)
d.Set("name", maintenanceSchedule.Name)
d.Set("windows", maintenanceSchedule.MaintenanceWindows)

return nil
}
10 changes: 6 additions & 4 deletions acloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ func Provider() *schema.Provider {
},
},
ResourcesMap: map[string]*schema.Resource{
"acloud_environment": resourceEnvironment(),
"acloud_cluster": resourceCluster(),
"acloud_nodepool": resourceNodepool(),
"acloud_cloud_account": resourceCloudAccount(),
"acloud_environment": resourceEnvironment(),
"acloud_cluster": resourceCluster(),
"acloud_nodepool": resourceNodepool(),
"acloud_cloud_account": resourceCloudAccount(),
"acloud_maintenance_schedule": resourceMaintenanceSchedule(),
},
DataSourcesMap: map[string]*schema.Resource{
"acloud_cloud_profile": dataSourceCloudProfile(),
Expand All @@ -51,6 +52,7 @@ func Provider() *schema.Provider {
"acloud_nodepool_join_config": dataSourceNodeJoinConfig(),
"acloud_organisation": dataSourceOrganisations(),
"acloud_update_channel": dataSourceUpdateChannel(),
"acloud_maintenance_schedule": dataSourceMaintenanceSchedule(),
},
ConfigureContextFunc: providerConfigure,
}
Expand Down
47 changes: 46 additions & 1 deletion acloud/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func resourceCluster() *schema.Resource {
"pod_security_standards_profile": {
Type: schema.TypeString,
Optional: true,
Default: "privileged",
Default: "PRIVILEGED",
Description: "Pod Security Standards used by default within the cluster",
},
"enable_multi_availability_zones": {
Expand Down Expand Up @@ -133,6 +133,12 @@ func resourceCluster() *schema.Resource {
Default: true,
Description: "Enable Network Encryption at the node level (if supported by the CNI).",
},
"enable_auto_upgrade": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable auto-upgrade for the cluster",
},
"status": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -149,6 +155,11 @@ func resourceCluster() *schema.Resource {
Default: 600,
Description: "Time-out for waiting until the cluster reaches the desired state",
},
"maintenance_schedule_id": {
Type: schema.TypeString,
Optional: true,
Description: "ID of the maintenance schedule to apply to the cluster",
},
},
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Expand Down Expand Up @@ -176,8 +187,11 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, m interf
EnableHighAvailability: d.Get("enable_high_available_control_plane").(bool),
EnableNATGateway: d.Get("enable_private_cluster").(bool),
EnableNetworkEncryption: d.Get("enable_network_encryption").(bool),
EnableAutoUpgrade: d.Get("enable_auto_upgrade").(bool),
CloudAccountIdentity: d.Get("cloud_account_identity").(string),
NodePools: nodePools,
MaintenanceScheduleIdentity: d.Get("maintenance_schedule_id").(string),
UpdateChannel: d.Get("update_channel").(string),
}

env := getStringAttributeWithLegacyName(d, "environment", "environment_slug")
Expand Down Expand Up @@ -258,7 +272,9 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, m interfac
d.Set("enable_high_available_control_plane", cluster.HighlyAvailable)
d.Set("enable_private_cluster", cluster.EnableNATGateway)
d.Set("enable_network_encryption", cluster.EnableNetworkEncryption)
d.Set("enable_auto_upgrade", cluster.AutoUpgrade)
d.Set("status", cluster.Status)
d.Set("maintenance_schedule_id", cluster.MaintenanceSchedule.Identity)

return nil
}
Expand All @@ -283,14 +299,43 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, m interf
status := d.Get("status").(string)

enableNetworkEncryption := d.Get("enable_network_encryption").(bool)
if d.HasChange("enable_network_encryption") {
_, newVal := d.GetChange("enable_network_encryption")
enableNetworkEncryption = newVal.(bool)
}

enableHAControlPlane := d.Get("enable_high_available_control_plane").(bool)
if d.HasChange("enable_high_available_control_plane") {
_, newVal := d.GetChange("enable_high_available_control_plane")
enableHAControlPlane = newVal.(bool)
}

enableAutoUpgrade := d.Get("enable_auto_upgrade").(bool)
if d.HasChange("enable_auto_upgrade") {
_, newVal := d.GetChange("enable_auto_upgrade")
enableAutoUpgrade = newVal.(bool)
}

pss := d.Get("pod_security_standards_profile").(string)
if d.HasChange("pod_security_standards_profile") {
_, newVal := d.GetChange("pod_security_standards_profile")
pss = newVal.(string)
}

maintenanceScheduleIdentity := d.Get("maintenance_schedule_id").(string)
if d.HasChange("maintenance_schedule_id") {
_, newVal := d.GetChange("maintenance_schedule_id")
maintenanceScheduleIdentity = newVal.(string)
}

updateCluster := acloudapi.UpdateCluster{
UpdateChannel: d.Get("update_channel").(string),
Version: d.Get("version").(string),
PodSecurityStandardsProfile: &pss,
EnableNetworkEncryption: &enableNetworkEncryption,
EnableHighAvailability: &enableHAControlPlane,
EnableAutoUpgrade: &enableAutoUpgrade,
MaintenanceScheduleIdentity: &maintenanceScheduleIdentity,
}

desiredStatus := "running"
Expand Down
Loading