From patchwork Mon Feb 24 19:12:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13988830 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DE781EDA24 for ; Mon, 24 Feb 2025 19:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740424339; cv=none; b=AogDB+l0xSDE+GwEyotWCB88+nfF/1NPFgl/zuOC2Lj0X+piNfTjBpYN1krBNxo0FC2Zl1HpuQgQZoiN0YiJvH6DNqlwSfyIG2E9/jCGu46W6bkVVP+BWKTq+uw7NZXcFH7usrLY/5jv0pwXUe43DvEPFHfjnCeQhx/FU1mmPdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740424339; c=relaxed/simple; bh=LtZk+GMYIn9UI6B8EuHoRlImuEaCycKYBY/uSjIDfuQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tv5KFN/AiLARUoN5qlSQq8IIagqEZStz/Wdmuk3Jo5C54Xf4QtTUgsydbiGwGshlWdSEcpxYIW/lQqCfKT8/HkGFTjCyQpvM18KA49a7l498mB8HJHFnhoUjclnv7gCrZFJKQ37GtTJpX5h9emM8EQR3kyGWSV5kfxT1j7e7B4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UmaEd9jT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UmaEd9jT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D352EC4CEEA; Mon, 24 Feb 2025 19:12:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740424339; bh=LtZk+GMYIn9UI6B8EuHoRlImuEaCycKYBY/uSjIDfuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UmaEd9jTzkEtTiHG7CcJ0ky/YKnnIpu6vUkKb46U7WYbR38EvhXRIotF7HmvM/EZ+ 1VS99SGavd6aGCLpoC1JfIKgKV4e7DkocobtWctQhempxsEznoFKGxeu0Yn2ZK5OIb 0+RxIYsEIgMFWuuN2UqFTexc0Cf+0aFnRTVNJcKhVzFbrOBy7WzvxblS4qoXnid/pk 1nt5YJzusaAJ9qBkI4didBiFJ1HrtXZxluu4GZesmkpu0ZYGWIwJcoGcIiNMaZmGx4 2CYkfjDQUTYnx6c1VdrfX2Fy2z7c4OY4OHTf/U8smFU1wbD4V882Ci5APdIetbPseL dfU1+abfUAAnQ== From: cel@kernel.org To: Cc: Chuck Lever Subject: [PATCH v3 1/6] terraform: Replace scripts/*_terraform.sh with an Ansible playbook Date: Mon, 24 Feb 2025 14:12:10 -0500 Message-ID: <20250224191215.637818-2-cel@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224191215.637818-1-cel@kernel.org> References: <20250224191215.637818-1-cel@kernel.org> Precedence: bulk X-Mailing-List: kdevops@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever Refactor: Combine separate terraform scripts into one playbook, adopting declarative infrastructure-as-code mechanisms rather than shell scripts. This also makes it simple to iterate over all defined target nodes -- that's Ansible's bread and butter. Terraform-specific Ansible-based ssh configuration can now easily be introduced. Note that the terraform actions are now silent unless an error occurs. Signed-off-by: Chuck Lever --- playbooks/roles/terraform/tasks/main.yml | 18 ++++++++++++++++++ playbooks/terraform.yml | 5 +++++ scripts/bringup_terraform.sh | 12 ------------ scripts/destroy_terraform.sh | 10 ---------- scripts/terraform.Makefile | 12 ++++++++++-- 5 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 playbooks/roles/terraform/tasks/main.yml create mode 100644 playbooks/terraform.yml delete mode 100755 scripts/bringup_terraform.sh delete mode 100755 scripts/destroy_terraform.sh diff --git a/playbooks/roles/terraform/tasks/main.yml b/playbooks/roles/terraform/tasks/main.yml new file mode 100644 index 000000000000..e328ea7bc0b2 --- /dev/null +++ b/playbooks/roles/terraform/tasks/main.yml @@ -0,0 +1,18 @@ +--- +- name: Bring up terraform resources + community.general.terraform: + project_path: "{{ topdir_path }}/terraform/{{ kdevops_terraform_provider }}" + state: present + force_init: true + tags: + - bringup + +- name: Destroy terraform resources + delegate_to: localhost + run_once: true + community.general.terraform: + project_path: "{{ topdir_path }}/terraform/{{ kdevops_terraform_provider }}" + state: absent + force_init: true + tags: + - destroy diff --git a/playbooks/terraform.yml b/playbooks/terraform.yml new file mode 100644 index 000000000000..374a76fb0ae7 --- /dev/null +++ b/playbooks/terraform.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + gather_facts: false + roles: + - role: terraform diff --git a/scripts/bringup_terraform.sh b/scripts/bringup_terraform.sh deleted file mode 100755 index 427962ac6eb9..000000000000 --- a/scripts/bringup_terraform.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: copyleft-next-0.3.1 - -set -e - -source ${TOPDIR}/.config -source ${TOPDIR}/scripts/lib.sh - -cd terraform/${KDEVOPS_CLOUD_PROVIDER} -terraform init -terraform plan -terraform apply -auto-approve diff --git a/scripts/destroy_terraform.sh b/scripts/destroy_terraform.sh deleted file mode 100755 index 58d467a40c07..000000000000 --- a/scripts/destroy_terraform.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: copyleft-next-0.3.1 - -set -e - -source ${TOPDIR}/.config -source ${TOPDIR}/scripts/lib.sh - -cd terraform/${KDEVOPS_CLOUD_PROVIDER} -terraform destroy -auto-approve diff --git a/scripts/terraform.Makefile b/scripts/terraform.Makefile index 888d3af88e3e..2436571a4aac 100644 --- a/scripts/terraform.Makefile +++ b/scripts/terraform.Makefile @@ -164,10 +164,18 @@ endif # CONFIG_TERRAFORM_SSH_CONFIG_GENKEY ANSIBLE_EXTRA_ARGS += $(TERRAFORM_EXTRA_VARS) bringup_terraform: - $(Q)$(TOPDIR)/scripts/bringup_terraform.sh + $(Q)ansible-playbook $(ANSIBLE_VERBOSE) \ + --connection=local --inventory localhost, \ + playbooks/terraform.yml --tags bringup \ + --extra-vars=@./extra_vars.yaml \ + -e 'ansible_python_interpreter=/usr/bin/python3' destroy_terraform: - $(Q)$(TOPDIR)/scripts/destroy_terraform.sh + $(Q)ansible-playbook $(ANSIBLE_VERBOSE) \ + --connection=local -i $(KDEVOPS_HOSTFILE) \ + playbooks/terraform.yml --tags destroy \ + --extra-vars=@./extra_vars.yaml \ + -e 'ansible_python_interpreter=/usr/bin/python3' $(Q)rm -f $(KDEVOPS_PROVISIONED_DEVCONFIG) $(KDEVOPS_TFVARS): $(KDEVOPS_TFVARS_TEMPLATE) .config