Skip to content

Commit cb88147

Browse files
committed
feat: update readme import script
1 parent 3460972 commit cb88147

File tree

1 file changed

+73
-8
lines changed

1 file changed

+73
-8
lines changed

modules/sapbtp/subaccounts/buildingblock/import-resources-README.md

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# import-resources.sh - Dynamic SAP BTP Resource Importer
1+
# Dynamic SAP BTP Resource Importer
22

33
## Overview
44

5-
Automatically imports existing SAP BTP resources into OpenTofu state by reading configuration from `terraform.tfvars` and discovering resource IDs from outputs.
5+
Automatically imports existing SAP BTP resources into OpenTofu state by reading configuration from `terraform.tfvars` and discovering resource IDs from state.
6+
7+
Available for both **Bash** (Linux/macOS) and **PowerShell** (Windows).
68

79
## Features
810

@@ -14,10 +16,16 @@ Automatically imports existing SAP BTP resources into OpenTofu state by reading
1416

1517
## Usage
1618

19+
**Bash (Linux/macOS):**
1720
```bash
1821
./import-resources.sh
1922
```
2023

24+
**PowerShell (Windows):**
25+
```powershell
26+
./import-resources.ps1
27+
```
28+
2129
That's it! The script does everything automatically.
2230

2331
## What It Does
@@ -89,17 +97,25 @@ Next steps:
8997

9098
## Requirements
9199

100+
**Common (All Platforms):**
92101
- `tofu` (OpenTofu) installed and configured
93-
- `jq` for JSON parsing (version 1.6+)
94102
- Valid BTP provider credentials (set via environment variables)
95103
- Existing `terraform.tfvars` with configuration
96104
- BTP CLI (`btp`) for manual ID lookup (if starting from empty state)
97105
- Cloud Foundry CLI (`cf`) for service instance GUIDs (if importing CF services)
98106

107+
**Bash Script (Linux/macOS):**
108+
- Bash 3.2+ (macOS default) or higher
109+
- `jq` for JSON parsing (version 1.6+)
110+
111+
**PowerShell Script (Windows):**
112+
- PowerShell 5.1+ or PowerShell Core 7+
113+
99114
## Workflow
100115

101116
### Initial Import (No State)
102117

118+
**Bash:**
103119
```bash
104120
# 1. Ensure terraform.tfvars exists with correct configuration
105121
cat terraform.tfvars
@@ -117,18 +133,43 @@ tofu plan
117133
tofu apply
118134
```
119135

136+
**PowerShell:**
137+
```powershell
138+
# 1. Ensure terraform.tfvars exists with correct configuration
139+
Get-Content terraform.tfvars
140+
141+
# 2. Run the import script
142+
./import-resources.ps1
143+
144+
# 3. Verify the imported resources
145+
tofu state list
146+
147+
# 4. Check what still needs to be created
148+
tofu plan
149+
150+
# 5. Apply remaining resources (entitlements, role assignments)
151+
tofu apply
152+
```
153+
120154
### Re-running (State Exists)
121155

156+
**Bash:**
122157
```bash
123-
# Safe to run - will skip already imported resources
124158
./import-resources.sh
125159
```
126160

161+
**PowerShell:**
162+
```powershell
163+
./import-resources.ps1
164+
```
165+
127166
Output:
128167
```
129168
⊙ ALREADY IMPORTED (skipping)
130169
```
131170

171+
Both scripts are idempotent and safe to run multiple times.
172+
132173
## Configuration Examples
133174

134175
### Minimal Configuration
@@ -201,6 +242,7 @@ tofu state list | grep <resource-name>
201242

202243
### Resource Discovery Logic
203244

245+
**Bash Script:**
204246
1. **State (Primary)**
205247
```bash
206248
tofu show -json | jq -r '.values.root_module.resources[]...'
@@ -209,7 +251,18 @@ tofu state list | grep <resource-name>
209251
2. **Manual Input (If State Empty)**
210252
```bash
211253
read -p "Enter Subaccount ID: "
212-
# Provides CLI commands to find IDs
254+
```
255+
256+
**PowerShell Script:**
257+
1. **State (Primary)**
258+
```powershell
259+
tofu show -json | ConvertFrom-Json
260+
$stateJson.values.root_module.resources | Where-Object {...}
261+
```
262+
263+
2. **Manual Input (If State Empty)**
264+
```powershell
265+
Read-Host "Enter Subaccount ID"
213266
```
214267

215268
### Resource Naming Pattern
@@ -226,16 +279,28 @@ Instance name: "destination-lite"
226279

227280
- **Role assignments** cannot be imported (SAP BTP provider limitation)
228281
- **Entitlements** don't need import (managed declaratively)
229-
- Requires **jq** for JSON parsing
230-
- Needs **existing outputs** or state to discover IDs
282+
- Bash script requires **jq** for JSON parsing
283+
- PowerShell script requires **PowerShell 5.1+**
231284

232285
## Exit Codes
233286

234287
- `0` - All imports successful
235288
- `1` - One or more imports failed
236289

290+
## Platform Notes
291+
292+
### macOS/Linux
293+
- Uses bash 3.2+ compatible syntax (macOS default shell)
294+
- Requires `jq` for JSON parsing: `brew install jq`
295+
296+
### Windows
297+
- PowerShell 5.1+ included by default in Windows 10+
298+
- PowerShell Core 7+ recommended for cross-platform consistency
299+
- Native JSON parsing with `ConvertFrom-Json`
300+
237301
## See Also
238302

239-
- [IMPORT_SUCCESS.md](./IMPORT_SUCCESS.md) - Detailed import report
303+
- [import-resources.sh](./import-resources.sh) - Bash script for Linux/macOS
304+
- [import-resources.ps1](./import-resources.ps1) - PowerShell script for Windows
240305
- [terraform.tfvars](./terraform.tfvars) - Configuration file
241306
- [main.tf](./main.tf) - Resource definitions

0 commit comments

Comments
 (0)