Skip to content

Commit

Permalink
terraform-provider: extend build process and docgen
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Sanft <[email protected]>
  • Loading branch information
msanft committed Nov 22, 2023
1 parent a79720b commit 288cff2
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 190 deletions.
19 changes: 18 additions & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ nixpkgs_package(
repository = "@nixpkgs",
)

nixpkgs_package(
name = "terraform-plugin-docs",
repository = "@nixpkgs",
)

nixpkgs_package(
name = "systemd",
repository = "@nixpkgs",
Expand Down Expand Up @@ -216,6 +221,19 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

# Aspect Bazel Lib
load("//bazel/toolchains:aspect_bazel_lib.bzl", "aspect_bazel_lib")

aspect_bazel_lib()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains", "register_coreutils_toolchains", "register_yq_toolchains")

aspect_bazel_lib_dependencies()

aspect_bazel_lib_register_toolchains()

register_coreutils_toolchains()

# OCI rules
load("//bazel/toolchains:oci_deps.bzl", "oci_deps")

Expand All @@ -232,7 +250,6 @@ oci_register_toolchains(
crane_version = LATEST_CRANE_VERSION,
)

load("@aspect_bazel_lib//lib:repositories.bzl", "register_yq_toolchains")
load("//bazel/toolchains:container_images.bzl", "containter_image_deps")

containter_image_deps()
Expand Down
7 changes: 5 additions & 2 deletions bazel/ci/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,13 @@ sh_template(
sh_template(
name = "terraform_docgen",
data = [
"@go_sdk//:bin/go",
":com_github_hashicorp_terraform",
"//terraform-provider-constellation:tf_provider",
"@terraform-plugin-docs//:bin/tfplugindocs"
],
substitutions = {
"@@GO@@": "$(rootpath @go_sdk//:bin/go)",
"@@TERRAFORM@@": "$(rootpath :com_github_hashicorp_terraform)",
"@@TFPLUGINDOCS@@": "$(rootpath @terraform-plugin-docs//:bin/tfplugindocs)"
},
template = "terraform_docgen.sh.in",
)
Expand Down
12 changes: 9 additions & 3 deletions bazel/ci/terraform_docgen.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ if ! source "${lib}"; then
exit 1
fi

go=$(realpath @@GO@@)
stat "${go}" >> /dev/null
terraform=$(realpath @@TERRAFORM@@)
stat "${terraform}" >> /dev/null
tfplugindocs=$(realpath @@TFPLUGINDOCS@@)
stat "${tfplugindocs}" >> /dev/null

cd "${BUILD_WORKSPACE_DIRECTORY}"

###### script body ######

TERRAFORM_PROVIDER_DIR=terraform-provider-constellation

# Use hermetic Terraform binary.
export PATH="$(dirname "${terraform}"):$PATH"
echo Using terraform at "$(command -v terraform)"

# TODO(msanft): Pin TF version or use built provider to generate schema and feed in here.
${go} run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate \
${tfplugindocs} generate \
--provider-dir ${TERRAFORM_PROVIDER_DIR} \
--provider-name constellation \
--rendered-provider-name Constellation
4 changes: 4 additions & 0 deletions bazel/devbuild/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ sh_template(
"//bootstrapper/cmd/bootstrapper:bootstrapper_linux_amd64",
"//cli:cli_edition_host",
"//debugd/cmd/cdbg:cdbg_host",
"//terraform-provider-constellation:terraform_rc",
"//terraform-provider-constellation:tf_provider",
"//upgrade-agent/cmd:upgrade_agent_linux_amd64",
"@yq_toolchains//:resolved_toolchain",
],
Expand All @@ -18,6 +20,8 @@ sh_template(
"@@CLI@@": "$(rootpath //cli:cli_edition_host)",
"@@CONTAINER_SUMS@@": "$(rootpath //bazel/release:container_sums)",
"@@EDITION@@": "$(rootpath :devbuild_cli_edition)",
"@@TERRAFORM_PROVIDER@@": "$(rootpath //terraform-provider-constellation:tf_provider)",
"@@TERRAFORM_RC@@": "$(rootpath //terraform-provider-constellation:terraform_rc)",
"@@UPGRADE_AGENT@@": "$(rootpath //upgrade-agent/cmd:upgrade_agent_linux_amd64)",
"@@YQ@@": "$(rootpath @yq_toolchains//:resolved_toolchain)",
},
Expand Down
10 changes: 10 additions & 0 deletions bazel/devbuild/prepare_developer_workspace.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ stat "${cdbg}" >> /dev/null
container_sums=$(realpath @@CONTAINER_SUMS@@)
stat "${container_sums}" >> /dev/null
edition=$(cat @@EDITION@@)
terraform_provider=$(realpath @@TERRAFORM_PROVIDER@@)
stat "${terraform_provider}" >> /dev/null
terraform_rc=$(realpath @@TERRAFORM_RC@@)
stat "${terraform_rc}" >> /dev/null

cd "${BUILD_WORKING_DIRECTORY}"

Expand Down Expand Up @@ -62,6 +66,12 @@ ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cdbg}")" "${workd
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${container_sums}")" "${workdir}/container_sums.sha256"
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cli}")" "${workdir}/constellation"

TF_PROVIDER_DIR="${workdir}/terraform"
mkdir -p "${TF_PROVIDER_DIR}"
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${terraform_provider}")" "${TF_PROVIDER_DIR}/terraform-provider-constellation"
cp "$(replace_prefix "${host_cache}" "${builder_cache}" "${terraform_rc}")" "${TF_PROVIDER_DIR}/config.tfrc"
sed -i "s|@@TERRAFORM_PROVIDER_PATH@@|${terraform_provider}|g" ${TF_PROVIDER_DIR}/config.tfrc

build_version=$("${cli}" version | grep ^Version: | awk '{print $2}')
if [[ ! -f "${workdir}/constellation-conf.yaml" ]]; then
echo "constellation-conf.yaml not present in workspace"
Expand Down
2 changes: 1 addition & 1 deletion bazel/settings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ config_setting(
stamp_tags(
# generates a container image version tag based on the version stamp
name = "tag",
repotags = [""""v"+($stamp.STABLE_STAMP_VERSION // "0.0.0")"""],
repotags = [""""v"+($stamp[0].STABLE_STAMP_VERSION // "0.0.0")"""],
visibility = ["//visibility:public"],
)
9 changes: 9 additions & 0 deletions bazel/toolchains/aspect_bazel_lib.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def aspect_bazel_lib():
http_archive(
name = "aspect_bazel_lib",
sha256 = "4b32cf6feab38b887941db022020eea5a49b848e11e3d6d4d18433594951717a",
strip_prefix = "bazel-lib-2.0.1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.0.1/bazel-lib-v2.0.1.tar.gz",
)
56 changes: 16 additions & 40 deletions bazel/toolchains/go_module_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1475,8 +1475,8 @@ def go_dependencies():
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/elazarl/goproxy",
sum = "h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0=",
version = "v0.0.0-20221015165544-a0805db90819",
sum = "h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU=",
version = "v0.0.0-20230808193330-2592e75ae04a",
)
go_repository(
name = "com_github_elazarl_goproxy_ext",
Expand Down Expand Up @@ -1747,8 +1747,8 @@ def go_dependencies():
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/go-git/go-billy/v5",
sum = "h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4=",
version = "v5.4.1",
sum = "h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=",
version = "v5.5.0",
)
go_repository(
name = "com_github_go_git_go_git_fixtures_v4",
Expand All @@ -1763,8 +1763,8 @@ def go_dependencies():
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/go-git/go-git/v5",
sum = "h1:Zo79E4p7TRk0xoRgMq0RShiTHGKcKI4+DI6BfJc/Q+A=",
version = "v5.8.1",
sum = "h1:cD9SFA7sHVRdJ7AYck1ZaAa/yeuBvGPxwXDL8cxrObY=",
version = "v5.9.0",
)
go_repository(
name = "com_github_go_gl_glfw",
Expand Down Expand Up @@ -2820,8 +2820,8 @@ def go_dependencies():
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/hashicorp/hc-install",
sum = "h1:fDHnU7JNFNSQebVKYhHZ0va1bC6SrPQ8fpebsvNr2w4=",
version = "v0.6.0",
sum = "h1:IGxShH7AVhPaSuSJpKtVi/EFORNjO+OYVJJrAtGG2mY=",
version = "v0.6.1",
)
go_repository(
name = "com_github_hashicorp_hcl",
Expand Down Expand Up @@ -2860,16 +2860,8 @@ def go_dependencies():
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/hashicorp/terraform-json",
sum = "h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA=",
version = "v0.17.1",
)
go_repository(
name = "com_github_hashicorp_terraform_plugin_docs",
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/hashicorp/terraform-plugin-docs",
sum = "h1:UmxFr3AScl6Wged84jndJIfFccGyBZn52KtMNsS12dI=",
version = "v0.16.0",
sum = "h1:pCjgJEqqDESv4y0Tzdqfxr/edOIGkjs8keY42xfNBwU=",
version = "v0.18.0",
)
go_repository(
name = "com_github_hashicorp_terraform_plugin_framework",
Expand Down Expand Up @@ -4312,8 +4304,8 @@ def go_dependencies():
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/ProtonMail/go-crypto",
sum = "h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs=",
version = "v0.0.0-20230717121422-5aa5874ade95",
sum = "h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg=",
version = "v0.0.0-20230828082145-3c4c8a2d2371",
)
go_repository(
name = "com_github_protonmail_go_mime",
Expand Down Expand Up @@ -4956,14 +4948,6 @@ def go_dependencies():
sum = "h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=",
version = "v4.0.4+incompatible",
)
go_repository(
name = "com_github_vmihailenco_msgpack_v4",
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/vmihailenco/msgpack/v4",
sum = "h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvCazn8G65U=",
version = "v4.3.12",
)
go_repository(
name = "com_github_vmihailenco_msgpack_v5",
build_file_generation = "on",
Expand All @@ -4972,14 +4956,6 @@ def go_dependencies():
sum = "h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=",
version = "v5.4.1",
)
go_repository(
name = "com_github_vmihailenco_tagparser",
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/vmihailenco/tagparser",
sum = "h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY=",
version = "v0.1.1",
)
go_repository(
name = "com_github_vmihailenco_tagparser_v2",
build_file_generation = "on",
Expand Down Expand Up @@ -5201,8 +5177,8 @@ def go_dependencies():
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/zclconf/go-cty",
sum = "h1:/Xrd39K7DXbHzlisFP9c4pHao4yyf+/Ug9LEz+Y/yhc=",
version = "v1.14.0",
sum = "h1:t9fyA35fwjjUMcmL5hLER+e/rEPqrbCK1/OSE4SI9KA=",
version = "v1.14.1",
)
go_repository(
name = "com_github_zclconf_go_cty_debug",
Expand Down Expand Up @@ -7164,8 +7140,8 @@ def go_dependencies():
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/text",
sum = "h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=",
version = "v0.13.0",
sum = "h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=",
version = "v0.14.0",
)
go_repository(
name = "org_golang_x_time",
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ require (
github.com/hashicorp/hc-install v0.5.2
github.com/hashicorp/hcl/v2 v2.17.0
github.com/hashicorp/terraform-exec v0.18.1
github.com/hashicorp/terraform-json v0.15.0
github.com/hashicorp/terraform-json v0.17.1
github.com/martinjungblut/go-cryptsetup v0.0.0-20220520180014-fd0874fd07a6
github.com/mattn/go-isatty v0.0.19
github.com/microsoft/ApplicationInsights-Go v0.4.4
Expand Down Expand Up @@ -325,7 +325,7 @@ require (
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
Expand Down
Loading

0 comments on commit 288cff2

Please sign in to comment.