Version Control with Git in Infrastructure as Code Quiz

Explore essential concepts of using Git for version control in Infrastructure as Code workflows. This quiz covers basic commands, collaboration patterns, and best practices for managing infrastructure configurations with Git, helping you ensure reliability and traceability in code-driven environments.

  1. Understanding Git's Purpose in Infrastructure as Code

    What is the primary benefit of using Git as a version control system for Infrastructure as Code (IaC) projects?

    1. It eliminates the need for configuration files in infrastructure management.
    2. It automatically generates cloud resources without templates.
    3. It allows you to track changes and roll back to previous infrastructure configurations.
    4. It increases the speed of deploying resources by itself.

    Explanation: Git enables you to keep a detailed record of changes made to your infrastructure code and revert back to earlier states when needed, which is essential for reliability. Git by itself doesn't increase deployment speed, as deployments depend on tools and scripts. It does not automatically create resources without proper configuration files. Git also doesn't remove the need for configuration files; rather, it manages their versions.

  2. Basic Commit Operation

    In Git, which command is used to save your staged changes to the repository with a descriptive message in the context of an IaC project?

    1. git record -m 'message'
    2. git update -m 'message'
    3. git commit -m 'message'
    4. git save -m 'message'

    Explanation: The correct command 'git commit -m' is used to store staged changes along with a commit message. 'git save', 'git record', and 'git update' are not valid commands in Git for committing. These distractors may seem similar but do not perform the intended Git commit operation.

  3. Collaboration on Infrastructure Projects

    Which Git feature enables multiple engineers to work independently on separate versions of Infrastructure as Code files simultaneously?

    1. Forking
    2. Branching
    3. Cloning
    4. Tagging

    Explanation: Branching in Git allows users to create independent versions of the codebase, making parallel work on infrastructure changes possible. Forking creates a separate copy of the entire repository, which is more typical for open collaboration. Cloning downloads the repository but doesn't enable parallel development by itself. Tagging is used for marking specific points in history, not for developing separate features.

  4. Changing a Tracked IaC File

    After modifying an Infrastructure as Code file, which sequence correctly prepares and records the change in Git?

    1. git tag, git status
    2. git add, git commit
    3. git remove, git log
    4. git fork, git push

    Explanation: 'git add' stages the file, and 'git commit' records the change, which is the necessary process in Git. 'git tag' and 'git status' either label commits or show status but do not record changes. 'git fork' and 'git push' copy or upload repositories, not changes. 'git remove' deletes tracking and 'git log' is for viewing history, not committing.

  5. Undoing Changes in Infrastructure Code

    Which Git command can you use to revert an Infrastructure as Code file to its last committed state if you made an unwanted local edit?

    1. git delete filename
    2. git checkout -- filename
    3. git forward filename
    4. git revertall filename

    Explanation: The 'git checkout -- filename' command restores the file from the last commit, effectively discarding local changes. 'git delete' simply deletes files and is not a Git command. 'git forward' and 'git revertall' are not valid Git commands for undoing local modifications.

  6. Tracking Changes Over Time

    How does using Git enhance the auditability of changes in Infrastructure as Code repositories?

    1. It speeds up code execution during deployments.
    2. It encrypts all code files automatically.
    3. It removes unused code without notice.
    4. It keeps a log of who made each change and when.

    Explanation: Git maintains a complete history of all changes including the author and timestamp, which aids audits. It does not speed up code during deployments, nor does it encrypt files by itself. Automatic code removal without transparency is not a function of Git.

  7. Resolving Conflicts in Collaborative Work

    When two team members modify the same Infrastructure as Code file differently and try to merge their changes, what situation does Git report?

    1. A fork error
    2. A merge conflict
    3. A code freeze
    4. A repository lock

    Explanation: Git shows a merge conflict when the same file is changed in incompatible ways, prompting the user to resolve differences. A code freeze is a project management term, not a Git status. A repository lock refers to access control, not file merging. A fork error does not describe this issue.

  8. Best Practices for Infrastructure Code Commits

    Which practice is recommended when committing Infrastructure as Code changes with Git?

    1. Use random code snippets in commit messages.
    2. Commit unrelated changes together for speed.
    3. Write clear and descriptive commit messages.
    4. Avoid using commit messages for minor changes.

    Explanation: Descriptive messages explain what the change involves, aiding collaboration and troubleshooting. Random snippets are unhelpful, unrelated changes should be separate for clarity, and all commits should be accompanied by helpful messages regardless of size.

  9. Identifying Infrastructure Code History

    If you need to review all changes made to the infrastructure code repository, which Git command do you use?

    1. git log
    2. git branch
    3. git init
    4. git fetch

    Explanation: 'git log' displays a list of all previous commits and their details. 'git branch' shows branch names, 'git fetch' downloads changes from a remote without showing logs, and 'git init' initializes a new repository, none of which display commit history.

  10. Restoring a Deleted Configuration

    Suppose you accidentally deleted a key configuration file from your Infrastructure as Code repository and have not yet committed. Which Git command can you use to recover it?

    1. git erase filename
    2. git checkout -- filename
    3. git fix filename
    4. git create filename

    Explanation: 'git checkout -- filename' brings back a deleted, uncommitted file from the last version in Git. The command 'git erase filename' does not exist in Git. 'git create filename' and 'git fix filename' are also invalid and will not restore the file.