@@ -277,29 +277,8 @@ def main():
277277 print (f" - { filename } ({ size } bytes)" )
278278
279279 try :
280- # Create tar.gz archive manually since go-slug isn't available
281- print ("Creating tar.gz archive manually..." )
282-
283- import tarfile
284-
285- # Create tar.gz archive in memory
286- archive_buffer = io .BytesIO ()
287- with tarfile .open (fileobj = archive_buffer , mode = "w:gz" ) as tar :
288- # Add all files from the temp directory
289- for filename in files :
290- filepath = os .path .join (temp_dir , filename )
291- tar .add (filepath , arcname = filename )
292-
293- archive_buffer .seek (0 )
294- archive_bytes = archive_buffer .getvalue ()
295- print (f"Created archive: { len (archive_bytes )} bytes" )
296-
297- # Use the SDK's upload_tar_gzip method instead of direct HTTP calls
298- print ("Uploading archive using SDK method..." )
299- archive_buffer .seek (0 ) # Reset buffer position
300- client .configuration_versions .upload_tar_gzip (
301- new_cv .upload_url , archive_buffer
302- )
280+ print ("Uploading Terraform configuration..." )
281+ client .configuration_versions .upload (new_cv .upload_url , temp_dir )
303282 print ("Terraform configuration uploaded successfully!" )
304283
305284 # Wait and check status
@@ -408,8 +387,6 @@ def main():
408387 # =====================================================
409388 # TEST 4: UPLOAD CONFIGURATION VERSION
410389 # =====================================================
411- # Test 4: Upload function (requires go-slug)
412- # =====================================================
413390 print ("\n 4. Testing upload() function:" )
414391 try :
415392 # Create a fresh configuration version specifically for upload testing
@@ -441,33 +418,19 @@ def main():
441418 print (f"\n Uploading configuration to CV: { fresh_cv .id } " )
442419 print (f"Upload URL: { upload_url [:60 ]} ..." )
443420
444- try :
445- client .configuration_versions .upload (upload_url , temp_dir )
446- print ("Configuration uploaded successfully!" )
447-
448- # Check status after upload
449- print ("\n Checking status after upload:" )
450- time .sleep (3 ) # Give TFE time to process
451- updated_cv = client .configuration_versions .read (fresh_cv .id )
452- print (f"Status after upload: { updated_cv .status } " )
421+ client .configuration_versions .upload (upload_url , temp_dir )
422+ print ("Configuration uploaded successfully!" )
453423
454- if updated_cv .status .value != "pending" :
455- print ("Status changed (upload processed)" )
456- else :
457- print ("Status still pending (may need more time)" )
424+ # Check status after upload
425+ print ("\n Checking status after upload:" )
426+ time .sleep (3 ) # Give TFE time to process
427+ updated_cv = client .configuration_versions .read (fresh_cv .id )
428+ print (f"Status after upload: { updated_cv .status } " )
458429
459- except ImportError as e :
460- if "go-slug" in str (e ):
461- print ("go-slug package not available" )
462- print ("Install with: pip install go-slug" )
463- print (
464- "Upload function exists but requires go-slug for packaging"
465- )
466- print (
467- "Function correctly raises ImportError when go-slug unavailable"
468- )
469- else :
470- raise
430+ if updated_cv .status .value != "pending" :
431+ print ("Status changed (upload processed)" )
432+ else :
433+ print ("Status still pending (may need more time)" )
471434
472435 except Exception as e :
473436 print (f"Error: { e } " )
@@ -868,7 +831,7 @@ def main():
868831 "TEST 2: create() - Create new configuration versions with different options"
869832 )
870833 print ("TEST 3: read() - Read configuration version details and validate fields" )
871- print ("TEST 4: upload() - Upload Terraform configurations (requires go-slug )" )
834+ print ("TEST 4: upload() - Upload Terraform configurations (stdlib tarfile )" )
872835 print ("TEST 5: download() - Download configuration version archives" )
873836 print ("TEST 6: archive() - Archive configuration versions" )
874837 print ("TEST 7: read_with_options() - Read with include options" )
0 commit comments