Skip to content
Closed
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
1 change: 1 addition & 0 deletions changelog/63636.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Explicit "priv" attribute in terraform state is now correctly used instead of overriden with default / fallback values.
4 changes: 3 additions & 1 deletion salt/roster/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def _add_ssh_key(ret):
"""
Setups the salt-ssh minion to be accessed with salt-ssh default key
"""
priv = None
priv = ret.get("priv", None)
if priv and os.path.isfile(priv):
return # Use roster_entry explicitly defined "priv"
if __opts__.get("ssh_use_home_key") and os.path.isfile(
os.path.expanduser("~/.ssh/id_rsa")
):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FAKE-SSH-KEY
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": 4,
"terraform_version": "1.2.3",
"serial": 1,
"lineage": "86545604-7463-4aa5-e9e8-a2a221de98d2",
"outputs": {},
"resources": [
{
"mode": "managed",
"name": "example",
"type": "salt_host",
"provider": "provider.libvrt",
"instances": [
{
"schema_version": 1,
"attributes": {
"host": "192.168.122.106",
"id": "web0",
"passwd": "linux",
"salt_id": "web0",
"timeout": "22",
"user": "root"
}
},
{
"schema_version": 1,
"attributes": {
"host": "192.168.122.107",
"id": "web1",
"passwd": "linux",
"salt_id": "web1",
"timeout": "22",
"user": "root",
"priv": "tests/pytests/unit/roster/terraform.data/ssh/salt-ssh-custom.rsa"
}
}
]
},
{
"mode": "managed",
"name": "example",
"type": "non_salt_host",
"provider": "provider.libvrt",
"instances": [
{
"schema_version": 1,
"attributes": {
"host": "192.168.122.106",
"id": "web0",
"passwd": "linux",
"salt_id": "web0",
"timeout": "22",
"user": "root"
}
}
]
}
]
}
33 changes: 33 additions & 0 deletions tests/pytests/unit/roster/test_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def roster_file_new():
return pathlib.Path(__file__).parent / "terraform.data" / "terraform-new.tfstate"


@pytest.fixture
def roster_file_priv():
""" Fixture containing a specified "priv" argument. """
return pathlib.Path(__file__).parent / "terraform.data" / "terraform-new-specific-priv.tfstate"


@pytest.fixture
def pki_dir():
return pathlib.Path(__file__).parent / "terraform.data"
Expand Down Expand Up @@ -154,6 +160,33 @@ def test_defaults_new_matching(pki_dir, roster_file_new):
assert expected_result == ret


def test_specified_priv(pki_dir, roster_file_priv):
"""
Test the output of a fixture tfstate file which contains libvirt
resources using matching
"""
expected_result = {
"web0": {
"host": "192.168.122.106",
"user": "root",
"passwd": "linux",
"timeout": 22,
"priv": str(pki_dir / "ssh" / "salt-ssh.rsa"),
},
"web1": {
"host": "192.168.122.107",
"user": "root",
"passwd": "linux",
"timeout": 22,
"priv": "tests/pytests/unit/roster/terraform.data/ssh/salt-ssh-custom.rsa",
},
}

with patch.dict(terraform.__opts__, {"roster_file": str(roster_file_priv)}):
ret = terraform.targets("*")
assert expected_result == ret


def test_correct_handler_called_old():
old_mock = patch.object(terraform, "_do__parse_old_state_file")
new_mock = patch.object(terraform, "_do_parse_new_state_file")
Expand Down