Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Closed
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
120 changes: 120 additions & 0 deletions octopusdeploy_framework/resource_azure_web_app_deployment_target.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package octopusdeploy_framework

import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

type azureWebAppDeploymentTargetResource struct {
*Config
}

func NewAzureWebAppDeploymentTargetResource() resource.Resource {
return &azureWebAppDeploymentTargetResource{}
}

var _ resource.ResourceWithImportState = &azureWebAppDeploymentTargetResource{}

func (r *azureWebAppDeploymentTargetResource) Metadata(_ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = util.GetTypeName("azure_web_app_deployment_target")
}

func (r *azureWebAppDeploymentTargetResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schemas.AzureWebAppDeploymentTargetSchema{}.GetResourceSchema()
}

func (r *azureWebAppDeploymentTargetResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
r.Config = ResourceConfiguration(req, resp)
}

func (r *azureWebAppDeploymentTargetResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var plan schemas.AzureWebAppDeploymentTargetModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}

tflog.Debug(ctx, "Creating Azure Web App deployment target", map[string]interface{}{
"name": plan.Name.ValueString(),
})

deploymentTarget := expandAzureWebAppDeploymentTarget(ctx, plan)
createdDeploymentTarget, err := machines.Add(r.Config.Client, deploymentTarget)
if err != nil {
resp.Diagnostics.AddError("Error creating Amazon Web App deployment target", err.Error())
return
}

state := flattenAzureWebAppDeploymentTarget(ctx, *createdDeploymentTarget, plan)
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r *azureWebAppDeploymentTargetResource) Read(_ context.Context, _ resource.ReadRequest, _ *resource.ReadResponse) {
return
}

func (r *azureWebAppDeploymentTargetResource) Update(_ context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) {
return
}

func (r *azureWebAppDeploymentTargetResource) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) {
return
}

func (*azureWebAppDeploymentTargetResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

func expandAzureWebAppDeploymentTarget(ctx context.Context, model schemas.AzureWebAppDeploymentTargetModel) *machines.DeploymentTarget {
deploymentTarget := expandDeploymentTarget(ctx, model.DeploymentTargetModel)

endpoint := machines.NewAzureWebAppEndpoint()
endpoint.AccountID = model.AccountId.ValueString()
endpoint.ResourceGroupName = model.ResourceGroupName.ValueString()
endpoint.WebAppName = model.WebAppName.ValueString()
endpoint.WebAppSlotName = model.WebAppSlotName.ValueString()
deploymentTarget.Endpoint = endpoint

return deploymentTarget
}

func flattenAzureWebAppDeploymentTarget(ctx context.Context, deploymentTarget machines.DeploymentTarget, model schemas.AzureWebAppDeploymentTargetModel) schemas.AzureWebAppDeploymentTargetModel {
flattenedDeploymentTarget := flattenDeploymentTarget(ctx, deploymentTarget, model.DeploymentTargetModel)

model.ID = flattenedDeploymentTarget.ID
model.Endpoint = flattenedDeploymentTarget.Endpoint
model.Environments = flattenedDeploymentTarget.Environments
model.HasLatestCalamari = flattenedDeploymentTarget.HasLatestCalamari
model.HealthStatus = flattenedDeploymentTarget.HealthStatus
model.IsDisabled = flattenedDeploymentTarget.IsDisabled
model.IsInProcess = flattenedDeploymentTarget.IsInProcess
model.MachinePolicyId = flattenedDeploymentTarget.MachinePolicyId
model.Name = flattenedDeploymentTarget.Name
model.OperatingSystem = flattenedDeploymentTarget.OperatingSystem
model.Roles = flattenedDeploymentTarget.Roles
model.ShellName = flattenedDeploymentTarget.ShellName
model.ShellVersion = flattenedDeploymentTarget.ShellVersion
model.SpaceId = flattenedDeploymentTarget.SpaceId
model.Status = flattenedDeploymentTarget.Status
model.StatusSummary = flattenedDeploymentTarget.StatusSummary
model.TenantedDeploymentParticipation = flattenedDeploymentTarget.TenantedDeploymentParticipation
model.Tenants = flattenedDeploymentTarget.Tenants
model.TenantTags = flattenedDeploymentTarget.TenantTags
model.Thumbprint = flattenedDeploymentTarget.Thumbprint
model.Uri = flattenedDeploymentTarget.Uri

endpointResource, _ := machines.ToEndpointResource(deploymentTarget.Endpoint)

model.AccountId = types.StringValue(endpointResource.AccountID)
model.ResourceGroupName = types.StringValue(endpointResource.ResourceGroupName)
model.WebAppName = types.StringValue(endpointResource.WebAppName)
model.WebAppSlotName = types.StringValue(endpointResource.WebAppSlotName)

return model
}
99 changes: 99 additions & 0 deletions octopusdeploy_framework/resource_deployment_target.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package octopusdeploy_framework

import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
)

