Skip to content

Commit

Permalink
Merge pull request #28 from zachomedia/feat-kubernetes
Browse files Browse the repository at this point in the history
Add Kubernetes deployment target support
  • Loading branch information
jeff-french authored Jul 13, 2019
2 parents 7c3fb8d + c7b3e1d commit 17836f0
Show file tree
Hide file tree
Showing 10 changed files with 336 additions and 48 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/OctopusDeploy/terraform-provider-octopusdeploy

require (
github.com/OctopusDeploy/go-octopusdeploy v1.3.0
github.com/OctopusDeploy/go-octopusdeploy v1.4.0
github.com/apparentlymart/go-cidr v1.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.15.53 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/OctopusDeploy/go-octopusdeploy v1.2.1 h1:wfyln0AKOg74dBJM6V2hKHxskXQz
github.com/OctopusDeploy/go-octopusdeploy v1.2.1/go.mod h1:WyBvcyhFPMULbZwFFWOmt6/irqrfZ/WqCy7ufa8/CGE=
github.com/OctopusDeploy/go-octopusdeploy v1.3.0 h1:ZekYly62VzsHx7PHSSPI8bOKMNNz1DhlonIeWdPobO8=
github.com/OctopusDeploy/go-octopusdeploy v1.3.0/go.mod h1:WyBvcyhFPMULbZwFFWOmt6/irqrfZ/WqCy7ufa8/CGE=
github.com/OctopusDeploy/go-octopusdeploy v1.4.0 h1:uTBRPoGcS3tN40LKQb70xq+m/hpKX1fExfLhGAAxHDk=
github.com/OctopusDeploy/go-octopusdeploy v1.4.0/go.mod h1:WyBvcyhFPMULbZwFFWOmt6/irqrfZ/WqCy7ufa8/CGE=
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-cidr v1.0.0 h1:lGDvXx8Lv9QHjrAVP7jyzleG4F9+FkRhJcEsDFxeb8w=
Expand Down
53 changes: 24 additions & 29 deletions octopusdeploy/data_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,42 +117,37 @@ func dataMachineReadByName(d *schema.ResourceData, m interface{}) error {
client := m.(*octopusdeploy.Client)

machineName := d.Get("name").(string)
machines, err := client.Machine.GetAll()
machine, err := client.Machine.GetByName(machineName)
if err == octopusdeploy.ErrItemNotFound {
return nil
}
if err != nil {
return fmt.Errorf("error reading machine with name %s: %s", machineName, err.Error())
}

for _, m := range *machines {
if m.Name == machineName {
d.SetId(m.ID)
d.Set("endpoint_communicationstyle", m.Endpoint.CommunicationStyle)
d.Set("endpoint_id", m.Endpoint.ID)
d.Set("endpoint_proxyid", m.Endpoint.ProxyID)
d.Set("endpoint_tentacleversiondetails_upgradelocked", m.Endpoint.TentacleVersionDetails.UpgradeLocked)
d.Set("endpoint_tentacleversiondetails_upgraderequired", m.Endpoint.TentacleVersionDetails.UpgradeRequired)
d.Set("endpoint_tentacleversiondetails_upgradesuggested", m.Endpoint.TentacleVersionDetails.UpgradeSuggested)
d.Set("endpoint_tentacleversiondetails_version", m.Endpoint.TentacleVersionDetails.Version)
d.Set("endpoint_thumbprint", m.Endpoint.Thumbprint)
d.Set("endpoint_uri", m.Endpoint.URI)
d.Set("environments", m.EnvironmentIDs)
d.Set("haslatestcalamari", m.HasLatestCalamari)
d.Set("isdisabled", m.IsDisabled)
d.Set("isinprocess", m.IsInProcess)
d.Set("machinepolicy", m.MachinePolicyID)
d.Set("roles", m.Roles)
d.Set("status", m.Status)
d.Set("statussummary", m.StatusSummary)
d.Set("tenanteddeploymentparticipation", m.TenantedDeploymentParticipation)
d.Set("tenantids", m.TenantIDs)
d.Set("tenanttags", m.TenantTags)
//d.Set("thumbprint", m.Thumbprint)
//d.Set("uri", m.URI)

}
}
d.SetId(machine.ID)
d.Set("endpoint_communicationstyle", machine.Endpoint.CommunicationStyle)
d.Set("endpoint_id", machine.Endpoint.ID)
d.Set("endpoint_proxyid", machine.Endpoint.ProxyID)
d.Set("endpoint_tentacleversiondetails_upgradelocked", machine.Endpoint.TentacleVersionDetails.UpgradeLocked)
d.Set("endpoint_tentacleversiondetails_upgraderequired", machine.Endpoint.TentacleVersionDetails.UpgradeRequired)
d.Set("endpoint_tentacleversiondetails_upgradesuggested", machine.Endpoint.TentacleVersionDetails.UpgradeSuggested)
d.Set("endpoint_tentacleversiondetails_version", machine.Endpoint.TentacleVersionDetails.Version)
d.Set("endpoint_thumbprint", machine.Endpoint.Thumbprint)
d.Set("endpoint_uri", machine.Endpoint.URI)
d.Set("environments", machine.EnvironmentIDs)
d.Set("haslatestcalamari", machine.HasLatestCalamari)
d.Set("isdisabled", machine.IsDisabled)
d.Set("isinprocess", machine.IsInProcess)
d.Set("machinepolicy", machine.MachinePolicyID)
d.Set("roles", machine.Roles)
d.Set("status", machine.Status)
d.Set("statussummary", machine.StatusSummary)
d.Set("tenanteddeploymentparticipation", machine.TenantedDeploymentParticipation)
d.Set("tenantids", machine.TenantIDs)
d.Set("tenanttags", machine.TenantTags)
//d.Set("thumbprint", machine.Thumbprint)
//d.Set("uri", machine.URI)

return nil
}
39 changes: 34 additions & 5 deletions octopusdeploy/resource_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,32 @@ func resourceAccount() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"environments": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
"account_type": {
Type: schema.TypeString,
Required: true,
},
"client_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"tenant_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"subscription_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"client_secret": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"tenant_tags": {
Type: schema.TypeList,
Expand All @@ -48,13 +55,17 @@ func resourceAccount() *schema.Resource {
},
"tenanted_deployment_participation": {
Type: schema.TypeString,
Required: true,
Optional: true,
ValidateFunc: validateValueFunc([]string{
"Untenanted",
"TenantedOrUntenanted",
"Tenanted",
}),
},
"token": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand All @@ -75,27 +86,36 @@ func resourceAccountRead(d *schema.ResourceData, m interface{}) error {
}

d.Set("name", account.Name)
d.Set("environments", account.EnvironmentIDs)
d.Set("account_type", account.AccountType)
d.Set("client_id", account.ClientId)
d.Set("tenant_id", account.TenantId)
d.Set("subscription_id", account.SubscriptionNumber)
d.Set("client_secret", account.Password)
d.Set("tenant_tags", account.TenantTags)
d.Set("tenanted_deployment_participation", account.TenantedDeploymentParticipation)
d.Set("token", account.Token)

return nil
}

