Cloud and Container Basics
An environment was created by applying, with a declarative IaC (Infrastructure as Code) tool, a file that defines a network and two virtual machines. Immediately afterwards, the same file is applied again without any changes. Which of the following is what happens?
- AThere is no difference between the definition and the actual state, so nothing is changed
- BAnother identical set is created, giving four virtual machines
- CBecause the environment already exists, the second apply stops with an error
Show answer and explanation
Answer: A. There is no difference between the definition and the actual state, so nothing is changed
With declarative IaC, the code describes the desired configuration rather than the steps, and the tool compares it with the actual state and creates, changes or deletes only what differs. Applying the same definition any number of times therefore gives the same result (idempotence), and the second apply changes nothing. If someone changes a setting by hand and the actual state drifts from the definition (configuration drift), the next apply brings it back to the defined state. Managing the definitions in Git also allows history checks and reviews in the same way as for programs.
- A. Correct. Only the differences are changed, so applying the same definition any number of times leads to the same state.
- B. This could happen if a script describing the creation steps were run twice. A declarative tool does not recreate what already exists.
- C. A declarative tool compares existing resources with the definition and does nothing if there is no difference.