Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICG - Infrastucture as Code Generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PIACERE
public
The Platform
ICG - Infrastucture as Code Generator
Commits
eb47bf76
Commit
eb47bf76
authored
2 years ago
by
debora.benedetto@hpe.com
Browse files
Options
Downloads
Patches
Plain Diff
added vms output terraform file template and generation
parent
19097d75
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
plugin/TerraformPlugin.py
+29
-9
29 additions, 9 deletions
plugin/TerraformPlugin.py
template-location.properties
+1
-0
1 addition, 0 deletions
template-location.properties
templates/terraform/open_stack/virtual_machine_out.tpl
+11
-0
11 additions, 0 deletions
templates/terraform/open_stack/virtual_machine_out.tpl
with
41 additions
and
9 deletions
plugin/TerraformPlugin.py
+
29
−
9
View file @
eb47bf76
...
...
@@ -6,19 +6,34 @@ def create_files(parameters, output_path):
language
=
"
terraform
"
provider
=
parameters
[
"
provider
"
]
resources
=
parameters
.
keys
()
terraform_file
=
create_init_file
(
language
,
provider
)
terraform_main_file
=
create_init_file
(
language
,
provider
)
terraform_out_file
=
""
for
resource_name
in
resources
:
logging
.
info
(
"
Creating template for resource
'
%s
'"
,
resource_name
)
template_path
=
TemplateUtils
.
find_template_path
(
language
,
provider
,
resource_name
)
if
template_path
:
logging
.
info
(
"
Creating output and main terraform template for resource
'
%s
'"
,
resource_name
)
template_for_main_path
=
TemplateUtils
.
find_template_path
(
language
,
provider
,
resource_name
)
template_for_output_path
=
TemplateUtils
.
find_template_path
(
language
,
provider
,
get_resource_out_path
(
resource_name
))
if
template_for_main_path
:
for
resource_params
in
parameters
[
resource_name
]:
template
=
TemplateUtils
.
read_template
(
template_path
)
template
=
TemplateUtils
.
read_template
(
template_
for_main_
path
)
# resource = parameters[resource_name]
template_filled
=
TemplateUtils
.
edit_template
(
template
,
resource_params
)
terraform_file
=
terraform_file
+
template_filled
+
"
\n
"
output_file_path
=
output_path
+
"
/main.tf
"
TemplateUtils
.
write_template
(
terraform_file
,
output_file_path
)
logging
.
info
(
"
File available at: {}
"
.
format
(
output_path
))
terraform_main_file
=
terraform_main_file
+
template_filled
+
"
\n
"
if
template_for_output_path
:
for
resource_params
in
parameters
[
resource_name
]:
template_out
=
TemplateUtils
.
read_template
(
template_for_output_path
)
# resource = parameters[resource_name]
template_out_filled
=
TemplateUtils
.
edit_template
(
template_out
,
resource_params
)
terraform_out_file
=
terraform_out_file
+
template_out_filled
+
"
\n
"
main_file_stored_path
=
output_path
+
"
/main.tf
"
TemplateUtils
.
write_template
(
terraform_main_file
,
main_file_stored_path
)
output_file_stored_path
=
output_path
+
"
/output.tf
"
TemplateUtils
.
write_template
(
terraform_out_file
,
output_file_stored_path
)
logging
.
info
(
"
Terraform main file available at: {}
"
.
format
(
main_file_stored_path
))
logging
.
info
(
f
"
Terraform output file available at
{
output_file_stored_path
}
"
)
def
create_init_file
(
language
,
provider
):
...
...
@@ -26,3 +41,8 @@ def create_init_file(language, provider):
template_path
=
TemplateUtils
.
find_template_path
(
language
,
provider
,
"
init
"
)
template
=
TemplateUtils
.
read_template
(
template_path
)
return
template
.
render
()
+
"
\n
"
## TODO spostare i template di out in una cartella?? es. cartella vms&vms_out? altrimenti come prendo nome di out?
## non è nel doml
def
get_resource_out_path
(
resource_name
):
return
resource_name
+
"
_out
"
This diff is collapsed.
Click to expand it.
template-location.properties
+
1
−
0
View file @
eb47bf76
[terraform.openstack]
init
=
templates/terraform/open_stack/init.tpl
vms
=
templates/terraform/open_stack/virtual_machine.tpl
vms_out
=
templates/terraform/open_stack/virtual_machine_out.tpl
networks
=
templates/terraform/open_stack/network.tpl
computingGroup
=
templates/terraform/open_stack/port_rule.tpl
...
...
This diff is collapsed.
Click to expand it.
templates/terraform/open_stack/virtual_machine_out.tpl
0 → 100644
+
11
−
0
View file @
eb47bf76
output "instance_server_public_key_{{ vm_key_name }}" {
value = openstack_compute_keypair_v2.{{ vm_key_name }}.public_key
}
output "instance_server_private_key_{{ vm_key_name }}" {
value = openstack_compute_keypair_v2.{{ vm_key_name }}.private_key
}
output "instance_ip" {
value = openstack_compute_floatingip_associate_v2.{{ infra_element_name ~ "_floating_ip_association" }}.floating_ip
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment