Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit fc62b37

Browse files
committed
Re-map all subflow_link flow references based on provided subflows
1 parent deafd59 commit fc62b37

41 files changed

Lines changed: 276616 additions & 50 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ testoutput*
22
vendor
33
env*.sh
44
output.log
5-
generated*
5+
generated*
6+
dvtf-pingctl

internal/generate/generate.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/patrickcping/dvtf-pingctl/internal/generate/export"
1414
"github.com/patrickcping/dvtf-pingctl/internal/logger"
15+
"github.com/patrickcping/dvtf-pingctl/internal/output"
1516
"github.com/patrickcping/dvtf-pingctl/internal/terraform"
1617
"github.com/samir-gandhi/davinci-client-go/davinci"
1718
)
@@ -24,13 +25,15 @@ type DaVinciGenerator struct {
2425
connectionsData []connectionData
2526
variablesData []variableData
2627
flowAssets []flowAssetData
28+
flowNames map[string]string
2729
}
2830

2931
func New(exportDefs []export.DaVinciGeneratorExport, resources []terraform.ProviderResource, outputPath string) *DaVinciGenerator {
3032
return &DaVinciGenerator{
3133
exportDefs: exportDefs,
3234
resources: resources,
3335
outputPath: outputPath,
36+
flowNames: map[string]string{},
3437
}
3538
}
3639

@@ -54,6 +57,9 @@ func (d *DaVinciGenerator) Generate(version string, overwrite bool) error {
5457
}
5558
}
5659

