APURV
  • Home
  • Journey
  • Projects
  • Blogs
  • Interview
  • Exams
Resume
APURV

Building scalable, secure, and production-ready cloud infrastructure. Automation first.

NAVIGATION

HomeExperienceProjectsCertificationsSkills

TECH STACK

AWSGCPK8sCI/CDLinuxDocker

CONNECT

LinkedInGitHubEmailResume

© 2026 Apurv Gujjar. All rights reserved.
Apurv Gujjar
Apurv GujjarDevOps & Cloud Engineer
|Interview Documentation
Portfolio
Handbooks
🎯Linux🐙Git & GitHub🤖GitHub Actions🌐Networking☁AWS🛠Terraform🐳Docker☸Kubernetes📊Monitoring🛡DevSecOps💰Cost Optimization🚨Incident Scenarios👤HR & Behavioral☁GCP🐍Python
Interview DocumentationPythonScenario 5: Write a script that takes the target environment as an input argument (`sys.argv`) and runs environment-specific deployment commands.
Back to all Python questions
Q5

Scenario 5: Write a script that takes the target environment as an input argument (`sys.argv`) and runs environment-specific deployment commands.

💬Answer
import sys

def deploy(environment):
    print(f"Initializing deployment configuration for: {environment.upper()}")
    
    if environment == "dev":
        print("Running: terraform apply -var-file=dev.tfvars")
    elif environment == "stage":
        print("Running: terraform apply -var-file=stage.tfvars")
    elif environment == "prod":
        print("CRITICAL: Executing Production deployment pipeline...")
        print("Running: terraform apply -var-file=prod.tfvars")
    else:
        print(f"Error: Unknown environment '{environment}'!")
        sys.exit(1)

if __name__ == "__main__":
    # Ensure environment argument is provided
    if len(sys.argv) < 2:
        print("Usage: python deploy.py <dev|stage|prod>")
        sys.exit(1)
        
    target_env = sys.argv[1].lower()
    deploy(target_env)

Related Python Questions

View All PythonQuestions →
Q1

What is the difference between a List and a Tuple?

Q2

What is the difference between the `==` and `is` operators?

Q3

What are the primary Python data types?

Q4

What is a dictionary and why is it heavily used in DevOps?

Apurv Gujjar - DevOps & Cloud Engineer
Created by

Apurv Gujjar

DevOps & Cloud Engineer

Specialized in:DevOpsAWSGCPKubernetesTerraformDocker
View Portfolio