File terraform.spec of Package terraform

%define realname terraform
%define realver  1.7.3
%define srcext   tar.gz

%if ! 0%{?go_os:1}
%define go_os %(go env GOOS)
%endif
%if ! 0%{?go_arch:1}
%define go_arch %(go env GOARCH)
%endif

# Common info
Name:          %{realname}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       MPL-2.0
Group:         System/Management
URL:           https://www.terraform.io
Summary:       Infrastructure as code software tool for cloud services

# Build-time parameters
BuildRequires: go
BuildRoot:     %{_tmppath}/%{name}-root
Source:        https://codeload.github.com/hashicorp/terraform/%{srcext}/refs/tags/v%{realver}#/%{realname}-%{realver}%{?extraver}.%{srcext}
# go mod vendor -v && tar -Jcvf ../vendor.tar.xz vendor && rm -rf vendor/
Source11:      vendor.tar.xz

%description
Terraform enables you to safely and predictably create, change, and improve
infrastructure. It is an open source tool that codifies APIs into declarative
configuration files that can be shared amongst team members, treated as code,
edited, reviewed, and versioned.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver} -a11

# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS='%{optflags}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro'
export GOPATH=$(pwd -P)/.gomodules
export GOCACHE=$(pwd -P)/.gocache
export GOTRACEBACK=crash
export CGO_ENABLED=1
export CGO_CFLAGS="$_CFLAGS"
export CGO_LDFLAGS="$_LDFLAGS"
go build -v -mod=vendor -buildmode=pie \
    -gcflags=all=-dwarf=false \
    -ldflags='all=-s -w -X main.GitCommit=v%{version}' \
    -o bin/terraform

# Install built stuff
%install
%{__install} -D -m0755 bin/terraform %{buildroot}%{_bindir}/terraform
%{__install} -d -m0755 %{buildroot}%{_datadir}/bash-completion/completions
echo 'complete -C %{_bindir}/terraform terraform' > %{buildroot}%{_datadir}/bash-completion/completions/terraform

# Cleanup
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

# Files
%files
%defattr(-,root,root)
%license LICENSE
%doc CHANGELOG.md README.md docs/
%{_bindir}/terraform
%dir %{_datadir}/bash-completion/completions
%dir %{_datadir}/bash-completion
%{_datadir}/bash-completion/completions/terraform

%changelog
openSUSE Build Service is sponsored by