You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/sapbtp/subaccounts/buildingblock/import-resources-README.md
+73-8Lines changed: 73 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
-
# import-resources.sh - Dynamic SAP BTP Resource Importer
1
+
# Dynamic SAP BTP Resource Importer
2
2
3
3
## Overview
4
4
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).
6
8
7
9
## Features
8
10
@@ -14,10 +16,16 @@ Automatically imports existing SAP BTP resources into OpenTofu state by reading
14
16
15
17
## Usage
16
18
19
+
**Bash (Linux/macOS):**
17
20
```bash
18
21
./import-resources.sh
19
22
```
20
23
24
+
**PowerShell (Windows):**
25
+
```powershell
26
+
./import-resources.ps1
27
+
```
28
+
21
29
That's it! The script does everything automatically.
22
30
23
31
## What It Does
@@ -89,17 +97,25 @@ Next steps:
89
97
90
98
## Requirements
91
99
100
+
**Common (All Platforms):**
92
101
-`tofu` (OpenTofu) installed and configured
93
-
-`jq` for JSON parsing (version 1.6+)
94
102
- Valid BTP provider credentials (set via environment variables)
95
103
- Existing `terraform.tfvars` with configuration
96
104
- BTP CLI (`btp`) for manual ID lookup (if starting from empty state)
97
105
- Cloud Foundry CLI (`cf`) for service instance GUIDs (if importing CF services)
98
106
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
+
99
114
## Workflow
100
115
101
116
### Initial Import (No State)
102
117
118
+
**Bash:**
103
119
```bash
104
120
# 1. Ensure terraform.tfvars exists with correct configuration
105
121
cat terraform.tfvars
@@ -117,18 +133,43 @@ tofu plan
117
133
tofu apply
118
134
```
119
135
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
+
120
154
### Re-running (State Exists)
121
155
156
+
**Bash:**
122
157
```bash
123
-
# Safe to run - will skip already imported resources
124
158
./import-resources.sh
125
159
```
126
160
161
+
**PowerShell:**
162
+
```powershell
163
+
./import-resources.ps1
164
+
```
165
+
127
166
Output:
128
167
```
129
168
⊙ ALREADY IMPORTED (skipping)
130
169
```
131
170
171
+
Both scripts are idempotent and safe to run multiple times.
172
+
132
173
## Configuration Examples
133
174
134
175
### Minimal Configuration
@@ -201,6 +242,7 @@ tofu state list | grep <resource-name>
201
242
202
243
### Resource Discovery Logic
203
244
245
+
**Bash Script:**
204
246
1.**State (Primary)**
205
247
```bash
206
248
tofu show -json | jq -r '.values.root_module.resources[]...'
@@ -209,7 +251,18 @@ tofu state list | grep <resource-name>
0 commit comments