Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS::EC2::Instance ImageId is not converted to correct Terraform argument #148

Open
seifrajhi opened this issue Apr 15, 2023 · 3 comments
Open
Labels
argument_search_error A CF parameter was not correctly translated to Terraform bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@seifrajhi
Copy link

seifrajhi commented Apr 15, 2023

Hello,
First of all thank you for this amazing tool. it is time and efforts saver.

In the below CloudFormation stack, the tool is unable to convert the User data and can helpers which are used heavily in any CloudFormation stack

Resources:
  MyParameter:
    Type: AWS::SSM::Parameter
    Properties:
      Name: /MyStack/MyParameter
      Type: String
      Value: 'default-value'
  MyInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-01010101010101
      InstanceType: t2.micro
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash
          echo "MyParameter value is ${MyParameter}" >> /var/log/user-data.log
    Metadata:
      AWS::CloudFormation::Init:
        configSets:
          default:
            - myConfig
        myConfig:
          commands:
            01_set_param:
              command: !Sub |
                aws ssm put-parameter --name /MyStack/MyParameter --value "new-value" --type "String" 
@seifrajhi
Copy link
Author

Output :
many comments which is a weird behaviour I think

resource "aws_ssm_parameter" "my_parameter" {
  name = "/MyStack/MyParameter"
  type = "String"
  value = "default-value"
}

resource "aws_ec2_instance_state" "my_instance" {
  // CF Property(ImageId) = "ami-01010101010101"
  instance_id = "t2.micro"
  // CF Property(UserData) = base64encode("#!/bin/bash
  // echo "MyParameter value is ${aws_ssm_parameter.my_parameter.arn}" >> /var/log/user-data.log
  // ")
}

@shadycuz
Copy link
Member

@seifrajhi The comments are so that the program doesn't crash when it fails to convert a Cloudformation property to a Terraform attribute. It's not actually explained anywhere so that is something that could be improved.

The real question is why are basic things like ImageId and UserData not being converted correctly? This is easy to explain. The converter decided to try and convert the Cloudformation resource AWS::EC2::Instance to a Terraform resource of aws_ec2_instance_state when it should have done aws_instance. This is a bug.

Things we need to fix:

  1. Explain the use of comments for resources or attributes that could not be converted.
  2. Fix ec2 instance so that it converts to the proper resource.

@shadycuz shadycuz added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Apr 17, 2023
@shadycuz shadycuz changed the title Unable to convert many Cloudformation fields in EC2 and System manager AWS::EC2::Instance is converted to aws_ec2_instance_state instead of aws_instance Apr 17, 2023
@shadycuz
Copy link
Member

This conversion is getting better:

resource "aws_ssm_parameter" "my_parameter" {
  name = "/MyStack/MyParameter"
  type = "String"
  value = "default-value"
}

resource "aws_instance" "my_instance" {
  // CF Property(ImageId) = "ami-01010101010101"
  instance_type = "t2.micro"
  user_data = base64encode("#!/bin/bash
echo "MyParameter value is ${aws_ssm_parameter.my_parameter.arn}" >> /var/log/user-data.log
")
}

Still having issues with the ImageId.

@shadycuz shadycuz added the argument_search_error A CF parameter was not correctly translated to Terraform label Jun 18, 2023
@shadycuz shadycuz changed the title AWS::EC2::Instance is converted to aws_ec2_instance_state instead of aws_instance AWS::EC2::Instance ImageId is not converted to correct Terraform argument Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
argument_search_error A CF parameter was not correctly translated to Terraform bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants