3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 function terraform_apply () {
21 # Run terraform apply command to prepare topology.
24 # - ${CSIT_DIR} - CSIT main directory, where terraform modules are located.
25 # - ${NODENESS} - Node multiplicity of desired testbed.
26 # - ${FLAVOR} - Node flavor string, see common.sh
30 if ! installed terraform; then
31 die "Please install terraform!"
34 pushd "${CSIT_DIR}"/fdio.infra.terraform || die "Pushd failed!"
35 pushd "${NODENESS}_${FLAVOR}_c5n" || die "Pushd failed!"
37 terraform apply -no-color -auto-approve || die "Terraform apply failed!"
38 popd || die "Popd failed!"
39 popd || die "Popd failed!"
42 function terraform_destroy () {
44 # Run terraform destroy command to prepare module.
47 # - ${CSIT_DIR} - CSIT main directory, where terraform modules are located.
48 # - ${NODENESS} - Node multiplicity of desired testbed.
49 # - ${FLAVOR} - Node flavor string, see common.sh
53 if ! installed terraform; then
54 die "Please install terraform!"
57 pushd "${CSIT_DIR}"/fdio.infra.terraform || die "Pushd failed!"
58 pushd "${NODENESS}_${FLAVOR}_c5n" || die "Pushd failed!"
60 terraform destroy -auto-approve -no-color || die "Terraform destroy failed!"
61 popd || die "Popd failed!"
62 popd || die "Popd failed!"
66 function terraform_init () {
68 # Run terraform init command to prepare module.
71 # - ${CSIT_DIR} - CSIT main directory, where terraform modules are located.
72 # - ${NODENESS} - Node multiplicity of desired testbed.
73 # - ${FLAVOR} - Node flavor string, see common.sh
77 if ! installed terraform; then
78 curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
79 os="$(lsb_release -cs)" || die "Failed to get OS release!"
80 repo="deb [arch=amd64] https://apt.releases.hashicorp.com ${os} main"
81 sudo apt-add-repository "${repo}" || die "Failed to add repo!"
83 apt install -y terraform
84 #die "Please install terraform!"
87 pushd "${CSIT_DIR}"/fdio.infra.terraform || die "Pushd failed!"
88 pushd "${NODENESS}_${FLAVOR}_c5n" || die "Pushd failed!"
90 plugin_url="https://github.com/radekg/terraform-provisioner-ansible/"
91 plugin_url+="releases/download/v2.5.0/"
92 plugin_url+="terraform-provisioner-ansible-linux-amd64_v2.5.0"
93 plugin_dir="${HOME}/.terraform.d/plugins/"
94 plugin_path+="${plugin_dir}terraform-provisioner-ansible_v2.5.0"
96 mkdir -p "${plugin_dir}" || die "Failed to create dir!"
97 wget -O "${plugin_path}" "${plugin_url}" || die "Failed to download plugin!"
98 chmod +x "${plugin_path}" || die "Failed to add execute rights!"
101 terraform init || die "Failed to run terraform init!"
103 popd || die "Popd failed!"
104 popd || die "Popd failed!"
108 function installed () {
110 # Check if the given utility is installed. Fail if not installed.
113 # - ${1} - Utility to check.
114 # Returns (implicitly):
115 # - 0 - If command is installed.
116 # - 1 - If command is not installed.