-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds windows OS resources (#25)
* feat(windows-os): Windows OS - implementation * implementation Data provider * fix(windows-os): double naming * docs(windows-os): templating documentation and examples --------- Co-authored-by: Maximilian.Brand <[email protected]>
- Loading branch information
1 parent
77b47d0
commit 28a33bb
Showing
14 changed files
with
516 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package windowsos | ||
|
||
import ( | ||
"github.com/cancom/terraform-provider-cancom/client" | ||
client_windowsos "github.com/cancom/terraform-provider-cancom/client/services/windows-os" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataWindowsOSDeploymentProgress() *schema.Resource { | ||
return &schema.Resource{ | ||
|
||
Read: WindowsOSDeploymentProgressRead, | ||
Schema: map[string]*schema.Schema{ | ||
"deployment_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "ID of the deployment object.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func WindowsOSDeploymentProgressRead(d *schema.ResourceData, meta interface{}) error { | ||
c := meta.(*client.Client) | ||
|
||
c.HostURL = c.ServiceURLs["managed-windows"] | ||
|
||
resp, err := (*client_windowsos.Client)(c).CreateWindowsDeploymentStatus(d.Get("deployment_id").(string)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(resp.Id) | ||
|
||
return nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package windowsos | ||
|
||
import ( | ||
"github.com/cancom/terraform-provider-cancom/cancom/services/base" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
type Provider base.Provider | ||
|
||
func (p Provider) Name() string { | ||
return p.ServiceName | ||
} | ||
|
||
func (p Provider) Provider() *schema.Provider { | ||
return p.ProviderSchema | ||
} | ||
|
||
func New() Provider { | ||
return Provider{ | ||
ServiceName: "windows_os", | ||
ProviderSchema: &schema.Provider{ | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"deployment": resourceWindowsOSDeployment(), | ||
}, | ||
DataSourcesMap: map[string]*schema.Resource{ | ||
"deployment_progress": dataWindowsOSDeploymentProgress(), | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package windowsos | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cancom/terraform-provider-cancom/client" | ||
client_windowsos "github.com/cancom/terraform-provider-cancom/client/services/windows-os" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceWindowsOSDeployment() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceWindowsOSCreate, | ||
ReadContext: resourceWindowsOSRead, | ||
UpdateContext: resourceWindowsOSUpdate, | ||
DeleteContext: resourceWindowsOSDelete, | ||
Schema: map[string]*schema.Schema{ | ||
"customer_environment_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "ID of the customer environment.", | ||
}, | ||
"role": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Role of the Machine - needs to match predefined roles.", | ||
}, | ||
"maintenance_window_id": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Description: "List of maintenanceWindow IDs", | ||
}, | ||
"services": { | ||
Type: schema.TypeList, | ||
Required: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Description: "Services deployed and delivered to maschine", | ||
}, | ||
"customer_number": { | ||
Type: schema.TypeString, | ||
Required: false, | ||
Computed: true, | ||
Description: "Customer number for Windows Management", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceWindowsOSCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*client.Client) | ||
|
||
c.HostURL = c.ServiceURLs["managed-windows"] | ||
|
||
var diags diag.Diagnostics | ||
|
||
tempservices := d.Get("services").([]interface{}) | ||
servicesarray := []string{} | ||
for _, tempservices := range tempservices { | ||
servicesarray = append(servicesarray, tempservices.(string)) | ||
} | ||
|
||
tempmaintenance_window_id := d.Get("maintenance_window_id").([]interface{}) | ||
maintenance_window_id_array := []string{} | ||
for _, tempmaintenance_window_id := range tempmaintenance_window_id { | ||
maintenance_window_id_array = append(maintenance_window_id_array, tempmaintenance_window_id.(string)) | ||
} | ||
computerObject := client_windowsos.WindowsOS_Computer{ | ||
Services: servicesarray, | ||
MaintenanceWindowId: maintenance_window_id_array, | ||
Role: d.Get("role").(string), | ||
} | ||
|
||
windowsOSRequest := client_windowsos.WindowsOS_Deplyoment{ | ||
|
||
Computer: computerObject, | ||
CoustomerEnvironmentID: d.Get("customer_environment_id").(string), | ||
} | ||
|
||
resp, err := (*client_windowsos.Client)(c).CreateWindowsDeployment(&windowsOSRequest) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.Set("customer_number", resp.Computer.CustomerID) | ||
d.SetId(resp.Id) | ||
|
||
return diags | ||
|
||
} | ||
|
||
func resourceWindowsOSRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*client.Client) | ||
|
||
c.HostURL = c.ServiceURLs["managed-windows"] | ||
|
||
var diags diag.Diagnostics | ||
|
||
resp, err := (*client_windowsos.Client)(c).GetWindowsDeployment(d.Id()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.Set("customer_environment_id", resp.CoustomerEnvironmentID) | ||
d.Set("role", resp.Computer.Role) | ||
d.Set("maintenance_window_id", resp.Computer.MaintenanceWindowId) | ||
d.Set("services", resp.Computer.Services) | ||
|
||
return diags | ||
} | ||
|
||
func resourceWindowsOSUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*client.Client) | ||
|
||
c.HostURL = c.ServiceURLs["managed-windows"] | ||
|
||
var diags diag.Diagnostics | ||
|
||
computerObject := client_windowsos.WindowsOS_Computer{ | ||
Services: d.Get("services").([]string), | ||
MaintenanceWindowId: d.Get("maintenance_window_id").([]string), | ||
Role: d.Get("role").(string), | ||
} | ||
|
||
windowsOSRequest := client_windowsos.WindowsOS_Deplyoment{ | ||
Computer: computerObject, | ||
CoustomerEnvironmentID: d.Get("customer_environment_id").(string), | ||
} | ||
|
||
resp, err := (*client_windowsos.Client)(c).UpdateWindowsOsDeployment(d.Id(), &windowsOSRequest) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(resp.Id) | ||
|
||
return diags | ||
} | ||
|
||
func resourceWindowsOSDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*client.Client) | ||
|
||
c.HostURL = c.ServiceURLs["managed-windows"] | ||
|
||
var diags diag.Diagnostics | ||
|
||
err := (*client_windowsos.Client)(c).DeleteWindowsDeployment(d.Id()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return diags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package client_windowsos | ||
|
||
type WindowsOS_Deplyoment struct { | ||
Status int `json:"status,omitempty"` | ||
Id string `json:"deploymentId,omitempty"` | ||
CoustomerEnvironmentID string `json:"coustomerEnvironmentID"` | ||
Computer WindowsOS_Computer `json:"computer"` | ||
} | ||
type WindowsOS_Computer struct { | ||
Computername string `json:"computername,omitempty"` | ||
Guid string `json:"guid,omitempty"` | ||
Services []string `json:"services"` | ||
CustomerID string `json:"customerID,omitempty"` | ||
MaintenanceWindowId []string `json:"maintenanceWindowId"` | ||
Role string `json:"role"` | ||
} |
Oops, something went wrong.