# -*- 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.38

subport terragrunt-0.38 {
    set dependsOn       1.2
    set patchNumber     7

    checksums           rmd160  e295b0e90a6ec7f7a0a31c8c683fe1621c878b71 \
                        sha256  19ae411c3206857b655976c8d4b972113be90592dac9f73050449e27ee8aeda3 \
                        size    2299205
}

subport terragrunt-0.37 {
    set dependsOn       1.1
    set patchNumber     4

    checksums           rmd160  05c2c7f530cf1057c7a1cae0617fffb0ca353c16 \
                        sha256  b2dc6468535e057cf01b7aa5d6b40c74717e0c3b5501a14bb8bb4420136e0a52 \
                        size    2292470
}

subport terragrunt-0.36 {
    set dependsOn       1.1
    set patchNumber     12

    checksums           rmd160  83934e8373eda08aa64391031975195bc059ce6c \
                        sha256  91a6f41056971d231de1b0786ee92019608cda9aa1066fe66119dafd94919024 \
                        size    2288539
}

subport terragrunt-0.35 {
    set dependsOn       1.0
    set patchNumber     20

    checksums           rmd160  5e29cc8cb9adee6612bd76fb7405027231548cd0 \
                        sha256  4b3ea8406e2a42e066148a073cba3413be65f2edb0e4e528d033533774aeefa3 \
                        size    2281426
}

subport terragrunt-0.34 {
    set dependsOn       1.0
    set patchNumber     3

    checksums           rmd160  87f15774fe41a8e2ebe893ce5cfd19dfb813cfc8 \
                        sha256  8885e91d853d9f2284fa6e11d88160d040130cb547595f2f90ad34a1e9fd115f \
                        size    2268245
}

subport terragrunt-0.33 {
    set dependsOn       1.0
    set patchNumber     2

    checksums           rmd160  783302b6ca6845d8743e8cf0ad3da071877e4f76 \
                        sha256  567b61a8f4a739f115e980ee665773584ffe8b01ae306f0dd13b7d0d6c341105 \
                        size    2264318
}

subport terragrunt-0.32 {
    set dependsOn       1.0
    set patchNumber     6

    checksums           rmd160  20a04e3d928d06565327f37e5bed5117ff7d6031 \
                        sha256  a58e87b8a99e3adbfdde5807453236dccd1186e1d100e33aa546d3cecea6b985 \
                        size    2259950
}

subport terragrunt-0.31 {
    set dependsOn       1.0
    set patchNumber     11

    checksums           rmd160  b18d043e757af99213c4668b57f28f2217b4941f \
                        sha256  9ebde9edc147121fada2ecdcb90fd21b67592ee13720401835ed7dae3a1bb091 \
                        size    2246065
}

subport terragrunt-0.29 {
    set dependsOn       0.15
    set patchNumber     4

    checksums           rmd160  26ac8c2618aa7ca869ee45dc8eb55027e2f75159 \
                        sha256  4ee3db5390f93bfe43b49f45a2904d9ebe91179a1d154beb8b43a0a24ba650c3 \
                        size    2232674
}

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 arm64

    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}
    "


}
