Skip to content

Commit

Permalink
chore: initial auto-prue
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Riobo Lorenzo <[email protected]>
  • Loading branch information
adrianriobo committed Jun 10, 2024
1 parent 8362d19 commit de9e824
Show file tree
Hide file tree
Showing 172 changed files with 113,054 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.15.15
github.com/aws/aws-sdk-go-v2/service/ec2 v1.142.0
github.com/pulumi/pulumi-aws/sdk/v6 v6.37.1
github.com/pulumi/pulumi-awsx/sdk/v2 v2.3.0
github.com/pulumi/pulumi-azure-native-sdk/compute/v2 v2.42.1
github.com/pulumi/pulumi-azure-native-sdk/network/v2 v2.42.1
github.com/pulumi/pulumi-azure-native-sdk/resources/v2 v2.42.1
Expand Down Expand Up @@ -77,6 +78,7 @@ require (
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
github.com/pulumi/esc v0.8.3 // indirect
github.com/pulumi/pulumi-azure-native-sdk/v2 v2.42.1 // indirect
github.com/pulumi/pulumi-docker/sdk/v4 v4.4.3 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ github.com/pulumi/esc v0.8.3 h1:myeDL6dD/mz34zZjCL8s7d/tWHBJYxfMxDCL11MHoqc=
github.com/pulumi/esc v0.8.3/go.mod h1:v5VAPxYDa9DRwvubbzKt4ZYf5y0esWC2ccSp/AT923I=
github.com/pulumi/pulumi-aws/sdk/v6 v6.37.1 h1:U0Z6dagxFsOhV9J16aAjIfEZJf7NU+L9l9aGABQyrNs=
github.com/pulumi/pulumi-aws/sdk/v6 v6.37.1/go.mod h1:OQXIshEv/eVOYyBPMHADSaLG+qDJKQqP8p9lBy7tkOA=
github.com/pulumi/pulumi-awsx/sdk/v2 v2.3.0 h1:UEdUQKep1Y4vr6YasSO2tXRGJWaoVVQfpD87sEFYhTI=
github.com/pulumi/pulumi-awsx/sdk/v2 v2.3.0/go.mod h1:0LFX4V3PY88rBBfRIIA4DxOTAI/GEffwvjnFGccfTyw=
github.com/pulumi/pulumi-azure-native-sdk/compute/v2 v2.42.1 h1:TkBjR0eoL+tZMDsAMFyxGW3CRWA+fEfNcGEoE4zwkNc=
github.com/pulumi/pulumi-azure-native-sdk/compute/v2 v2.42.1/go.mod h1:PgajQXVwJD5xHhd2FsvueIjItNso/hXSjo5BrYk+6wM=
github.com/pulumi/pulumi-azure-native-sdk/network/v2 v2.42.1 h1:JqGwoMhZFTNpGkK+FI8H5m4rNbytWAXZ2fz7CNVVkLI=
Expand All @@ -240,6 +242,8 @@ github.com/pulumi/pulumi-azure-native-sdk/v2 v2.42.1 h1:u11UBY/uHUbNDPYyQF6MuDtT
github.com/pulumi/pulumi-azure-native-sdk/v2 v2.42.1/go.mod h1:sXtxcyIW/V67zIwmGEZJ5F61EO/S6+1lH8c7zUYNhVA=
github.com/pulumi/pulumi-command/sdk v0.11.1 h1:5LCte8TvYlnOfD2Cn6Xm7ZA1fRtT74XAP0QvCPFpIcA=
github.com/pulumi/pulumi-command/sdk v0.11.1/go.mod h1:NfMh7+awKDW3r8Z91JkAN4/lRPsXcCsMqGID0YJHjkk=
github.com/pulumi/pulumi-docker/sdk/v4 v4.4.3 h1:gQC2As+wE8QflbLCG90jLaKwIpqW3yl1y327Jj6ovbI=
github.com/pulumi/pulumi-docker/sdk/v4 v4.4.3/go.mod h1:i19ZhFjFQrngtXYLHp3kjZNRmnEnq/DUdXK6/CBk77o=
github.com/pulumi/pulumi-random/sdk/v4 v4.16.2 h1:5el+INHB9exKLbuQMaz1OEmnasU1A6/GoOMFHCveXb8=
github.com/pulumi/pulumi-random/sdk/v4 v4.16.2/go.mod h1:FuKLicnDYepG3W/tGmqCYkgdML5GK9RE/Ti984E/Tq8=
github.com/pulumi/pulumi-tls/sdk/v5 v5.0.3 h1:kbdrJVO1PczQakfZZ2Ke2P5G4jlPgTw2geGHR2+7zYc=
Expand Down
57 changes: 57 additions & 0 deletions pkg/provider/aws/action/mac/mac-dh.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"github.com/adrianriobo/qenvs/pkg/provider/util/output"
"github.com/adrianriobo/qenvs/pkg/util/logging"
resourcesUtil "github.com/adrianriobo/qenvs/pkg/util/resources"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cloudwatch"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
awsECS "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ecs"
"github.com/pulumi/pulumi-awsx/sdk/v2/go/awsx/ecs"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
Expand Down Expand Up @@ -104,3 +107,57 @@ func (r *MacRequest) manageResultsDedicatedHost(stackResult auto.UpResult) (*str
}
return &dhID, &dhAZ, nil
}

func (r *MacRequest) ScheduleDestroy(ctx *pulumi.Context) error {
// https://medium.com/@nilangav/set-up-scheduled-tasks-with-aws-fargate-using-cloudformation-templates-b7bd2f7db46b
// Cluster is not deleted as it is required to run the self prune container
clusterName := resourcesUtil.GetResourceName(r.Prefix, awsMacMachineID, "mac-dh-event-destroy")
cluster, err := awsECS.NewCluster(ctx,
clusterName,
&awsECS.ClusterArgs{
Tags: qenvsContext.ResourceTags(),
Name: pulumi.String(clusterName),
},
pulumi.RetainOnDelete(true))
if err != nil {
return err
}

destroyCmd := []string{"aws", "destroy", "mac"}
fs, err := ecs.NewFargateService(ctx,
resourcesUtil.GetResourceName(r.Prefix, awsMacMachineID, "fg"),
&ecs.FargateServiceArgs{
Cluster: cluster.Arn,
TaskDefinitionArgs: &ecs.FargateServiceTaskDefinitionArgs{
Container: &ecs.TaskDefinitionContainerDefinitionArgs{
Command: pulumi.ToStringArray(destroyCmd),
Image: pulumi.String(""),
},
},
})
if err != nil {
return err
}

cloudwatch.NewEventRule(ctx,
resourcesUtil.GetResourceName(r.Prefix, awsMacMachineID, "mac-dh-event-destroy"),
&cloudwatch.EventRuleArgs{
Description: pulumi.String("Destroy event for mac dedicated host"),
Name: pulumi.String(resourcesUtil.GetResourceName(r.Prefix,
awsMacMachineID, "mac-dh-event-desotry")),

// ScheduleExpression: ,
},
)

cloudwatch.NewEventTarget(ctx,
resourcesUtil.GetResourceName(r.Prefix, awsMacMachineID, "mac-dh-event-destroy"),
&cloudwatch.EventTargetArgs{
EcsTarget: cloudwatch.EventTargetEcsTargetArgs{
TaskCount: pulumi.IntPtr(1),
TaskDefinitionArn: fs.TaskDefinition.Arn(),
},
})

return fmt.Errorf("not implemented yet")
}
Loading

0 comments on commit de9e824

Please sign in to comment.