Skip to content

Commit

Permalink
Merge pull request #3596 from hashicorp/automation/refactor-and-enabl…
Browse files Browse the repository at this point in the history
…e-data-api-v2-for-terraform-generator

automation: updating the Terraform Generator to use Data API V2
  • Loading branch information
tombuildsstuff authored Jan 10, 2024
2 parents 31687ac + ae635fd commit 408b2e7
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 137 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/automation-regenerate-go-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ jobs:
with:
go-version: '1.21.3'

- name: Setup .NET
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
with:
dotnet-version: 7.0.x

- name: "Build Data API"
run: |
cd ./data
make build
cd ../tools/data-api
make build
- name: "Launch SSH Agent"
run: |
# launch an ssh agent and export it's env vars
Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/unit-test-end-to-end-resource-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,10 @@ jobs:
with:
submodules: recursive

- name: Setup .NET
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
with:
dotnet-version: 7.0.x

- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '1.21.3'

- name: "Build Data API"
run: |
cd ./data
make build
- name: "Build and Run importer-rest-api-specs"
id: import-data
run: |
Expand Down
45 changes: 22 additions & 23 deletions scripts/automation-generate-and-commit-go-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@ set -e
DIR="$(cd "$(dirname "$0")" && pwd)/.."

function buildAndInstallDependencies {
echo "Installing the Go SDK Generator into the GOBIN.."
cd "${DIR}/tools/generator-go-sdk"
go install .
cd "${DIR}"

echo "Building Wrapper.."
cd "${DIR}/tools/wrapper-automation"
go build -o wrapper-automation
cd "${DIR}"
echo "Outputting Go Version.."
go version

echo "Installing the Data API V2 onto the GOBIN.."
cd "${DIR}/tools/data-api"
go install .
cd "${DIR}"

echo "Installing the Go SDK Generator into the GOBIN.."
cd "${DIR}/tools/generator-go-sdk"
go install .
cd "${DIR}"

echo "Building Wrapper.."
cd "${DIR}/tools/wrapper-automation"
go build -o wrapper-automation
cd "${DIR}"
}

