Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce re-usable gh actions #60

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/actions/create-sap-btp-kyma/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: 'Create SAP BTP Kyma Environment'
description: 'Action for creating Kyma environment in the SAP BTP Platform'

inputs:
btp_subaccount_name:
description: 'Name of the new SAP BTP subaccount to be created'
required: true
btp_backend_url:
description: 'URL of the BTP CLI API'
required: true
btp_user:
description: 'SAP BTP username on behalf of whom the BTP platform resources are created'
required: true
btp_password:
description: 'SAP BTP user password'
required: true
btp_global_account:
description: 'Global account in the context of which the BTP platform resources are created'
required: true
btp_idp_tenant:
description: 'Identity provider that recognizes identity of the given username'
required: true
btp_subaccount_region:
description: 'Region of the new SAP BTP platform where new subaccount will be created'
required: true
btp_kyma_region:
description: 'Region where Kyma environment will be created'
required: true
btp_kyma_plan:
description: 'Service plan of the kyma environment'
required: true
btp_kyma_modules:
description: 'String representation of the requested kyma modules list that should be pre-installed on the kyma environments'
required: false
default: "[{name = 'istio', channel = 'fast'},{name = 'api-gateway', channel = 'fast'},{name = 'btp-operator', channel = 'fast'}]"
btp_kyma_autoscaler_min:
description: 'Minimum numbers of worker nodes the new kyma environment shoud start with'
required: false
default: '3'

outputs:
subaccount_id:
value: ${{ steps.create-btp-resources.outputs.subaccount_id }}
description: "ID of the created SAP BTP subaccount"

runs:
using: 'composite'
steps:
- name: Create btp resources
id: create-btp-resources
run: |
terraform -chdir=${{ github.action_path }} init
terraform -chdir=${{ github.action_path }} apply -auto-approve
SUBACCOUNT_ID=$(terraform -chdir=${{ github.action_path }} output -raw subaccount_id)
echo ${SUBACCOUNT_ID}
echo "subaccount_id=$SUBACCOUNT_ID" >> "$GITHUB_OUTPUT"
echo "KUBECONFIG=${{ github.action_path }}/kubeconfig.yaml" >> "$GITHUB_ENV"
shell: bash
env:
TF_VAR_BTP_NEW_SUBACCOUNT_NAME: ${{ inputs.btp_subaccount_name }}
TF_VAR_BTP_NEW_SUBACCOUNT_REGION: ${{ inputs.btp_subaccount_region }}
TF_VAR_BTP_BACKEND_URL: ${{ inputs.btp_backend_url }}
TF_VAR_BTP_BOT_USER: ${{ inputs.btp_user }}
TF_VAR_BTP_BOT_PASSWORD: ${{ inputs.btp_password }}
TF_VAR_BTP_CUSTOM_IAS_TENANT: ${{ inputs.btp_idp_tenant }}
TF_VAR_BTP_GLOBAL_ACCOUNT: ${{ inputs.btp_global_account }}
TF_VAR_BTP_KYMA_PLAN: ${{ inputs.btp_kyma_plan }}
TF_VAR_BTP_KYMA_REGION: ${{ inputs.btp_kyma_region }}
TF_VAR_BTP_KYMA_MODULES_STRINGIFIED: ${{ inputs.btp_kyma_modules }}
TF_VAR_BTP_KYMA_AUTOSCALER_MIN: ${{ inputs.btp_kyma_autoscaler_min }}

46 changes: 46 additions & 0 deletions .github/actions/create-sap-btp-kyma/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
terraform {
required_providers {
btp = {
source = "SAP/btp"
version = ">= 1.7.0"
}
http = {
source = "hashicorp/http"
}
http-full = {
source = "salrashid123/http-full"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.32.0"
}
}
}

provider "http" {}
provider "http-full" {}
provider "btp" {
globalaccount = var.BTP_GLOBAL_ACCOUNT
cli_server_url = var.BTP_BACKEND_URL
idp = var.BTP_CUSTOM_IAS_TENANT
username = var.BTP_BOT_USER
password = var.BTP_BOT_PASSWORD
}

module "kyma" {
source = "git::https://github.com/kyma-project/terraform-module.git?ref=v0.4.0"
BTP_KYMA_PLAN = var.BTP_KYMA_PLAN
BTP_NEW_SUBACCOUNT_NAME = var.BTP_NEW_SUBACCOUNT_NAME
BTP_KYMA_REGION = var.BTP_KYMA_REGION
BTP_NEW_SUBACCOUNT_REGION = var.BTP_NEW_SUBACCOUNT_REGION
BTP_KYMA_MODULES = jsondecode(var.BTP_KYMA_MODULES_STRINGIFIED)
BTP_KYMA_AUTOSCALER_MIN = var.BTP_KYMA_AUTOSCALER_MIN
}

output "subaccount_id" {
value = module.kyma.subaccount_id
}

