# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           select 1.0

name                terragrunt
categories          sysutils
license             MIT
platforms           darwin linux
homepage            https://terragrunt.gruntwork.io

maintainers         {mjrc.nl:macports @mjrc} openmaintainer




# *NOTE* Remember to update `latestVersion` on a version upgrade.
set latestVersion       terragrunt-0.27

subport terragrunt-0.27 {
    set dependsOn       0.14
    set patchNumber    0

    checksums           rmd160  22cc7f81c24718c39cf1aaa57266590775bf6dea \
                        sha256  051eeb79c326bc6ccc734418a15366d9cef9880a1c5fdee0304d818e0ccb8a25 \
                        size    2184321
}

subport terragrunt-0.26 {
    set dependsOn       0.13
    set patchNumber    7

    checksums           rmd160  d17297226396d511ba7e14cf44cb18a33d76fe51 \
                        sha256  291246e6ccfd0f1c18712de4f85fc63bcae49bc20fd54330af109daf5d186330 \
                        size    2178214
}

subport terragrunt-0.24 {
    set dependsOn       0.12
    set patchNumber     4

    checksums           rmd160  5c23e704d7192b4de32c824663598a3466729b7f \
                        sha256  cc9c56fcbd299f59055b92f1f6258c9ea1610609c1d29a3ca5d32ac93577e335 \
                        size    2029411
}

subport terragrunt_select {}

if {${subport} == ${name}} {
    PortGroup           obsolete 1.0

    replaced_by         ${latestVersion}
    version             0.27.0
    revision            0

} elseif {${subport} eq "terragrunt_select"} {
    version             0.0.0
    revision            0
    supported_archs     noarch

    description         Common files for selecting the default terragrunt \
                        version
    long_description    This port installs files that allow 'port select' \
                        to create links to the preferred default version \
                        of terragrunt.
    homepage            https://www.macports.org/

    distfiles
    use_configure       no
    build {}

    destroot {
        select::install terragrunt ${filespath}/base
        select::install terragrunt ${filespath}/none
    }

    livecheck.type     none

} else {

    PortGroup           golang 1.0

    supported_archs     x86_64

    depends_run         port:terragrunt_select port:terraform-${dependsOn}

    set baseVersion     [lindex [split ${subport} "-"] 1]
    set patchVersion    ${baseVersion}.${patchNumber}
    set baseName        terragrunt${baseVersion}

    go.setup            github.com/gruntwork-io/terragrunt ${patchVersion} v

    description         Terragrunt is a thin wrapper for Terraform
    long_description    ${description} that provides extra tools for working \
                        with multiple Terraform modules.

    set go_ldflags      "-X main.VERSION=${patchVersion}"

    # FIXME: This port currently can't be built without allowing go mod to fetch
    # dependencies during the build phase. See
    # https://trac.macports.org/ticket/61192
    build.env-delete    GOPROXY=off GO111MODULE=off
    build.args          -ldflags \"${go_ldflags}\" -o ${baseName} ${go.package}

    patchfiles          patch-options.go.diff

    post-patch {
        reinplace "s|@@TERRAFORM_BIN@@|terraform${dependsOn}|g" ${worksrcpath}/options/options.go
    }

    post-build {
        file copy ${filespath}/terragruntX.YY.template ${workpath}/${baseName}
        reinplace "s|@@BASE_VERSION@@|${baseVersion}|g" ${workpath}/${baseName}
    }

    destroot {
        xinstall -m 755 ${worksrcpath}/${baseName} ${destroot}${prefix}/bin/${baseName}
    }

    select.group        terragrunt
    select.file         ${workpath}/${baseName}

    notes "
    To make this the default terragrunt run:
        sudo port select --set terragrunt ${baseName}
    "


}
