Skip to content

Instantly share code, notes, and snippets.

@yunarta
Last active March 12, 2024 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunarta/0ce4cd8ab1dd1adb2cd1c7db5f9b551e to your computer and use it in GitHub Desktop.
Save yunarta/0ce4cd8ab1dd1adb2cd1c7db5f9b551e to your computer and use it in GitHub Desktop.
python code for using nexus as terraform state backend
def handle_state(method, path, body):
session = requests.sessions.Session()
session.auth = ('jenkins', 'jenkins')
if method == 'GET':
response = session.get(url=f"http://nxrm.funf/repository/storage-terraform-states{path}")
if response.status_code == 404:
return {
'statusCode': 200,
'body': {
'version': 1
}
}
else:
return {
'statusCode': 200,
'body': response.json()
}
elif method == 'POST':
content_buffer = io.BytesIO()
content_buffer.write(body)
content_buffer.seek(0)
response = session.put(url=f"http://nxrm.funf/repository/storage-terraform-states{path}", data=content_buffer)
print(response.status_code, file=stderr)
print(response.text, file=stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment