Skip to content

Commit b1bfceb

Browse files
authored
fix: use terraform_data instead of null_resource (#924)
1 parent 28b6f26 commit b1bfceb

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ Optionally, you need the following permissions to attach Access Management tags
366366
| [kubernetes_config_map_v1_data.set_autoscaling](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/config_map_v1_data) | resource |
367367
| [null_resource.config_map_status](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
368368
| [null_resource.confirm_network_healthy](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
369-
| [null_resource.install_required_binaries](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
370369
| [null_resource.ocp_console_management](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
370+
| [terraform_data.install_required_binaries](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
371371
| [time_sleep.wait_for_auth_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
372372
| [external_external.ocp_addon_versions](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external) | data source |
373373
| [ibm_container_addons.existing_addons](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_addons) | data source |

main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ locals {
125125
default_wp_validation = local.rhcos_check ? true : tobool("If RHCOS is used with this cluster, the default worker pool should be created with RHCOS.")
126126
}
127127

128-
resource "null_resource" "install_required_binaries" {
128+
resource "terraform_data" "install_required_binaries" {
129129
count = var.install_required_binaries && (var.verify_worker_network_readiness || var.enable_ocp_console != null || lookup(var.addons, "cluster-autoscaler", null) != null) ? 1 : 0
130-
triggers = {
130+
triggers_replace = {
131131
verify_worker_network_readiness = var.verify_worker_network_readiness
132132
cluster_autoscaler = lookup(var.addons, "cluster-autoscaler", null) != null
133133
enable_ocp_console = var.enable_ocp_console
@@ -516,7 +516,7 @@ resource "null_resource" "confirm_network_healthy" {
516516
# Worker pool creation can start before the 'ibm_container_vpc_cluster' completes since there is no explicit
517517
# depends_on in 'ibm_container_vpc_worker_pool', just an implicit depends_on on the cluster ID. Cluster ID can exist before
518518
# 'ibm_container_vpc_cluster' completes, so hence need to add explicit depends on against 'ibm_container_vpc_cluster' here.
519-
depends_on = [null_resource.install_required_binaries, ibm_container_vpc_cluster.cluster, ibm_container_vpc_cluster.cluster_with_upgrade, ibm_container_vpc_cluster.autoscaling_cluster, ibm_container_vpc_cluster.autoscaling_cluster_with_upgrade, module.worker_pools]
519+
depends_on = [terraform_data.install_required_binaries, ibm_container_vpc_cluster.cluster, ibm_container_vpc_cluster.cluster_with_upgrade, ibm_container_vpc_cluster.autoscaling_cluster, ibm_container_vpc_cluster.autoscaling_cluster_with_upgrade, module.worker_pools]
520520

521521
triggers = {
522522
verify_worker_network_readiness = var.verify_worker_network_readiness
@@ -536,7 +536,7 @@ resource "null_resource" "confirm_network_healthy" {
536536
##############################################################################
537537
resource "null_resource" "ocp_console_management" {
538538
count = var.enable_ocp_console != null ? 1 : 0
539-
depends_on = [null_resource.install_required_binaries, null_resource.confirm_network_healthy]
539+
depends_on = [terraform_data.install_required_binaries, null_resource.confirm_network_healthy]
540540
triggers = {
541541
enable_ocp_console = var.enable_ocp_console
542542
}
@@ -613,7 +613,7 @@ locals {
613613

614614
resource "null_resource" "config_map_status" {
615615
count = lookup(var.addons, "cluster-autoscaler", null) != null ? 1 : 0
616-
depends_on = [null_resource.install_required_binaries, ibm_container_addons.addons]
616+
depends_on = [terraform_data.install_required_binaries, ibm_container_addons.addons]
617617

618618
triggers = {
619619
cluster_autoscaler = lookup(var.addons, "cluster-autoscaler", null) != null

modules/kube-audit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ No modules.
7070
| Name | Type |
7171
|------|------|
7272
| [helm_release.kube_audit](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
73-
| [null_resource.install_required_binaries](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
7473
| [null_resource.set_audit_log_policy](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
7574
| [null_resource.set_audit_webhook](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
75+
| [terraform_data.install_required_binaries](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
7676
| [time_sleep.wait_for_kube_audit](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
7777
| [ibm_container_cluster_config.cluster_config](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_cluster_config) | data source |
7878
| [ibm_container_vpc_cluster.cluster](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_vpc_cluster) | data source |

modules/kube-audit/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ locals {
22
binaries_path = "/tmp"
33
}
44

5-
resource "null_resource" "install_required_binaries" {
5+
resource "terraform_data" "install_required_binaries" {
66
count = var.install_required_binaries ? 1 : 0
7-
triggers = {
7+
triggers_replace = {
88
audit_log_policy = var.audit_log_policy
99
audit_deployment_name = var.audit_deployment_name
1010
audit_namespace = var.audit_namespace
@@ -38,7 +38,7 @@ locals {
3838
}
3939

4040
resource "null_resource" "set_audit_log_policy" {
41-
depends_on = [null_resource.install_required_binaries]
41+
depends_on = [terraform_data.install_required_binaries]
4242
triggers = {
4343
audit_log_policy = var.audit_log_policy
4444
}
@@ -60,7 +60,7 @@ locals {
6060
}
6161

6262
resource "helm_release" "kube_audit" {
63-
depends_on = [null_resource.install_required_binaries, null_resource.set_audit_log_policy, data.ibm_container_vpc_cluster.cluster]
63+
depends_on = [terraform_data.install_required_binaries, null_resource.set_audit_log_policy, data.ibm_container_vpc_cluster.cluster]
6464
name = var.audit_deployment_name
6565
chart = local.kube_audit_chart_location
6666
timeout = 1200
@@ -116,7 +116,7 @@ locals {
116116
# }
117117

118118
resource "null_resource" "set_audit_webhook" {
119-
depends_on = [null_resource.install_required_binaries, time_sleep.wait_for_kube_audit]
119+
depends_on = [terraform_data.install_required_binaries, time_sleep.wait_for_kube_audit]
120120
triggers = {
121121
audit_log_policy = var.audit_log_policy
122122
}

modules/kube-audit/scripts/install-binaries.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ set -o errexit
88
set -o pipefail
99

1010
DIRECTORY=${1:-"/tmp"}
11+
export PATH=$PATH:$DIRECTORY
1112
# renovate: datasource=github-tags depName=terraform-ibm-modules/common-bash-library
1213
TAG=v0.2.0
1314
# Running multiple Terraform executions on the same environment that share a /tmp directory can lead to conflicts during script execution.
14-
SUFFIX=""
15-
for _ in {1..4}; do
16-
SUFFIX+=${RANDOM:0:1}
17-
done
15+
TMP_DIR=$(mktemp -d "${DIRECTORY}/common-bash-XXXXX")
1816

1917
echo "Downloading common-bash-library version ${TAG}."
2018

@@ -28,22 +26,22 @@ curl --silent \
2826
--fail \
2927
--show-error \
3028
--location \
31-
--output "${DIRECTORY}/common-bash-${SUFFIX}.tar.gz" \
29+
--output "${TMP_DIR}/common-bash.tar.gz" \
3230
"https://github.com/terraform-ibm-modules/common-bash-library/archive/refs/tags/$TAG.tar.gz"
3331

34-
mkdir -p "${DIRECTORY}/common-bash-library-${SUFFIX}"
35-
tar -xzf "${DIRECTORY}/common-bash-${SUFFIX}.tar.gz" -C "${DIRECTORY}/common-bash-library-${SUFFIX}"
36-
rm -f "${DIRECTORY}/common-bash-${SUFFIX}.tar.gz"
32+
mkdir -p "${TMP_DIR}/common-bash-library"
33+
tar -xzf "${TMP_DIR}/common-bash.tar.gz" -C "${TMP_DIR}"
34+
rm -f "${TMP_DIR}/common-bash.tar.gz"
3735

3836
# The file doesn’t exist at the time shellcheck runs, so this check is skipped.
3937
# shellcheck disable=SC1091,SC1090
40-
source "${DIRECTORY}/common-bash-library-${SUFFIX}/common-bash-library-${TAG#v}/common/common.sh"
38+
source "${TMP_DIR}/common-bash-library-${TAG#v}/common/common.sh"
4139

4240
echo "Installing jq."
4341
install_jq "latest" "${DIRECTORY}" "true"
4442
echo "Installing kubectl."
4543
install_kubectl "latest" "${DIRECTORY}" "true"
4644

47-
rm -rf "${DIRECTORY}/common-bash-library-${SUFFIX}"
45+
rm -rf "$TMP_DIR"
4846

4947
echo "Installation complete successfully"

0 commit comments

Comments
 (0)