func buildAccountResource(d *schema.ResourceData) *octopusdeploy.Account {
accountName := d.Get("name").(string)

var environments []string
var accountType string
var clientId string
var tenantId string
var subscriptionId string
var clientSecret string
var tenantTags []string
var tenantedDeploymentParticipation string
var token string

environmentsInterface, ok := d.GetOk("environments")
if ok {
environments = getSliceFromTerraformTypeList(environmentsInterface)
}

accountTypeInterface, ok := d.GetOk("account_type")
if ok {
Expand Down Expand Up @@ -136,7 +156,13 @@ func buildAccountResource(d *schema.ResourceData) *octopusdeploy.Account {
tenantTags = []string{}
}

tokenInterface, ok := d.GetOk("token")
if ok {
token = tokenInterface.(string)
}

var account = octopusdeploy.NewAccount(accountName, accountType)
account.EnvironmentIDs = environments
account.ClientId = clientId
account.TenantId = tenantId
account.Password = octopusdeploy.SensitiveValue{
Expand All @@ -145,6 +171,9 @@ func buildAccountResource(d *schema.ResourceData) *octopusdeploy.Account {
account.SubscriptionNumber = subscriptionId
account.TenantTags = tenantTags
account.TenantedDeploymentParticipation = tenantedDeploymentParticipation
account.Token = octopusdeploy.SensitiveValue{
NewValue: token,
}

return account
}
Expand Down
75 changes: 71 additions & 4 deletions octopusdeploy/resource_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package octopusdeploy

import (
"fmt"
"strconv"

"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -41,6 +42,7 @@ func resourceMachine() *schema.Resource {
"AzureWebApp",
"Ftp",
"AzureCloudService",
"Kubernetes"
}),
},

Expand All @@ -56,6 +58,52 @@ func resourceMachine() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"clustercertificate": {
Type: schema.TypeString,
Optional: true,
},
"clusterurl": {
Type: schema.TypeString,
Optional: true,
},
"namespace": {
Type: schema.TypeString,
Optional: true,
},
"skiptlsverification": {
Type: schema.TypeBool,
Optional: true,
},
"defaultworkerpoolid": {
Type: schema.TypeString,
Optional: true,
},
"authentication": {
Type: schema.TypeSet,
MaxItems: 1,
MinItems: 0,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"accountid": {
Type: schema.TypeString,
Optional: true,
},
"clientcertificate": {
Type: schema.TypeString,
Optional: true,
},
"authenticationtype": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateValueFunc([]string{
"KubernetesCertificate",
"KubernetesStandard",
}),
},
},
},
},
},
},
},
Expand Down Expand Up @@ -209,10 +257,29 @@ func buildMachineResource(d *schema.ResourceData) *octopusdeploy.Machine {
}

