Skip to content

Commit

Permalink
Merge pull request #9 from lorengordon/skip-repo
Browse files Browse the repository at this point in the history
 Skips modules if salt version is an empty string
  • Loading branch information
lorengordon authored May 16, 2018
2 parents 651fe6a + c73a592 commit 5575e28
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.0.0
current_version = 2.0.1
commit = True
message = Bumps version to {new_version}
tag = False
Expand Down
27 changes: 18 additions & 9 deletions defs/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
locals {
skip_module = "${var.salt_version == ""}"
salt_versions = "${sort(distinct(concat(list(var.salt_version), var.extra_salt_versions)))}"
repo_prefix = "${replace("${var.s3_endpoint}/${var.bucket_name}/${var.repo_prefix}", "/[/]$/", "")}"
}

data "null_data_source" "amzn" {
count = "${length(local.salt_versions)}"
count = "${local.skip_module ? 0 : length(local.salt_versions)}"

inputs {
name = "salt-reposync-amzn"
Expand All @@ -14,7 +15,7 @@ data "null_data_source" "amzn" {
}

data "null_data_source" "el6" {
count = "${length(local.salt_versions)}"
count = "${local.skip_module ? 0 : length(local.salt_versions)}"

inputs {
name = "salt-reposync-el6"
Expand All @@ -24,7 +25,7 @@ data "null_data_source" "el6" {
}

data "null_data_source" "el7" {
count = "${length(local.salt_versions)}"
count = "${local.skip_module ? 0 : length(local.salt_versions)}"

inputs {
name = "salt-reposync-el7"
Expand All @@ -34,7 +35,7 @@ data "null_data_source" "el7" {
}

data "template_file" "amzn" {
count = "${length(local.salt_versions)}"
count = "${local.skip_module ? 0 : length(local.salt_versions)}"

template = "${file("${path.module}/yum.repo")}"

Expand All @@ -46,7 +47,7 @@ data "template_file" "amzn" {
}

data "template_file" "el6" {
count = "${length(local.salt_versions)}"
count = "${local.skip_module ? 0 : length(local.salt_versions)}"

template = "${file("${path.module}/yum.repo")}"

Expand All @@ -58,7 +59,7 @@ data "template_file" "el6" {
}

data "template_file" "el7" {
count = "${length(local.salt_versions)}"
count = "${local.skip_module ? 0 : length(local.salt_versions)}"

template = "${file("${path.module}/yum.repo")}"

Expand All @@ -70,37 +71,43 @@ data "template_file" "el7" {
}

resource "local_file" "amzn" {
count = "${length(local.salt_versions)}"
count = "${local.skip_module ? 0 : length(local.salt_versions)}"

content = "${data.template_file.amzn.*.rendered[count.index]}"
filename = "${var.cache_dir}/${local.salt_versions[count.index]}/salt-reposync-amzn}"
}

resource "local_file" "el6" {
count = "${length(local.salt_versions)}"
count = "${local.skip_module ? 0 : length(local.salt_versions)}"

content = "${data.template_file.el6.*.rendered[count.index]}"
filename = "${var.cache_dir}/${local.salt_versions[count.index]}/salt-reposync-el6}"
}

resource "local_file" "el7" {
count = "${length(local.salt_versions)}"
count = "${local.skip_module ? 0 : length(local.salt_versions)}"

content = "${data.template_file.el7.*.rendered[count.index]}"
filename = "${var.cache_dir}/${local.salt_versions[count.index]}/salt-reposync-el7}"
}

resource "local_file" "amzn_default" {
count = "${local.skip_module ? 0 : 1}"

content = "${data.template_file.amzn.*.rendered[index(local.salt_versions, var.salt_version)]}"
filename = "${var.cache_dir}/salt-reposync-amzn"
}

resource "local_file" "el6_default" {
count = "${local.skip_module ? 0 : 1}"

content = "${data.template_file.el6.*.rendered[index(local.salt_versions, var.salt_version)]}"
filename = "${var.cache_dir}/salt-reposync-el6"
}

resource "local_file" "el7_default" {
count = "${local.skip_module ? 0 : 1}"

content = "${data.template_file.el7.*.rendered[index(local.salt_versions, var.salt_version)]}"
filename = "${var.cache_dir}/salt-reposync-el7"
}
Expand All @@ -119,6 +126,8 @@ locals {
}

resource "null_resource" "push" {
count = "${local.skip_module ? 0 : 1}"

provisioner "local-exec" {
command = "${join(" ", local.s3_command)}"
}
Expand Down
5 changes: 5 additions & 0 deletions repo/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
locals {
skip_module = "${var.salt_version == ""}"
salt_versions = "${sort(distinct(concat(list(var.salt_version), var.extra_salt_versions)))}"
salt_versions_include = "${formatlist("--include \"*/%s/**\"", local.salt_versions)}"
}
Expand All @@ -17,6 +18,8 @@ locals {
}

resource "null_resource" "pull" {
count = "${local.skip_module ? 0 : 1}"

provisioner "local-exec" {
command = "${join(" ", local.rsync_command)}"
}
Expand All @@ -40,6 +43,8 @@ locals {
}

resource "null_resource" "push" {
count = "${local.skip_module ? 0 : 1}"

provisioner "local-exec" {
command = "${join(" ", local.s3_command)}"
}
Expand Down

0 comments on commit 5575e28

Please sign in to comment.