Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add http backend #193

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<https://www.terraform.io/docs/backends/types/http.html#configuration-variables>
<https://www.terraform.io/docs/backends/types/s3.html#configuration-variables>
<https://www.terraform.io/docs/backends/types/gcs.html#configuration-variables>

#### 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:
Expand Down
4 changes: 2 additions & 2 deletions requirements.pip
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 32 additions & 1 deletion terrawrap/models/wrapper_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions terrawrap/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
Expand Down