Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Krish Moodbidri
Terraform Openstack
Commits
265d0488
Commit
265d0488
authored
Jul 11, 2019
by
Mitchell Moore
Committed by
Ryan Randles Jones
Jul 11, 2019
Browse files
Feat ood instantiate
parent
46693062
Changes
3
Hide whitespace changes
Inline
Side-by-side
main.tf
View file @
265d0488
...
...
@@ -48,7 +48,11 @@ resource "openstack_networking_subnet_v2" "internal_subnet" {
# defines where floating ip will come from using variable from vars.tf
resource
"openstack_networking_floatingip_v2"
"ip_pool"
{
resource
"openstack_networking_floatingip_v2"
"ohpc_ip"
{
pool
=
"
${
var
.
public-network-name
}
"
}
resource
"openstack_networking_floatingip_v2"
"ood_ip"
{
pool
=
"
${
var
.
public-network-name
}
"
}
...
...
@@ -72,12 +76,12 @@ depends_on = ["openstack_networking_subnet_v2.external_subnet"]
# associates floating ip with the OHPC instance and run the ansible playbook
resource
"openstack_compute_floatingip_associate_v2"
"ohpc"
{
floating_ip
=
"
${
openstack_networking_floatingip_v2
.
ip_pool
.
address
}
"
floating_ip
=
"
${
openstack_networking_floatingip_v2
.
ohpc_ip
.
address
}
"
instance_id
=
"
${
openstack_compute_instance_v2
.
ohpc
.
id
}
"
# defines ssh connection
connection
{
host
=
"
${
format
(
"
${
var
.
host-prefix
}
"
,
element
(
split
(
"."
,
openstack_networking_floatingip_v2
.
ip_pool
.
address
),
3
))
}
"
host
=
"
${
format
(
"
${
var
.
host-prefix
}
"
,
element
(
split
(
"."
,
openstack_networking_floatingip_v2
.
ohpc_ip
.
address
),
3
))
}
"
user
=
"
${
var
.
ohpc-user
}
"
private_key
=
"
${
file
(
var
.
ssh-private-key
)
}
"
}
...
...
@@ -107,3 +111,60 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" {
]
}
}
# creates details for the OOD instance using variables defined in vars.tf
resource
"openstack_compute_instance_v2"
"ood"
{
depends_on
=
[
"openstack_networking_subnet_v2.external_subnet"
]
name
=
"
${
var
.
ood-instance-name
}
"
image_name
=
"
${
var
.
image
}
"
flavor_name
=
"
${
var
.
flavor
}
"
key_pair
=
"
${
openstack_compute_keypair_v2
.
keypair
.
name
}
"
security_groups
=
[
"default"
]
# defines the networks of the instance
network
{
name
=
"
${
var
.
external-net
}
"
}
network
{
name
=
"
${
var
.
internal-net
}
"
}
}
# associates floating ip with the OOD instance and run the ansible playbook
resource
"openstack_compute_floatingip_associate_v2"
"ood"
{
floating_ip
=
"
${
openstack_networking_floatingip_v2
.
ood_ip
.
address
}
"
instance_id
=
"
${
openstack_compute_instance_v2
.
ood
.
id
}
"
# defines ssh connection
connection
{
host
=
"
${
format
(
"
${
var
.
host-prefix
}
"
,
element
(
split
(
"."
,
openstack_networking_floatingip_v2
.
ood_ip
.
address
),
3
))
}
"
user
=
"
${
var
.
ood-user
}
"
private_key
=
"
${
file
(
var
.
ssh-private-key
)
}
"
}
# installs programs
provisioner
"remote-exec"
{
inline
=
[
"sudo mkdir -p /CRI_XCBC && sudo chown centos: /CRI_XCBC"
,
"sudo yum install -y epel-release"
,
"sudo yum install -y ansible git vim bash-completion"
,
"sudo yum install -y NetworkManager"
,
"sudo systemctl restart NetworkManager"
,
"sudo nmcli con mod 'Wired connection 1' connection.id 'eth1'"
]
}
# moves CRI_XCBC file into directory made above
provisioner
"file"
{
source
=
"CRI_XCBC/"
destination
=
"/CRI_XCBC/"
}
# runs ansible playbook
provisioner
"remote-exec"
{
inline
=
[
"sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/site.yaml -b"
]
}
}
output.tf
View file @
265d0488
output
"address"
{
value
=
"
${
openstack_networking_floatingip_v2
.
ip_pool
.
address
}
"
output
"ohpc_address"
{
value
=
"
${
openstack_networking_floatingip_v2
.
ohpc_ip
.
address
}
"
}
output
"ood_address"
{
value
=
"
${
openstack_networking_floatingip_v2
.
ood_ip
.
address
}
"
}
output
"external_network_id"
{
...
...
vars.tf
View file @
265d0488
...
...
@@ -49,6 +49,14 @@ variable "ohpc-user" {
default
=
"centos"
}
variable
"ood-instance-name"
{
default
=
"ood"
}
variable
"ood-user"
{
default
=
"centos"
}
variable
"public-network-name"
{
default
=
"bright-external-flat-externalnet"
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment