diff --git a/README.md b/README.md index e01fe9af..a578fba5 100644 --- a/README.md +++ b/README.md @@ -209,11 +209,46 @@ terraform init -reconfigure \ ``` Terrawrap configures the backend by looking for `.tf_wrapper` files in the directory structure. -Either `s3` or `gcs` are supported. See the relevant Terraform documentation for the options available +Either `http`, `s3` or `gcs` are supported. See the relevant Terraform documentation for the options available for each type of backend: + + +#### http Backend +```yml +backends: + http: + address: + lock_address: + lock_method: + unlock_address: + unlock_method: + username: + password: + skip_cert_verification: + retry_max: + retry_wait_min: + retry_wait_max: +``` + +| Option Name | Required | Purpose | +| -----------------------| -------- | -------------------------------------------------------------------------------- | +| address | Yes | Address of the REST endpoint | +| update_method | No | HTTP method to use when updating state. Defaults to POST | +| lock_address | No | Address of the lock REST endpoint. Defaults to disabled | +| lock_method | No | HTTP method to use when locking. Defaults to LOCK | +| unlock_address | No | Address of the unlock REST endpoint. Defaults to disabled | +| unlock_method | No | HTTP method to use when unlocking. Defaults to UNLOCK | +| username | No | Username for HTTP basic authentication | +| password | No | Password for HTTP basic authentication | +| skip_cert_verification | No | Whether to skip TLS verification. Defaults to false | +| retry_max | No | Number of HTTP request retires. Defaults to 2 | +| retry_wait_min | No | Minimum time in seconds to wait between HTTP request attempts. Defaults to 1 | +| retry_wait_max | No | Maximum time in seconds to wait between HTTP request attempts. Defaults to 30 | + + #### S3 Backend ```yml backends: diff --git a/requirements.pip b/requirements.pip index 1a656031..c47c8fcb 100644 --- a/requirements.pip +++ b/requirements.pip @@ -4,11 +4,11 @@ amplify-aws-utils>=0.1.2 docopt==0.6.2 filelock>=3.0.12,<4 gitpython>=2.1.10 -PyYAML>=5.3.1,<6 +PyYAML>=6.0.1,<7 ssm-cache>=2.7,<3 jsons>=1.0.0,<2.0.0 python-hcl2>=3,<4 # Packaging does not obey semver -packaging==19.1 +packaging diskcache>=5.0.0,<6 networkx>=2.4 diff --git a/terrawrap/models/wrapper_config.py b/terrawrap/models/wrapper_config.py index 8a7f746c..f290caca 100644 --- a/terrawrap/models/wrapper_config.py +++ b/terrawrap/models/wrapper_config.py @@ -36,6 +36,36 @@ def __init__(self): super().__init__(EnvVarSource.UNSET) +class HTTPBackendConfig: + def __init( + self, + address: str = None, + update_method: str = None, + lock_address: str = None, + lock_method: str = None, + unlock_address: str = None, + unlock_method: str = None, + username: str = None, + password: str = None, + skip_cert_verification: str = None, + retry_max: str = None, + retry_wait_min: str = None, + retry_wait_max: str = None, + ): + self.address = address + self.update_method = update_method + self.lock_address = lock_address + self.lock_method = lock_method + self.unlock_address = unlock_address + self.unlock_method = unlock_method + self.username = username + self.password = password + self.skip_cert_verifications = skip_cert_verification + self.retry_max = retry_max + self.retry_wait_min = retry_wait_min + self.retry_wait_max = retry_wait_max + + class S3BackendConfig: def __init__( self, @@ -57,7 +87,8 @@ def __init__(self, bucket: str = None): class BackendsConfig: # pylint: disable=invalid-name - def __init__(self, s3: Optional[S3BackendConfig] = None, gcs: Optional[GCSBackendConfig] = None): + def __init__(self, s3: Optional[S3BackendConfig] = None, gcs: Optional[GCSBackendConfig] = None, http: Optional[HTTPBackendConfig] = None): + self.http = http self.s3 = s3 self.gcs = gcs diff --git a/terrawrap/utils/config.py b/terrawrap/utils/config.py index 2715dc3c..b79862a4 100644 --- a/terrawrap/utils/config.py +++ b/terrawrap/utils/config.py @@ -325,6 +325,8 @@ def calc_backend_config( wrapper_options['prefix'] = repo_path if existing_backend_config.s3 is not None and wrapper_config.backends.s3 is not None: wrapper_options = vars(wrapper_config.backends.s3) + if existing_backend_config.http is None and wrapper_config.backends.http is not None: + wrapper_options = vars(wrapper_config.backends.http) options.update({key: value for key, value in wrapper_options.items() if value is not None}) backend_config.extend([f'-backend-config={key}={value}' for key, value in options.items()])