60+
// Re-write the subflow names to fix issue https://github.com/patrickcping/dvtf-pingctl/issues/11
61+
d.rewriteSubflowNames()
62+
5763
// Write the HCL configuration
5864
err = d.write(version, overwrite)
5965
if err != nil {
@@ -63,6 +69,34 @@ func (d *DaVinciGenerator) Generate(version string, overwrite bool) error {
6369
return nil
6470
}
6571

72+
func (d *DaVinciGenerator) rewriteSubflowNames() {
73+
updatedFlowsData := make([]flowData, 0)
74+
for _, flowData := range d.flowsData {
75+
updatedSubflowLinks := make([]flowSubflowLink, 0)
76+
for _, subflowLink := range flowData.SubflowLinks {
77+
if subFlowName, ok := d.flowNames[subflowLink.ReplaceSubflowID]; ok {
78+
// update the subflow link name
79+
subflowLink.FlowRefID = d.sanitiseResourceName(subFlowName)
80+
subflowLink.SubFlowName = subFlowName
81+
} else {
82+
// Issue warning that subflow hasn't been included in the `-e` param list
83+
output.Print(output.Opts{
84+
Message: "Warning: Subflow has not been found in any of the JSON files provided in the `-e` param list. Plan errors may occur.",
85+
Fields: map[string]interface{}{
86+
"Missing Subflow ID": subflowLink.ReplaceSubflowID,
87+
},
88+
})
89+
}
90+
updatedSubflowLinks = append(updatedSubflowLinks, subflowLink)
91+
}
92+
flowData.SubflowLinks = updatedSubflowLinks
93+
94+
updatedFlowsData = append(updatedFlowsData, flowData)
95+
}
96+
97+
d.flowsData = updatedFlowsData
98+
}
99+
66100
func (d *DaVinciGenerator) parseFlows() error {
67101

68102
newExportDefs := make([]export.DaVinciGeneratorExport, 0)
@@ -128,6 +162,7 @@ func (d *DaVinciGenerator) buildDataSingleFlow(flow davinci.Flow, parsedIntf map
128162
l.Debug().Msgf("buildDataSingleFlow Command called.")
129163

130164
flowResourceName := d.sanitiseResourceName(flow.Name)
165+
d.flowNames[flow.FlowID] = flow.Name
131166

132167
pathVar := fmt.Sprintf("assets/flows/%s.json", flowResourceName)
133168
createFlow := true

scripts/generate-test.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
go build .
4+
5+
# Directory containing the files
6+
directory=$1
7+
8+
# Directory containing the script
9+
script_dir=$(dirname "$(realpath "$0")")
10+
11+
# Directory to generate HCL in
12+
DIR="$directory/testoutput"
13+
14+
if [ -d "$DIR" ]; then
15+
echo "Directory $DIR exists. Removing it."
16+
rm -r $DIR
17+
fi
18+
19+
# Initialize the command variable
20+
command=""
21+
22+
# Loop through all JSON (export) files in the directory
23+
for file in "$directory"/*.json; do
24+
25+
# ./dvtf-pingctl validate -e "$file"
26+
# validateResponse=$?
27+
# # Check if the command failed
28+
# if [ $validateResponse -eq 1 ]; then
29+
# echo "Validation failed"
30+
# exit 1
31+
# fi
32+
# if [ $validateResponse -eq 2 ]; then
33+
# echo "Validation warning"
34+
# fi
35+
36+
# Add each file as a parameter
37+
command+=" -e \"$file\""
38+
done
39+
40+
set -e
41+
42+
# Execute the command
43+
./dvtf-pingctl generate -o $DIR $command
44+
45+
if [ -d "$DIR" ]; then
46+
echo "Directory $DIR exists. Bootstrapping it."
47+
48+
cp $script_dir/../testing/bootstrap-hcl/* $DIR
49+
cp $directory/*.tftest.hcl $DIR
50+
51+
pushd $DIR
52+
terraform init
53+
terraform validate
54+
terraform test
55+
popd
56+
else
57+
echo "Directory $DIR does not exist."
58+
exit 1
59+
fi

scripts/test-bootstrap-hcl/main.tf

Lines changed: 0 additions & 19 deletions
This file was deleted.

scripts/test-bootstrap-hcl/variables.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

scripts/test-bootstrap-hcl/versions.tf

Lines changed: 0 additions & 23 deletions
This file was deleted.

scripts/validate-test.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Directory containing the files
4+
directory=$1
5+
6+
# Initialize the command variable
7+
command="go run ./ validate"
8+
9+
# Loop through all files in the directory
10+
for file in "$directory"/*.json; do
11+
# Add each file as a parameter
12+
command+=" -e \"$file\""
13+
done
14+
15+
# Execute the command
16+
eval $command

testing/bootstrap-hcl/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "pingone_environment" "test_environment" {
2+
name = format("DVTF-PINGCTL Test Environment - %s", var.test_name)
3+
type = "SANDBOX"
4+
license_id = var.license_id
5+
6+
services = [
7+
{
8+
type = "SSO"
9+
},
10+
{
11+
type = "DaVinci",
12+
tags = ["DAVINCI_MINIMAL"]
13+
}
14+
]
15+
}
16+
17+
locals {
18+
pingone_environment_id = pingone_environment.test_environment.id
19+
}

testing/bootstrap-hcl/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
variable "license_id" {
2+
type = string
3+
}
4+
5+
variable "davinci_admin_environment_id" {
6+
type = string
7+
}
8+
9+
variable "test_name" {
10+
type = string
11+
default = "no-test"
12+
}

testing/bootstrap-hcl/versions.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
terraform {
2+
required_providers {
3+
davinci = {
4+
source = "pingidentity/davinci"
5+
version = ">= 0.4.2, < 1.0.0"
6+
}
7+
pingone = {
8+
source = "pingidentity/pingone"
9+
version = ">= 1.1.0, < 2.0.0"
10+
}
11+
}
12+
}
13+
14+
provider "pingone" {
15+
# Configuration options
16+
# Ref: https://registry.terraform.io/providers/pingidentity/pingone/latest/docs#provider-schema-reference
17+
18+
# Ensure the following environment variables are set:
19+
# - PINGONE_CLIENT_ID
20+
# - PINGONE_CLIENT_SECRET
21+
# - PINGONE_ENVIRONMENT_ID
22+
# - PINGONE_REGION_CODE
23+
}
24+
25+
provider "davinci" {
26+
# Configuration options
27+
# Ref: https://registry.terraform.io/providers/pingidentity/davinci/latest/docs#schema
28+
29+
# Ensure the following environment variables are set:
30+
# - PINGONE_USERNAME
31+
# - PINGONE_PASSWORD
32+
# - TF_VAR_davinci_admin_environment_id
33+
# - PINGONE_REGION
34+
35+
environment_id = var.davinci_admin_environment_id
36+
}

0 commit comments

Comments
 (0)