terraform to run Cloud formation template

2,750 views
Skip to first unread message

Sanjay Shitole

unread,
Mar 15, 2017, 3:33:57 PM3/15/17
to Terraform
Folks,
Was trying to run CFT from terraform  getting error, any help is appreciated ... below is the snippet 



resource "aws_cloudformation_stack"  "network" {

 name = "networking-stack"

  parameters {

   VPCCidr = "10.0.0.0/16"

}

  template_body = <<STACK


{

    "Description": "Template Version 1.0.0: AWS CloudFormation Template for creating a full stack with a 1NIC BIG-IP, a 1 Availability Zone VPC, subnets, security groups and a webserver (Bitnami LAMP stack with username bitnami **WARNING** This template creates Amazon EC2 Instances. You will be billed for the AWS resources used if you create a stack from this template.",

    "Mappings": {

        "BigipRegionMap": {

            "ap-northeast-1": {

                "Best1000Mbps": "ami-acf82acd",

                "Best200Mbps": "ami-6bfc2e0a",

                "Best25Mbps": "ami-a6f92bc7",

                "Better1000Mbps": "ami-aff82ace",


-----snippet




            },

            "Type": "AWS::EC2::Subnet"

        }

    }

}


}

} STACK

}


ubuntu@ubuntu-xenial:~/terraform/sanbox$ terraform plan

Error loading config: Error loading /home/ubuntu/terraform/sanbox/main.tf: Error reading config for aws_cloudformation_stack[network]: parse error: syntax error

ubuntu@ubuntu-xenial:~/terraform/sanbox





egul...@gmail.com

unread,
Mar 15, 2017, 6:32:17 PM3/15/17
to Terraform
Convert all your Cloudformation code to use Terraform.

Don't use Terraform to execute cloudformation. That's kind of missing the point of using Terraform :)

Derek Helmick

unread,
Mar 23, 2017, 2:10:41 PM3/23/17
to Terraform
You might do better saving your preexisting template to a file and importing to your terraform stack like this

template_body = "${file("cft.json")}"

Sanjay Shitole

unread,
Mar 29, 2017, 6:03:15 PM3/29/17
to Terraform


On Thursday, March 23, 2017 at 11:10:41 AM UTC-7, Derek Helmick wrote:
You might do better saving your preexisting template to a file and importing to your terraform stack like this

template_body = "${file("cft.json")}"

On Wednesday, March 15, 2017 at 3:33:57 PM UTC-4, Sanjay Shitole wrote:
Folks,
Was trying to run CFT from terraform  getting error, any help is appreciated ... below is the snippet 


Thanks for you response appreciate it, however I got an error with terraform apply... with terraform plan it shows no error

1.0/24\",\"Tags\":[{\"Key\":\"Application\",\"Value\":{\"Ref\":\"application\"}},{\"Key\":\"Costcenter\",\"Value\":{\"Ref\":\"costcenter\"}},{\"Key\":\"Environment\",\"Value\":{\"Ref\":\"environment\"}},{\"Key\":\"Group\",\"Value\":{\"Ref\":\"group\"}},{\"Key\":\"Name\",\"Value\":{\"Fn::Join\":[\"\",[\"Az\",\"1\",\" External Subnet:\",{\"Ref\":\"AWS::StackName\"}]]}},{\"Key\":\"Owner\",\"Value\":{\"Ref\":\"owner\"}}],\"VpcId\":{\"Ref\":\"Vpc\"}},\"Type\":\"AWS::EC2::Subnet\"}}}"

Error applying plan:


1 error(s) occurred:


* aws_cloudformation_stack.network: Creating CloudFormation stack failed: ValidationError: Parameters: [availabilityZone1, sshKey, adminPassword] must have values

status code: 400, request id: 01999b65-14cb-11e7-a932-e73c151739d8


Terraform does not automatically rollback in the face of errors.

Instead, your Terraform state file has been partially updated with

any resources that successfully completed. Please address the error

above and apply again to incrementally change your infrastructure.

ubuntu@ubuntu-xenial:~/terraform/sanbox 

Benjamin Lau

