How to get IP address of MAAS machine by terraform output

152 Views Asked by At

I provision machine by terraform and maas but I can't get ip address of provided machine in

output of terraform.

I'm using of suchpuppet as maas provider

for IaC but just returned machine_id and doesn't return IP address of it. Terraform code

output terraform

In output returning machine_id instead of ip address of machine.

1

There are 1 best solutions below

0
On BEST ANSWER

Thanks for your comment.

I resolve my problem by calling MAAS API and sending machine_id to MAAS API

and getting the IP address of the machine for use in the configuration manager

tools.

from oauthlib.oauth1 import SIGNATURE_PLAINTEXT # fades
from requests_oauthlib import OAuth1Session # fades

MAAS_HOST = "URL_OF_MAAS"
CONSUMER_KEY, CONSUMER_TOKEN, SECRET = "API_KEY_MAAS".split(":")

maas = OAuth1Session(CONSUMER_KEY, resource_owner_key=CONSUMER_TOKEN, 
resource_owner_secret=SECRET, signature_method=SIGNATURE_PLAINTEXT)

nodes = maas.get(f"{MAAS_HOST}/api/2.0/machines/gfppbc/")
nodes.raise_for_status()

print(nodes.json()['ip_addresses'][0])