type deploymentTargetResource struct {
*Config
}

func NewDeploymentTargetResource() resource.Resource {
return &deploymentTargetResource{}
}

var _ resource.ResourceWithImportState = &deploymentTargetResource{}

func (r *deploymentTargetResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = util.GetTypeName("deployment_target")
}

func (r *deploymentTargetResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schemas.AzureWebAppDeploymentTargetSchema{}.GetResourceSchema()
}

func (r *deploymentTargetResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
r.Config = ResourceConfiguration(req, resp)
}

func (r *deploymentTargetResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
}

func (r *deploymentTargetResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
return
}

func (r *deploymentTargetResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
return
}

func (r *deploymentTargetResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
return
}

func (*deploymentTargetResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

func expandDeploymentTarget(ctx context.Context, model schemas.DeploymentTargetModel) *machines.DeploymentTarget {
name := model.Name.ValueString()
endpoint := expandAzureWebAppDeploymentEndpoint(ctx, model)
environments := expandStringList(model.Environments)
roles := expandStringList(model.Roles)

deploymentTarget := machines.NewDeploymentTarget(name, endpoint, environments, roles)

deploymentTarget.ID = model.ID.ValueString()
deploymentTarget.HasLatestCalamari = model.HasLatestCalamari.ValueBool()
deploymentTarget.HealthStatus = model.HealthStatus.ValueString()
deploymentTarget.IsDisabled = model.IsDisabled.ValueBool()
deploymentTarget.IsInProcess = model.IsInProcess.ValueBool()
deploymentTarget.MachinePolicyID = model.MachinePolicyId.ValueString()
deploymentTarget.OperatingSystem = model.OperatingSystem.ValueString()
deploymentTarget.ShellName = model.ShellName.ValueString()
deploymentTarget.ShellVersion = model.ShellVersion.ValueString()
deploymentTarget.SpaceID = model.SpaceId.ValueString()
deploymentTarget.Status = model.Status.ValueString()
deploymentTarget.StatusSummary = model.StatusSummary.ValueString()
deploymentTarget.TenantedDeploymentMode = core.TenantedDeploymentMode(model.TenantedDeploymentParticipation.ValueString())
deploymentTarget.TenantIDs = expandStringList(model.Tenants)
deploymentTarget.TenantTags = expandStringList(model.TenantTags)
deploymentTarget.Thumbprint = model.Thumbprint.ValueString()
deploymentTarget.URI = model.Uri.ValueString()

return deploymentTarget
}

func expandAzureWebAppDeploymentEndpoint(_ context.Context, model schemas.DeploymentTargetModel) *machines.AzureWebAppEndpoint {
endpoint := machines.NewAzureWebAppEndpoint()

endpointAttributes := model.Endpoint.Attributes()

endpoint.AccountID = endpointAttributes["account_id"].String()
endpoint.ID = endpointAttributes["id"].String()
endpoint.ResourceGroupName = endpointAttributes["resource_group_name"].String()
endpoint.WebAppName = endpointAttributes["web_app_name"].String()
endpoint.WebAppSlotName = endpointAttributes["web_app_slot_name"].String()

return endpoint
}

func flattenDeploymentTarget(ctx context.Context, deploymentTarget machines.DeploymentTarget, model schemas.DeploymentTargetModel) schemas.DeploymentTargetModel {
return model
}
41 changes: 41 additions & 0 deletions octopusdeploy_framework/schemas/azure_web_app_deployment_target.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package schemas

import (
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

const AzureWebAppDeploymentTargetDescription = "Azure web app deployment target"

type AzureWebAppDeploymentTargetSchema struct{}

type AzureWebAppDeploymentTargetModel struct {
AccountId types.String `tfsdk:"account_id"`
ResourceGroupName types.String `tfsdk:"resource_group_name"`
WebAppName types.String `tfsdk:"web_app_name"`
WebAppSlotName types.String `tfsdk:"web_app_slot_name"`

DeploymentTargetModel
}

func (a AzureWebAppDeploymentTargetSchema) GetResourceSchema() resourceSchema.Schema {
deploymentTargetSchema := DeploymentTargetSchema{}.GetResourceSchema()

deploymentTargetSchema.Description = util.GetResourceSchemaDescription(AzureWebAppDeploymentTargetDescription)

deploymentTargetSchema.Attributes["account_id"] = resourceSchema.StringAttribute{
Required: true,
}
deploymentTargetSchema.Attributes["resource_group_name"] = resourceSchema.StringAttribute{
Required: true,
}
deploymentTargetSchema.Attributes["web_app_name"] = resourceSchema.StringAttribute{
Required: true,
}
deploymentTargetSchema.Attributes["web_app_slot_name"] = resourceSchema.StringAttribute{
Required: true,
}

return deploymentTargetSchema
}
127 changes: 127 additions & 0 deletions octopusdeploy_framework/schemas/deployment_target.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package schemas

import (
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

const DeploymentTargetDescription = "Deployment target"

type DeploymentTargetSchema struct{}

type DeploymentTargetModel struct {
Endpoint types.Object `tfsdk:"endpoint"`
Environments types.List `tfsdk:"environments"`
HasLatestCalamari types.Bool `tfsdk:"has_latest_calamari"`
HealthStatus types.String `tfsdk:"health_status"`
IsDisabled types.Bool `tfsdk:"is_disabled"`
IsInProcess types.Bool `tfsdk:"is_in_process"`
MachinePolicyId types.String `tfsdk:"machine_policy_id"`
Name types.String `tfsdk:"name"`
OperatingSystem types.String `tfsdk:"operating_system"`
Roles types.List `tfsdk:"roles"`
ShellName types.String `tfsdk:"shell_name"`
ShellVersion types.String `tfsdk:"shell_version"`
SpaceId types.String `tfsdk:"space_id"`
Status types.String `tfsdk:"status"`
StatusSummary types.String `tfsdk:"status_summary"`
TenantedDeploymentParticipation types.String `tfsdk:"tenanted_deployment_participation"`
Tenants types.List `tfsdk:"tenants"`
TenantTags types.List `tfsdk:"tenant_tags"`
Thumbprint types.String `tfsdk:"thumbprint"`
Uri types.String `tfsdk:"uri"`

ResourceModel
}

func (d DeploymentTargetSchema) GetResourceSchema() resourceSchema.Schema {
return resourceSchema.Schema{
Description: util.GetResourceSchemaDescription(DeploymentTargetDescription),
Attributes: map[string]resourceSchema.Attribute{
"endpoint": resourceSchema.SingleNestedAttribute{
Attributes: GetEndpointResourceSchema(),
},
"environments": resourceSchema.ListAttribute{
Description: "A list of environment IDs associated with this resource.",
Required: true,
ElementType: types.StringType,
Validators: []validator.List{
listvalidator.SizeAtLeast(1),
},
},
"has_latest_calamari": resourceSchema.BoolAttribute{
Computed: true,
},
"health_status": GetHealthStatusResourceSchema(),
"id": GetIdResourceSchema(),
"is_disabled": resourceSchema.BoolAttribute{
Computed: true,
Optional: true,
},
"is_in_process": resourceSchema.BoolAttribute{
Computed: true,
},
"machine_policy_id": resourceSchema.StringAttribute{
Computed: true,
Optional: true,
},
"name": GetNameResourceSchema(true),
"operating_system": resourceSchema.StringAttribute{
Computed: true,
Optional: true,
},
"roles": resourceSchema.ListAttribute{
ElementType: types.StringType,
Validators: []validator.List{
listvalidator.SizeAtLeast(1),
},
},
"shell_name": resourceSchema.StringAttribute{
Computed: true,
Optional: true,
},
"shell_version": resourceSchema.StringAttribute{
Computed: true,
Optional: true,
},
"space_id": GetSpaceIdResourceSchema(DeploymentTargetDescription),
"status": GetStatusResourceSchema(),
"status_summary": GetStatusSummaryResourceSchema(),
"tenanted_deployment_participation": resourceSchema.StringAttribute{
Description: "The tenanted deployment mode of the resource. Valid account types are `Untenanted`, `TenantedOrUntenanted`, or `Tenanted`.",
Optional: true,
Computed: true,
Validators: []validator.String{
stringvalidator.OneOf(
"Untenanted",
"TenantedOrUntenanted",
"Tenanted",
),
},
},
"tenants": resourceSchema.ListAttribute{
Description: "A list of tenant IDs associated with this certificate.",
Optional: true,
Computed: true,
ElementType: types.StringType,
},
"tenant_tags": resourceSchema.ListAttribute{
Description: "A list of tenant tags associated with this certificate.",
Optional: true,
ElementType: types.StringType,
},
"thumbprint": resourceSchema.StringAttribute{
Computed: true,
Optional: true,
},
"uri": resourceSchema.StringAttribute{
Computed: true,
Optional: true,
},
},
}
}
Loading
Loading