output "domain" {
value = module.kyma.domain
}
54 changes: 54 additions & 0 deletions .github/actions/create-sap-btp-kyma/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
variable "BTP_GLOBAL_ACCOUNT" {
type = string
description = "Global account name"
}

variable "BTP_BOT_USER" {
type = string
description = "Bot account name"
}

variable "BTP_BOT_PASSWORD" {
type = string
description = "Bot account password"
}

variable "BTP_BACKEND_URL" {
type = string
description = "BTP backend URL"
}

variable "BTP_NEW_SUBACCOUNT_NAME" {
type = string
description = "Subaccount name"
}

variable "BTP_KYMA_PLAN" {
type = string
description = "Plan name"
}

variable "BTP_NEW_SUBACCOUNT_REGION" {
type = string
description = "Region name"
}

variable "BTP_CUSTOM_IAS_TENANT" {
type = string
description = "Custom IAS tenant"
}

variable "BTP_KYMA_REGION" {
type = string
description = "Kyma region"
}

variable "BTP_KYMA_MODULES_STRINGIFIED" {
type = string
description = "Kyma modules as stringified json"
}

variable "BTP_KYMA_AUTOSCALER_MIN" {
type = number
default = 3
}
36 changes: 36 additions & 0 deletions .github/actions/force-delete-sap-btp-subaccount/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'Force Delete SAP BTP Subaccount'
description: 'Action for force deleting SAP BTP subaccount'

inputs:
btp_subaccount_id:
description: 'btp subaccount id'
required: true
btp_backend_url:
description: 'btp backend url'
required: true
btp_user:
description: 'btp user'
required: true
btp_password:
description: 'btp password'
required: true
btp_global_account:
description: 'btp global account'
required: true
btp_idp_tenant:
description: 'btp idp tenant'
required: true

runs:
using: 'composite'
steps:
- uses: ./.github/actions/setup-btp

- name: Force delete btp resources
shell: bash
run: |
btp login --url "${{ inputs.btp_backend_url }}" --user "${{ inputs.btp_user }}" --password "${{ inputs.btp_password }}" --idp "${{ inputs.btp_idp_tenant }}" --subdomain "${{ inputs.btp_global_account }}"
echo "Deleting ${{ inputs.btp_global_account }}/${{ inputs.btp_subaccount_id }}".
btp delete accounts/subaccount "${{ inputs.btp_subaccount_id }}" --global-account "${{ inputs.btp_global_account }}" --force-delete true --confirm true
echo "Deletion request for subaccount ${{ inputs.btp_subaccount_id }} sent."

21 changes: 21 additions & 0 deletions .github/actions/setup-btp/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Setup BTP CLI'
description: 'Action for the BTP CLI setup'

inputs:
path:
description: 'path where BTP CLI should be installed'
required: false
default: "/usr/local/bin"

runs:
using: 'composite'
steps:
- name: Install BTP CLI
shell: bash
run: |
sudo ln -sf bash /bin/sh
mkdir -p ${{ inputs.path }}
curl -LJO https://tools.hana.ondemand.com/additional/btp-cli-linux-amd64-latest.tar.gz --cookie "eula_3_2_agreed=tools.hana.ondemand.com/developer-license-3_2.txt"
tar -zxf btp-cli-linux-amd64-latest.tar.gz --strip-components=1 -C ${{ inputs.path }}
rm -f btp-cli-linux-amd64-latest.tar.gz
echo "BTP CLI downloaded into ${{ inputs.path }}"
39 changes: 39 additions & 0 deletions .github/workflows/push-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: push-actions
on:
push:
branches: ["main", "release-*"]

jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/create-sap-btp-kyma
id: create-btp-resources
with:
btp_subaccount_name: terraform-module-actions-tst-${{ github.sha }}-${{ github.run_attempt }}
btp_backend_url: '${{ secrets.btp_api_url }}'
btp_user: '${{ secrets.username }}'
btp_password: '${{ secrets.password }}'
btp_global_account: '${{ secrets.global_account }}'
btp_idp_tenant: '${{ secrets.ias_tenant }}'
btp_subaccount_region: '${{ secrets.sa_region }}'
btp_kyma_region: '${{ secrets.kyma_region }}'
btp_kyma_plan: '${{ secrets.kyma_plan }}'
btp_kyma_modules: "[]"
btp_kyma_autoscaler_min: 3
- name: run tests
run: |
kubectl get nodes
- uses: ./.github/actions/force-delete-sap-btp-subaccount
if: always()
with:
btp_subaccount_id: ${{ steps.create-btp-resources.outputs.subaccount_id }}
btp_backend_url: ${{ secrets.btp_api_url}}
btp_user: ${{ secrets.username}}
btp_password: ${{ secrets.password}}
btp_global_account: ${{ secrets.global_account }}
btp_idp_tenant: ${{ secrets.ias_tenant }}

Loading