unread,
Mar 29, 2017, 6:43:11 PM3/29/17
to terrafo...@googlegroups.com
Sanjay,

The template you're using requires parameters to be set. This can be done via the terraform cloudformation resource. You're already setting one actually: VPCCidr. You don't have your whole cloudformation template there so I can't tell you how to set them all but you need to set availabilityZone1, sshKey, and adminPassword.

I just used this feature for the first time yesterday. Made getting a transit vpc up and running pretty easy. Instead of having to port this template[1] to terraform I was able to kind of just use it as is. Which is a kind of handy feature if you're already got bit in cloudformation that you're not interested in maintaining.

Ben

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/5c15ff65-fecc-4ed6-8b67-ce5e04f2bc5c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Sanjay Shitole

unread,
Mar 29, 2017, 7:42:44 PM3/29/17
to terrafo...@googlegroups.com
Thank you very much Benjamin, do I need to change in the Json file ? where exactly I should change the paremeters ? I see avaiabilityzone1 at several places ? here is the link for my cft.json file https://github.com/scshitole/awswork/blob/master/cft.json
appreciate your help

You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/3Hr3nxBKpM0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CA%2BvtdQZkYr4D2XNd9MZrJwrv3K%2BqRDqoTE4A-_4fOjorAsaPbA%40mail.gmail.com.

Benjamin Lau

unread,
Mar 29, 2017, 7:47:34 PM3/29/17
to terrafo...@googlegroups.com
You don't need to change the json at all. You just need to provide those values from terraform.

parameters {
   VPCCidr = "10.0.0.0/16"
   availabilityZone1 = "???" #(this will be something like us-east-1c)
   sshKey = "???" #(without seeing the template I don't know exactly what this is... could be an ec2 keypair could be something else)
   adminPassword = "???" #(this will be a string of some kind, might have requirements but again without the cf template I can't tell)
}

Sanjay Shitole

unread,
Mar 30, 2017, 12:57:45 PM3/30/17
to terrafo...@googlegroups.com
Thank you very much it worked 

resource "aws_cloudformation_stack"  "network" {

 name = "networking-stack"

  parameters {

   availabilityZone1 = "us-east-1a"

   sshKey = "xxx"

   adminPassword = "abc"

   imageName = "Best1000Mbps"

   instanceType = "m3.2xlarge"

   managementGuiPort =  "8443"

}

 template_body = "${file("cft.json")}"


}


ws_cloudformation_stack.network: Still creating... (2m20s elapsed)

aws_cloudformation_stack.network: Creation complete


Apply complete! Resources: 1 added, 0 changed, 0 destroyed.


The state of your infrastructure has been saved to the path

below. This state is required to modify and destroy your

infrastructure, so keep it safe. To inspect the complete state

use the `terraform show` command.


Jitendra Goswami

unread,
Feb 18, 2018, 8:51:49 AM2/18/18
to Terraform
Dear Sanjay / Benjamin

Please let me know the complete steps of cft template to run in terraform.

Thanks in advance.

Sanjay Shitole

unread,
Feb 19, 2018, 6:43:49 PM2/19/18
to Terraform
here is an working example with parameters

provider "aws" {

  region = "us-east-1"

}


resource "aws_cloudformation_stack"  "network" {

 name = "networking-stack"

  parameters {

   sshKey = "kkk"

   availabilityZone1 = "us-east-1a"

   adminPassword = "cisco123"

   imageName = "Best1000Mbps"

   instanceType = "m3.2xlarge"

   managementGuiPort =  "8443"

}

 template_body = "${file("cft.json")}"


}


Sanjay Shitole

unread,
Feb 19, 2018, 6:46:09 PM2/19/18
to Terraform
Please find

provider "aws" {

  region = "us-east-1"

}


resource "aws_cloudformation_stack"  "network" {

 name = "networking-stack"

  parameters {

   sshKey = "kkk"

   availabilityZone1 = "us-east-1a"

   adminPassword = "cisco123"

   imageName = "Best1000Mbps"

   instanceType = "m3.2xlarge"

   managementGuiPort =  "8443"

}

 template_body = "${file("cft.json")}"


}


Reply all
Reply to author
Forward
0 new messages