tfMachine.Endpoint = &octopusdeploy.MachineEndpoint{
URI: tfSchemaList["uri"].(string),
Thumbprint: tfSchemaList["thumbprint"].(string),
CommunicationStyle: tfSchemaList["communicationstyle"].(string),
ProxyID: proxyid,
URI: tfSchemaList["uri"].(string),
Thumbprint: tfSchemaList["thumbprint"].(string),
CommunicationStyle: tfSchemaList["communicationstyle"].(string),
ProxyID: proxyid,
ClusterCertificate: tfSchemaList["clustercertificate"].(string),
ClusterURL: tfSchemaList["clusterurl"].(string),
SkipTLSVerification: strconv.FormatBool(tfSchemaList["skiptlsverification"].(bool)),
DefaultWorkerPoolID: tfSchemaList["defaultworkerpoolid"].(string),
}

tfAuthenticationSchemaSetInterface, ok := tfSchemaList["authentication"]
if ok {
tfAuthenticationSchemaSet := tfAuthenticationSchemaSetInterface.(*schema.Set)
if len(tfAuthenticationSchemaSet.List()) == 1 {
//Get the first element in the list, which is a map of the interfaces
tfAuthenticationSchemaList := tfAuthenticationSchemaSet.List()[0].(map[string]interface{})

tfMachine.Endpoint.Authentication = &octopusdeploy.MachineEndpointAuthentication{
AccountID: tfAuthenticationSchemaList["accountid"].(string),
ClientCertificate: tfAuthenticationSchemaList["clientcertificate"].(string),
AuthenticationType: tfAuthenticationSchemaList["authenticationtype"].(string),
}
}
}

return tfMachine
Expand Down

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

Loading

0 comments on commit 17836f0

Please sign in to comment.