How to deploy multiple terraform tf files through octopus
Hey there @kakarlayogitha - can you tell me a little more about your Terraform? Are you deploying separate environments, or separate projects? Are they all within the same package, or are you specifying them inline using the built in Terraform steps?
Learning a little more about how youâre using the steps today and youâre ultimate goal with multiple files will help me provide relevant recommendations and help!
Hello ,
Currently we want to deploy our couple of tf files (main.tf , variable.tf , output , etc) through octopus as part of single project.
Kindly help me on how to do the same
i need to deploy aws resources / create aws resources through octopus
Hello
In our current project , we have couple of terraform files as attached zip file
kindly let us know where to mention var file information
we have uploaded tis zip file as package and we are using it in â.Apply a Terraform templateâ step
Kindly guide terraform-ec2.0.2.zip (1.1 KB)
us
Hey @kakarlayogitha , thanks for sharing that additional context and sample file!
There are some great resources on working with Terraform in our documentation - that said, here are some resources around your specific use case.
With your current file structure, the Octopus configuration for deploying with your variable files is similar to using it from the command line.
If you were using this terraform from the command line, youâd use a command like terraform apply --var-file="var.tf"
, because var.tf
is the file that contains all of your variable defaults.
Using the Apply a Terraform Template
step, this option is available under Advanced Options â Terraform Options â Custom terraform apply parameters. The example above would look like this:
Something else to mention is that Octopus offers native variable substitution for Terraform files - following the examples in the documentation, you could create Octopus variables that map to your Terraform and allow you to not need the .var
files in the first place.
Hopefully this helps get you unblocked, feel free to reach out if you have any additional questions or run into any issues!
Hi
PFA screenshots which shows the process .please suggest me for error.we have uploaded the zip package of terraform files (as attached previously) as Package and am using it here .
PFA screeshots
When i tried to create release with above process , i get below error attached in txt file ServerTasks-1889.log.txt (18.0 KB)
Sorry @kakarlayogitha , my initial screenshot was incorrect - the input youâre looking for is under Template â Package â Additional Variable files:
An optional newline-separated list of files that are passed as -var-file parameters. Note that files called terraform.tfvars , terraform.tfvars.json ,*.auto.tfvars and *.auto.tfvars.json are automatically loaded by Terraform, and do not need to be listed here. Each line in this text area is passed as an individual -var-file parameter.
So, instead of -var-file="var.tf"
, you should be able to just put the var.tf
file name in that box and have it handled by the Octopus step. Sorry for the misinformation on that part!
Please suggest us
Your task logs indicate an issue with running terraform init
against the main ec2instance.tf
file.
Can you confirm that you can correctly terraform init
and terraform apply
from your local CLI?
It looks like there may be issues with your Terraform syntax - I noticed you have the var.tf
file weâve been discussing, as well as a terraform.tfvars
and a web.auto.tfvars
file. According to the terraform documentation, your input files for variables should end in .tfvars
. You have your variables declared in var.tf
, but youâre missing some values in your two .tfvars
file. Your ec2instance.tf
file also references Terraform resources that donât exist in your module - aws_security_group.vpc-ssh.id
and aws_security_group.vpc-web.id
Please recheck your source code and ensure itâs working correctly, that will help isolate where the issues are occurring in Octopus.
we need to have this terraform available in worker node right ?
i have ran below commands on worker node âŠPlease check and suggest me
C:\Users\Administrator>terraform init
Terraform initialized in an empty directory!
The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.
C:\Users\Administrator>terraform apply
â·
â Error: No configuration files
â
â Apply requires configuration to be present. Applying without a configuration would mark everything for destruction,
â which is normally not what is desired. If you would like to destroy everything, run âterraform destroyâ instead.
â”
@kakarlayogitha - Correct, youâll need Terraform installed on your worker. However, youâll need to run the commands in the directory of your .tf
files, rather than in the home directory. In this case, youâd want to run it in your terraform-ec2.0.2
folder.
I looked at your updated code, and I think you may still have some issues with variable declarations and variable assignment. Iâd recommend taking another look at the Hashicorp documentation on variables and making sure your code matches the expected input variable behavior: Input Variables - Configuration Language - Terraform by HashiCorp
Hello,
However, youâll need to run the commands in the directory of your .tf
files, rather than in the home directory. In this case, youâd want to run it in your terraform-ec2.0.2
folder.---- How can we ensure this ?? as mentioned earlier screenshots , i have given parameter as var.tfvars in additional variable files step
but still release failed with error .PFA file
ServerTasks-2059.log.txt (17.6 KB)
ServerTasks-2257.log.txt (21.4 KB)
Hello
I have sorted out few issues and we are getting below issue now
Please suggest us terraform-ec2.0.5.zip (985 Bytes)
Hello,
Kindly find our latest code and errors while release.
Please suggest us how to deploy terraform through octopus
terraform-ec2.0.9.zip (1.1 KB)
ServerTasks-2347.log.txt (21.6 KB)
Hi @kakarlayogitha,
Just stepping in for Cory.
From the logs youâve provided, it seems that Terraform is looking for âvar.tfvarsâ as the variable file however the files youâve provided has the name âvariable.tfvarsâ instead.
05:40:57 Info | "terraform.exe" apply -no-color -auto-approve -var-file="var.tf"
Feel free to let me know if this doesnât help resolve the issue or if you get any further error messages!
Best Regards,
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.