/
main.go
90 lines (76 loc) · 2.53 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
package main
import (
"context"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go-v2/service/sfn"
"github.com/hashicorp/aws-service-catalog-engine-for-tfc/engine/lambda-functions/shared/awsconfig"
"github.com/hashicorp/aws-service-catalog-engine-for-tfc/engine/lambda-functions/shared/stepfunctions"
"os"
)
type ProvisioningOperationsHandlerRequest struct {
Records []Record `json:"Records"`
}
type Record struct {
MessageId string `json:"messageId"`
Body string `json:"body"`
}
type StateMachinePayload struct {
Token string `json:"token"`
Operation string `json:"operation"`
ProductId string `json:"productId"`
ProvisionedProductId string `json:"provisionedProductId"`
ProvisionedProductName string `json:"provisionedProductName"`
ProvisionedArtifactId string `json:"provisioningArtifactId"`
RecordId string `json:"recordId"`
LaunchRoleArn string `json:"launchRoleArn"`
TerraformOrganization string `json:"terraformOrganization"`
Identity struct {
Principal string `json:"principal"`
AwsAccountId string `json:"awsAccountId"`
OrganizationId string `json:"organizationId"`
} `json:"identity"`
TracerTag struct {
Key string `json:"token"`
Value string `json:"operation"`
} `json:"tracerTag"`
Artifact struct {
Path string `json:"path"`
Type string `json:"type"`
} `json:"artifact"`
Tags []struct {
Key string `json:"key"`
Value string `json:"value"`
} `json:"tags"`
Parameters []struct {
Key string `json:"key"`
Value string `json:"value"`
} `json:"parameters"`
}
type ProvisioningOperationsHandlerResponse struct {
BatchItemFailures []BatchItemFailure `json:"batchItemFailures"`
}
type BatchItemFailure struct {
ItemIdentifier string `json:"itemIdentifier"`
}
func main() {
// Create temporary context to initialize the handler with
initContext := context.TODO()
// Initialize the TFE client
sdkConfig := awsconfig.GetSdkConfig(initContext)
// Create the Step Functions client
sfnClient := sfn.NewFromConfig(sdkConfig)
// Get Terraform Organization
terraformOrganization := os.Getenv("TERRAFORM_ORGANIZATION")
// Get state machine arn
stateMachineArn := os.Getenv("STATE_MACHINE_ARN")
handler := ProvisioningOperationsHandler{
terraformOrganization: terraformOrganization,
stepFunctions: stepfunctions.SFN{Client: sfnClient},
stateMachineArn: stateMachineArn,
}
lambda.Start(handler.HandleRequest)
}