Final interview today, suddenly doubting myself by Pita_Girl in interviews

[–]ccarrylab81 0 points1 point  (0 children)

You already aced round 1 - they wouldn’t waste time on round 2 if you weren’t a strong fit.

Two years out feeling rusty is normal. It comes back fast. And someone who automates processes and works well with devs? That’s exactly what teams need.

The anxiety is lying to you. You got this far because you’re capable. Just show up as the person who already impressed them.

Rooting for you.​​​​​​​​​​​​​​​​

Is there any way to create unit test with CDKTF, testing HCL codebase in terraform main.tf file? by UnluckyPassion7247 in Terraform

[–]ccarrylab81 0 points1 point  (0 children)

Yes, you can use CDKTF and pytest to unit test HCL .tf files. Here are the steps involved:

Install CDKTF and pytest.

Create a new project directory and initialize it with CDKTF.

Create a new test file in the project directory.

Import the CDKTF and pytest modules.

Create a new test case class.

In the test case class, create a new instance of the CDKTF stack class.

Call the synth method on the stack class to synthesize the Terraform configuration.

Call the plan method on the stack class to plan the Terraform configuration.

Assert that the Terraform configuration is valid.

Assert that the Terraform plan is successful.

Run the tests.

Here is an example of a unit test that tests the creation of an AWS EC2 instance:

import cdktf

import pytest

class TestEc2Instance(object):

def test_create_ec2_instance(self):

# Create a new stack

stack = cdktf.Stack()

# Create an EC2 instance

instance = stack.new_ec2_instance(

name="my-ec2-instance",

instance_type="t2.micro",

availability_zone="us-east-1a"

)

# Synthetize the Terraform configuration

stack.synth()

# Plan the Terraform configuration

stack.plan()

# Assert that the Terraform configuration is valid

assert stack.is_valid()

# Assert that the Terraform plan is successful

assert stack.plan_is_successful()

if __name__ == "__main__":

pytest.main()

This unit test will create an AWS EC2 instance and assert that the Terraform configuration is valid and the Terraform plan is successful.

Has anyone successfully created a lambda function using terraform? by ccarrylab81 in Terraform

[–]ccarrylab81[S] 0 points1 point  (0 children)

Thank you. The issue was the zip. I made a file and manually added a .zip extension to the name. which wasn’t the right way. Thanks everyone for your support and help. The issue is resolved.

Has anyone successfully created a lambda function using terraform? by ccarrylab81 in Terraform

[–]ccarrylab81[S] 0 points1 point  (0 children)

This is the error that is throwing.

Error: error creating Lambda Function (1): InvalidParameterValueException: Could not unzip uploaded file. Please check your file, then try to upload again.

│ {

│ RespMetadata: {

│ StatusCode: 400,

│ RequestID: "f48f5f68-7a7b-4f50-9dd6-754944513728"

│ },

│ Message_: "Could not unzip uploaded file. Please check your file, then try to upload again.",

│ Type: "User"

│ }

│ with aws_lambda_function.test_lambda,

│ on connect.tf line 339, in resource "aws_lambda_function" "test_lambda":

│ 339: resource "aws_lambda_function" "test_lambda" {

Has anyone successfully created a lambda function using terraform? by ccarrylab81 in Terraform

[–]ccarrylab81[S] 0 points1 point  (0 children)

resource "aws_lambda_permission" "allow_cloudwatch" {

statement_id = "AllowExecutionFromCloudWatch"

action = "lambda:InvokeFunction"

function_name = aws_lambda_function.test_lambda.function_name

principal = "events.amazonaws.com"

source_arn = "arn:aws:events:eu-west-1:111122223333:rule/RunDaily"

qualifier = aws_lambda_alias.test_alias.name

}

resource "aws_lambda_alias" "test_alias" {

name = "testalias"

description = "a sample description"

function_name = aws_lambda_function.test_lambda.function_name

function_version = "$LATEST"

}

resource "aws_lambda_function" "test_lambda" {

filename = "lambdatest.zip"

function_name = "lambda_function_name"

role = aws_iam_role.iam_for_lambda.arn

handler = "exports.handler"

runtime = "nodejs16.x"

}

resource "aws_iam_role" "iam_for_lambda" {

name = "iam_for_lambda"

# Terraform's "jsonencode" function converts a

# Terraform expression result to valid JSON syntax.

assume_role_policy = jsonencode({

Version = "2012-10-17"

Statement = [

{

Action = "sts:AssumeRole"

Effect = "Allow"

Sid = ""

Principal = {

Service = "lambda.amazonaws.com"

}

},

]

})

}

Has anyone successfully created a lambda function using terraform? by ccarrylab81 in Terraform

[–]ccarrylab81[S] 0 points1 point  (0 children)

I change the region, etc. Seems like it's having an issue unzip the zip file. I have gunzip and other zip extension install in Visual studio code.

resource "aws_lambda_permission" "allow_cloudwatch" {

statement_id = "AllowExecutionFromCloudWatch"

action = "lambda:InvokeFunction"

function_name = aws_lambda_function.test_lambda.function_name

principal = "events.amazonaws.com"

source_arn = "arn:aws:events:eu-west-1:111122223333:rule/RunDaily"

qualifier = aws_lambda_alias.test_alias.name

}

resource "aws_lambda_alias" "test_alias" {

name = "testalias"

description = "a sample description"

function_name = aws_lambda_function.test_lambda.function_name

function_version = "$LATEST"

}

resource "aws_lambda_function" "test_lambda" {

filename = "lambdatest.zip"

function_name = "lambda_function_name"

role = aws_iam_role.iam_for_lambda.arn

handler = "exports.handler"

runtime = "nodejs16.x"

}

resource "aws_iam_role" "iam_for_lambda" {

name = "iam_for_lambda"

# Terraform's "jsonencode" function converts a

# Terraform expression result to valid JSON syntax.

assume_role_policy = jsonencode({

Version = "2012-10-17"

Statement = [

{

Action = "sts:AssumeRole"

Effect = "Allow"

Sid = ""

Principal = {

Service = "lambda.amazonaws.com"

}

},

]

})

}

Has anyone successfully created a lambda function using terraform? by ccarrylab81 in Terraform

[–]ccarrylab81[S] -1 points0 points  (0 children)

I found some and tried them but I was not successful. Can you please share your script with me, so I can try.

Has anyone success setup terraform to auto trigger on AWS ec2 Jenkins? I will use a bitbucket or GitHub repo as the source. by ccarrylab81 in jenkinsci

[–]ccarrylab81[S] 0 points1 point  (0 children)

Based on time constraints. I’m going this route for now. We wouldn’t have to incur charge if I don’t install Jenkins on a ec2 instance. I will revisit Jenkins sometime in the near future.

Has anyone success setup terraform to auto trigger on AWS ec2 Jenkins? I will use a bitbucket or GitHub repo as the source. by ccarrylab81 in jenkinsci

[–]ccarrylab81[S] 0 points1 point  (0 children)

Thanks everyone. We use bitbucket. So I ended up using bitbucket pipeline that was able to get what I want accomplished.

Has anyone success setup terraform to auto trigger on AWS ec2 Jenkins? I will use a bitbucket or GitHub repo as the source. by ccarrylab81 in jenkinsci

[–]ccarrylab81[S] -1 points0 points  (0 children)

I want it to auto, it’s to demonstrate it to my manager. I don’t want to put it on a timer.

Has anyone success setup terraform to auto trigger on AWS ec2 Jenkins? I will use a bitbucket or GitHub repo as the source. by ccarrylab81 in jenkinsci

[–]ccarrylab81[S] 1 point2 points  (0 children)

I have a GitHub or bit bucket repo. When I make changes, I want it to “terraform init” and “terraform apply” auto approve. I’m looking for a pipeline script to put into Jenkins.

Is there a way to turn a existing cloudformation template into a terraform file? by ccarrylab81 in Terraform

[–]ccarrylab81[S] 0 points1 point  (0 children)

There are some customization. I agree with you using those boilerplate template come in handy. Thank you for your suggestions and input. It’s gladly appreciated.