Been starring at this too long and I think I missed something dumb.. Writing a script to write information to a file. All the variables are strings being passed in from another function to write a file.
Here's my code:
53 def makeMainTF():
54 NameTag,mcGroupTag,mcIPTag = makeNameMCTag()
55 yourName = getAccessSecretName()
56 instanceType ="t2.micro"
57 with open ("vlslabMain.tf","w") as text_file:
58 text_file.writelines(['provider \"aws\" {\n',
59 ' ',
60 'access_key = \"${var.access_key}\"\n',
61 ' ',
62 'secret_key = \"${var.secret_key}\"\n',
63 ' ',
64 'region = \"${var.access_key}\"\n',
65 '}\n\n\n',
66 'resource \"aws_instance\" \"example\" {\n',
67 ' ',
68 'ami = \"${lookup(var.amis, var.region)}\"\n',
69 ' ',
70 'instance_type = \"%s\" \n}' % instanceType,
71 '\n\n\n\n',
72 'tags {\n',
73 ' ',
74 'Name = \"%s\"\n' % NameTag,
75 ' ',
76 'Multicast = \"%s,%s\"' % (mcGroupTag,mcIPTag),
77 ' ',
78 'Owner = \"%s\"' % yourName,
79 '\n}'])
Not sure why I'm getting this error :
Enter Access Key: asd
Enter Secret Key: asd
Enter your name: asd
Access Key: asd
Secret Key: asd
Your full name is: asd
Traceback (most recent call last):
File "terraTFgen.py", line 86, in <module>
makeMainTF()
File "terraTFgen.py", line 78, in makeMainTF
'Owner = \"%s\"' % yourName,
TypeError: not all arguments converted during string formatting
Maybe I've been starring at it too long but I dont see the syntax mistake.
It actually wrote out
Enter Access Key: asd
Enter Secret Key: asd
Enter your name: asd
Access Key: asd
Secret Key: asd
Your full name is: asd
But the error is causing the script not to write to the actual file.
Thanks for the help! ****edit***
This is the function I used to get the yourName variable
3 def getAccessSecretName():
4 access_key = raw_input("Enter Access Key: ")
5 secret_key = raw_input("Enter Secret Key: ")
6 yourName = raw_input("Enter your name: ")
7 print "Access Key: %s" % access_key
8 print "Secret Key: %s" % secret_key
9 print "Your full name is: %s" % yourName
10 return access_key, secret_key, yourName
yourName, seems like its a tuple.... Owner = "1234 4321 ralph test"which turned my string, into a tuple. Did I do something wrong in my getAccessSecretName()?