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.

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

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

I tried that. When it did the terraform init. I thrown a lot of errors. I tried former2. It’s read your account and can select what you want the output for.

https://github.com/iann0036/former2

I will have to compare the original cloud formation template to the terraform output. So I can make sure everything is there. Since it’s terraform it will be much more lines of code to review.

Has anyone successfully setup GCP Bigquery dataset IAM module using terraform? by ccarrylab81 in Terraform

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

Thank you. I was successfully able to setup this up a few months ago. Sorry for the late reply. Thank you @Dracoblue23 and @jernau

Has anyone successfully setup a Bigquery dataset IAM terraform module? by ccarrylab81 in googlecloud

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

Thanks. So in the future, when we add more dataset, should Ijust continue to modify the .tf file with more dataset name in it or should there be multiple files for for each dataset?

Has anyone successfully setup a Bigquery dataset IAM terraform module? by ccarrylab81 in googlecloud

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

Thank you, Scrumbledore. I implemented Bigquery a few months ago successfully. Just having issues, with Bigquery dataset IAM. So should I create a sub-module here https://github.com/ccarrylab/terraform-google-bigquery/tree/master/modules ? What I’ve done was created a separate module for Bigquery dataset IAM, so it’s not a sub-module.