Created
January 19, 2024 13:45
-
-
Save Yamini-crypto/b64dd09db5c0125384bf3eca92a1285c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Codedeploy main.tf | |
resource "aws_iam_role" "codedeploy_service_role" { | |
name = "codedeploy_service_role" | |
assume_role_policy = jsonencode({ | |
Version = "2012-10-17", | |
Statement = [ | |
{ | |
Action = "sts:AssumeRole", | |
Effect = "Allow", | |
Principal = { | |
Service = "codedeploy.amazonaws.com" | |
}, | |
}, | |
], | |
}) | |
} | |
resource "aws_iam_policy" "codedeploy_access_policy" { | |
name = "codedeploy_access_policy" | |
policy = jsonencode({ | |
Version = "2012-10-17", | |
Statement = [ | |
{ | |
Action = [ | |
"autoscaling:CompleteLifecycleAction", | |
"autoscaling:DeleteLifecycleHook", | |
"autoscaling:DescribeAutoScalingGroups", | |
"autoscaling:DescribeLifecycleHooks", | |
"autoscaling:PutLifecycleHook", | |
"autoscaling:RecordLifecycleActionHeartbeat", | |
"ec2:CreateTags", | |
"ec2:DeleteTags", | |
"ec2:DescribeInstances", | |
"ec2:DescribeTags", | |
"ec2:DetachInstances", | |
"ec2:AttachInstances", | |
"elasticloadbalancing:DeregisterInstancesFromLoadBalancer", | |
"elasticloadbalancing:DescribeInstanceHealth", | |
"elasticloadbalancing:DescribeLoadBalancers", | |
"elasticloadbalancing:RegisterInstancesWithLoadBalancer" | |
], | |
Effect = "Allow", | |
Resource = "*" | |
}, | |
], | |
}) | |
} | |
resource "aws_iam_role_policy_attachment" "codedeploy_access_policy_attachment" { | |
role = aws_iam_role.codedeploy_service_role.name | |
policy_arn = aws_iam_policy.codedeploy_access_policy.arn | |
} | |
resource "aws_codedeploy_app" "my_app" { | |
compute_platform = "Server" | |
name = "my_app" | |
} | |
resource "aws_codedeploy_deployment_group" "blue" { | |
app_name = aws_codedeploy_app.my_app.name | |
deployment_group_name = "blue" | |
service_role_arn = aws_iam_role.codedeploy_service_role.arn | |
} | |
resource "aws_codedeploy_deployment_group" "green" { | |
app_name = aws_codedeploy_app.my_app.name | |
deployment_group_name = "green" | |
service_role_arn = aws_iam_role.codedeploy_service_role.arn | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment