Save the current configuration to the terraform.tfvars config file.
(self)
| 282 | self.encrypted_carbon_black_api_token = self.encrypted_carbon_black_api_token |
| 283 | |
| 284 | def save(self) -> None: |
| 285 | """Save the current configuration to the terraform.tfvars config file.""" |
| 286 | # In order to preserve comments, we overwrite each individual variable instead of re-writing |
| 287 | # the entire configuration file. |
| 288 | with open(CONFIG_FILE) as config_file: |
| 289 | raw_config = config_file.read() |
| 290 | |
| 291 | for variable_name, value in self._config.items(): |
| 292 | if isinstance(value, str): |
| 293 | formatted_value = '"{}"'.format(value) |
| 294 | elif isinstance(value, bool): |
| 295 | formatted_value = str(value).lower() |
| 296 | else: |
| 297 | formatted_value = value |
| 298 | |
| 299 | raw_config = re.sub( |
| 300 | r'{}\s*=\s*\S+'.format(variable_name), |
| 301 | '{} = {}'.format(variable_name, formatted_value), |
| 302 | raw_config |
| 303 | ) |
| 304 | |
| 305 | with open(CONFIG_FILE, 'w') as config_file: |
| 306 | config_file.write(raw_config) |
no outgoing calls