majuna/app/terraform/bridge/gandi.py

84 lines
2.7 KiB
Python
Raw Normal View History

2023-02-26 12:52:08 +00:00
from app.models.cloud import CloudProvider
2022-03-10 14:26:22 +00:00
from app.terraform.bridge import BridgeAutomation
class BridgeGandiAutomation(BridgeAutomation):
short_name = "bridge_gandi"
description = "Deploy Tor bridges on GandiCloud VPS"
2023-02-26 12:52:08 +00:00
provider = CloudProvider.GANDI
2022-03-10 14:26:22 +00:00
2024-12-06 18:15:47 +00:00
template_parameters = ["ssh_public_key_path", "ssh_private_key_path"]
2022-03-10 14:26:22 +00:00
template = """
terraform {
{{ backend_config }}
2022-03-10 14:26:22 +00:00
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.42.0"
}
}
}
2023-02-26 12:52:08 +00:00
locals {
public_ssh_key = "{{ ssh_public_key_path }}"
private_ssh_key = "{{ ssh_private_key_path }}"
}
{% for resource in destroyed_resources %}
{% set bridge, bridgeconf, account = resource %}
2022-03-10 14:26:22 +00:00
provider "openstack" {
auth_url = "https://keystone.sd6.api.gandi.net:5000/v3"
user_domain_name = "public"
project_domain_name = "public"
2023-02-26 12:52:08 +00:00
user_name = "{{ account.credentials["gandi_openstack_user"] }}"
password = "{{ account.credentials["gandi_openstack_password"] }}"
tenant_name = "{{ account.credentials["gandi_openstack_tenant_id"] }}"
2022-03-10 14:26:22 +00:00
region = "FR-SD6"
2023-02-26 12:52:08 +00:00
alias = "account_{{ bridge.id }}"
2022-03-10 14:26:22 +00:00
}
2023-02-26 12:52:08 +00:00
{% endfor %}
2022-03-10 14:26:22 +00:00
2023-02-26 12:52:08 +00:00
{% for resource in active_resources %}
{% set bridge, bridgeconf, account = resource %}
provider "openstack" {
auth_url = "https://keystone.sd6.api.gandi.net:5000/v3"
user_domain_name = "public"
project_domain_name = "public"
user_name = "{{ account.credentials["gandi_openstack_user"] }}"
password = "{{ account.credentials["gandi_openstack_password"] }}"
tenant_name = "{{ account.credentials["gandi_openstack_tenant_id"] }}"
region = "FR-SD6"
alias = "account_{{ bridge.id }}"
2022-03-10 14:26:22 +00:00
}
module "bridge_{{ bridge.id }}" {
2023-02-26 12:52:08 +00:00
providers = {
openstack = openstack.account_{{ bridge.id }}
}
2022-08-30 10:24:58 +01:00
source = "{{ terraform_modules_path }}/terraform-openstack-tor-bridge"
2023-02-26 12:52:08 +00:00
namespace = "{{ global_namespace }}"
name = "bridge"
2022-03-10 14:26:22 +00:00
attributes = ["{{ bridge.id }}"]
2023-02-26 14:07:23 +00:00
ssh_public_key = local.public_ssh_key
ssh_private_key = local.private_ssh_key
2023-02-26 12:52:08 +00:00
contact_info = "did not write the code to populate yet"
distribution_method = "{{ bridgeconf.method }}"
2022-03-10 14:26:22 +00:00
image_name = "Debian 11 Bullseye"
flavor_name = "V-R1"
external_network_name = "public"
require_block_device_creation = true
}
output "bridge_hashed_fingerprint_{{ bridge.id }}" {
value = module.bridge_{{ bridge.id }}.hashed_fingerprint
}
output "bridge_bridgeline_{{ bridge.id }}" {
value = module.bridge_{{ bridge.id }}.bridgeline
sensitive = true
}
{% endfor %}
"""