function runWrapper {
local dataApiAssemblyPath=$1
local apiDefinitionsDirectory=$1
local outputDirectory=$2
local useV2Generator=$4

echo "Running Wrapper.."
cd "${DIR}/tools/wrapper-automation"
./wrapper-automation go-sdk \
-data-api-assembly-path="../../$dataApiAssemblyPath"\
-output-dir="../../$outputDirectory"\
-use-v2-generator="$useV2Generator"
--api-definitions-dir="../../$apiDefinitionsDirectory"\
--output-dir="../../$outputDirectory"

cd "${DIR}"

Expand Down Expand Up @@ -109,23 +115,16 @@ function cleanup {
}

function main {
local dataApiAssemblyPath="data/Pandora.Api/bin/Debug/net7.0/Pandora.Api.dll"
local dataApiV2Path="tools/data-api/data-api"
local apiDefinitionsDirectory="./api-definitions"
local swaggerSubmodule="./submodules/rest-api-specs"
local outputDirectory="tmp/go-azure-sdk"
local sdkRepo="[email protected]:hashicorp/go-azure-sdk.git"
local sha
local useV2Generator=true

buildAndInstallDependencies
sha=$(getSwaggerSubmoduleSha "$swaggerSubmodule")
prepareGoSdk "$outputDirectory" "$sdkRepo"
if [ "$useV2Generator" = true ]
then
runWrapper "$dataApiV2Path" "$outputDirectory" "$sha" "$useV2Generator"
else
runWrapper "$dataApiAssemblyPath" "$outputDirectory" "$sha" "$useV2Generator"
fi
runWrapper "$apiDefinitionsDirectory" "$outputDirectory"
conditionallyCommitAndPushGoSdk "$outputDirectory" "$sha"
cleanup "$outputDirectory"
}
Expand Down
45 changes: 19 additions & 26 deletions scripts/automation-generate-and-commit-terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ set -e
DIR="$(cd "$(dirname "$0")" && pwd)/.."

function buildAndInstallDependencies {
echo "Outputting Go Version.."
go version
echo "Outputting Go Version.."
go version

echo "Outputting .net Version.."
dotnet --version
echo "Installing the Data API into the GOBIN.."
cd "${DIR}/tools/data-api"
go install .
cd "${DIR}"

echo "Installing the Terraform Generator into the GOBIN.."
cd "${DIR}/tools/generator-terraform"
go install .
cd "${DIR}"
echo "Installing the Terraform Generator into the GOBIN.."
cd "${DIR}/tools/generator-terraform"
go install .
cd "${DIR}"

echo "Building Wrapper.."
cd "${DIR}/tools/wrapper-automation"
go build -o wrapper-automation
cd "${DIR}"
echo "Building Wrapper.."
cd "${DIR}/tools/wrapper-automation"
go build -o wrapper-automation
cd "${DIR}"
}

function runWrapper {
local dataApiAssemblyPath=$1
local apiDefinitionsDirectory=$1
local outputDirectory=$2
local useV2Generator=$4

echo "Running Wrapper.."
cd "${DIR}/tools/wrapper-automation"
./wrapper-automation terraform \
-data-api-assembly-path="../../$dataApiAssemblyPath"\
-output-dir="../../$outputDirectory"\
-use-v2-generator="$useV2Generator"
--api-definitions-dir="../../$apiDefinitionsDirectory"\
--output-dir="../../$outputDirectory"

cd "${DIR}"

Expand Down Expand Up @@ -141,23 +141,16 @@ function cleanup {
}

function main {
local dataApiAssemblyPath="data/Pandora.Api/bin/Debug/net7.0/Pandora.Api.dll"
local dataApiV2Path="tools/data-api/data-api"
local apiDefinitionsDirectory="./api-definitions"
local swaggerSubmodule="./submodules/rest-api-specs"
local outputDirectory="tmp/terraform-provider-azurerm"
local providerRepo="[email protected]:hashicorp/terraform-provider-azurerm.git"
local sha
local useV2Generator=false

buildAndInstallDependencies
sha=$(getSwaggerSubmoduleSha "$swaggerSubmodule")
prepareTerraformProvider "$outputDirectory" "$providerRepo"
if [ "$useV2Generator" = true ]
then
runWrapper "$dataApiV2Path" "$outputDirectory" "$sha" "$useV2Generator"
else
runWrapper "$dataApiAssemblyPath" "$outputDirectory" "$sha" "$useV2Generator"
fi
runWrapper "$apiDefinitionsDirectory" "$outputDirectory"
runFmtImportsAndGenerate "$outputDirectory"
conditionallyCommitAndPushTerraformProvider "$outputDirectory" "$sha"
cleanup "$outputDirectory"
Expand Down
45 changes: 22 additions & 23 deletions scripts/automation-generate-go-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@ set -e
DIR="$(cd "$(dirname "$0")" && pwd)/.."

function buildAndInstallDependencies {
echo "Installing the Go SDK Generator into the GOBIN.."
cd "${DIR}/tools/generator-go-sdk"
go install .
cd "${DIR}"

echo "Building Wrapper.."
cd "${DIR}/tools/wrapper-automation"
go build -o wrapper-automation
cd "${DIR}"
echo "Outputting Go Version.."
go version

echo "Installing the Data API V2 onto the GOBIN.."
cd "${DIR}/tools/data-api"
go install .
cd "${DIR}"

echo "Installing the Go SDK Generator into the GOBIN.."
cd "${DIR}/tools/generator-go-sdk"
go install .
cd "${DIR}"

echo "Building Wrapper.."
cd "${DIR}/tools/wrapper-automation"
go build -o wrapper-automation
cd "${DIR}"
}

function runWrapper {
local dataApiAssemblyPath=$1
local apiDefinitionsDirectory=$1
local outputDirectory=$2
local useV2Generator=$4

echo "Running Wrapper.."
cd "${DIR}/tools/wrapper-automation"
./wrapper-automation go-sdk \
-data-api-assembly-path="../../$dataApiAssemblyPath"\
-output-dir="../../$outputDirectory"\
-use-v2-generator="$useV2Generator"
--api-definitions-dir="../../$apiDefinitionsDirectory"\
--output-dir="../../$outputDirectory"

cd "${DIR}"

Expand Down Expand Up @@ -89,23 +95,16 @@ function cleanup {
}

function main {
local dataApiAssemblyPath="data/Pandora.Api/bin/Debug/net7.0/Pandora.Api.dll"
local dataApiV2Path="tools/data-api/data-api"
local apiDefinitionsDirectory="./api-definitions"
local swaggerSubmodule="./submodules/rest-api-specs"
local outputDirectory="tmp/go-azure-sdk"
local sdkRepo="https://github.com/hashicorp/go-azure-sdk.git"
local sha
local useV2Generator=false

buildAndInstallDependencies
sha=$(getSwaggerSubmoduleSha "$swaggerSubmodule")
prepareGoSdk "$outputDirectory" "$sdkRepo"
if [ "$useV2Generator" = true ]
then
runWrapper "$dataApiV2Path" "$outputDirectory" "$sha" "$useV2Generator"
else
runWrapper "$dataApiAssemblyPath" "$outputDirectory" "$sha" "$useV2Generator"
fi
runWrapper "$apiDefinitionsDirectory" "$outputDirectory"
runGoSDKUnitTests "$outputDirectory"
cleanup "$outputDirectory"
}
Expand Down
45 changes: 19 additions & 26 deletions scripts/automation-generate-terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ set -e
DIR="$(cd "$(dirname "$0")" && pwd)/.."

function buildAndInstallDependencies {
echo "Outputting Go Version.."
go version
echo "Outputting Go Version.."
go version

echo "Outputting .net Version.."
dotnet --version
echo "Installing the Data API V2 onto the GOBIN.."
cd "${DIR}/tools/data-api"
go install .
cd "${DIR}"

echo "Installing the Terraform Generator into the GOBIN.."
cd "${DIR}/tools/generator-terraform"
go install .
cd "${DIR}"
echo "Installing the Terraform Generator into the GOBIN.."
cd "${DIR}/tools/generator-terraform"
go install .
cd "${DIR}"

echo "Building Wrapper.."
cd "${DIR}/tools/wrapper-automation"
go build -o wrapper-automation
cd "${DIR}"
echo "Building Wrapper.."
cd "${DIR}/tools/wrapper-automation"
go build -o wrapper-automation
cd "${DIR}"
}

function runWrapper {
local dataApiAssemblyPath=$1
local apiDefinitionsDirectory=$1
local outputDirectory=$2
local useV2Generator=$3

echo "Running Wrapper.."
cd "${DIR}/tools/wrapper-automation"
./wrapper-automation terraform \
-data-api-assembly-path="../../$dataApiAssemblyPath"\
-output-dir="../../$outputDirectory"\
-use-v2-generator="$useV2Generator"
--api-definitions-dir="../../$apiDefinitionsDirectory"\
--output-dir="../../$outputDirectory"

cd "${DIR}"

Expand Down Expand Up @@ -110,20 +110,13 @@ function cleanup {
}

function main {
local dataApiAssemblyPath="data/Pandora.Api/bin/Debug/net7.0/Pandora.Api.dll"
local dataApiV2Path="tools/data-api/data-api"
local apiDefinitionsDirectory="./api-definitions"
local outputDirectory="tmp/provider-azurerm"
local providerRepo="[email protected]:hashicorp/terraform-provider-azurerm.git"
local useV2Generator=false

buildAndInstallDependencies
prepareTerraformProvider "$outputDirectory" "$providerRepo"
if [ "$useV2Generator" = true ]
then
runWrapper "$dataApiV2Path" "$outputDirectory" "$useV2Generator"
else
runWrapper "$dataApiAssemblyPath" "$outputDirectory" "$useV2Generator"
fi
runWrapper "$apiDefinitionsDirectory" "$outputDirectory"
runFmtImportsAndGenerate "$outputDirectory"
runTerraformProviderUnitTests "$outputDirectory"
cleanup "$outputDirectory"
Expand Down
6 changes: 3 additions & 3 deletions tools/wrapper-automation/go_sdk_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func (c GoSdkGeneratorCmd) Run(args []string) int {
}

f := flag.NewFlagSet("wrapper-automation", flag.ExitOnError)
f.StringVar(&arguments.DataApiAssemblyPath, "data-api-assembly-path", "", "-data-api-assembly-path=../data/Pandora.Api.dll")
f.StringVar(&arguments.OutputDirectory, "output-dir", "", "-output-dir=../output")
f.BoolVar(&arguments.UseV2Generator, "use-v2-generator", false, "-use-v2-generator=true")
f.StringVar(&arguments.ApiDefinitionsDirectory, "api-definitions-dir", "", "--api-definitions-dir=./api-definitions")
f.StringVar(&arguments.DataApiAssemblyPath, "data-api-assembly-path", "", "--data-api-assembly-path=../data/Pandora.Api.dll")
f.StringVar(&arguments.OutputDirectory, "output-dir", "", "--output-dir=../output")

if err := f.Parse(args); err != nil {
log.Fatalf("parsing arguments: %+v", err)
Expand Down
Loading

0 comments on commit 408b2e7

Please sign in to comment.