-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathdata_source_ssh_connection_deployment_targets.go
54 lines (46 loc) · 2.14 KB
/
data_source_ssh_connection_deployment_targets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package octopusdeploy
import (
"context"
"time"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceSSHConnectionDeploymentTargets() *schema.Resource {
return &schema.Resource{
Description: "Provides information about existing SSH connection deployment targets.",
ReadContext: dataSourceSSHConnectionDeploymentTargetsRead,
Schema: getSSHConnectionDeploymentTargetDataSchema(),
}
}
func dataSourceSSHConnectionDeploymentTargetsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
query := octopusdeploy.MachinesQuery{
CommunicationStyles: []string{"Ssh"},
DeploymentID: d.Get("deployment_id").(string),
EnvironmentIDs: expandArray(d.Get("environments").([]interface{})),
HealthStatuses: expandArray(d.Get("health_statuses").([]interface{})),
IDs: expandArray(d.Get("ids").([]interface{})),
IsDisabled: d.Get("is_disabled").(bool),
Name: d.Get("name").(string),
PartialName: d.Get("partial_name").(string),
Roles: expandArray(d.Get("roles").([]interface{})),
ShellNames: expandArray(d.Get("shell_names").([]interface{})),
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
TenantIDs: expandArray(d.Get("tenants").([]interface{})),
TenantTags: expandArray(d.Get("tenant_tags").([]interface{})),
Thumbprint: d.Get("thumbprint").(string),
}
client := m.(*octopusdeploy.Client)
deploymentTargets, err := client.Machines.Get(query)
if err != nil {
return diag.FromErr(err)
}
flattenedSSHConnectionDeploymentTargets := []interface{}{}
for _, deploymentTarget := range deploymentTargets.Items {
flattenedSSHConnectionDeploymentTargets = append(flattenedSSHConnectionDeploymentTargets, flattenSSHConnectionDeploymentTarget(deploymentTarget))
}
d.Set("ssh_connection_deployment_targets", flattenedSSHConnectionDeploymentTargets)
d.SetId("SSHConnectionDeploymentTargets " + time.Now().UTC().String())
return nil
}