How to deploy terraform tf files through octopus

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!

1 Like

we are getting error again.PFA ServerTasks-2033.log.txt (11.5 KB)




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.

Hi

I am trying to use this terraform package
PFA and let us know terraform-ec2.0.2.zip (802 Bytes)

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)