Difference between revisions of "Terraform AWS Operations"

From NovaOrdis Knowledge Base
Jump to: navigation, search
(Ready-Made AWS Modules)
(Create a Role, Permission Policy and Instance Profile)
 
(One intermediate revision by the same user not shown)
Line 8: Line 8:
 
=Create an EC2 Instance=
 
=Create an EC2 Instance=
 
{{Internal|Create_an_EC2_Instance_with_Terraform|Create an EC2 Instance with Terraform}}
 
{{Internal|Create_an_EC2_Instance_with_Terraform|Create an EC2 Instance with Terraform}}
 +
 +
=IAM Operations=
 +
 +
==Create a Role, Permission Policy and Instance Profile==
 +
 +
<syntaxhighlight lang="json">
 +
resource "aws_iam_role" "kubernetes-master" {
 +
 +
  name = "infra-${var.environment_name}-kubernetes-master"
 +
 +
  assume_role_policy = <<EOF
 +
{
 +
  "Version": "2012-10-17",
 +
  "Statement": [
 +
    {
 +
      "Effect": "Allow",
 +
      "Action": "sts:AssumeRole",
 +
      "Principal": {
 +
        "Service": "ec2.amazonaws.com"
 +
      }
 +
      }
 +
  ]
 +
}
 +
EOF
 +
}
 +
 +
resource "aws_iam_role_policy" "kubernetes-master" {
 +
 +
  name = "infra-${var.environment_name}-kubernetes-master"
 +
  role = aws_iam_role.kubernetes-master.id
 +
 +
  policy = <<EOF
 +
{
 +
  "Version": "2012-10-17",
 +
  "Statement": [
 +
    {
 +
      "Effect": "Allow",
 +
      "Action": ["ec2:*"],
 +
      "Resource": ["*"]
 +
    },
 +
    {
 +
      "Effect": "Allow",
 +
      "Action": ["elasticloadbalancing:*"],
 +
      "Resource": ["*"]
 +
    },
 +
    {
 +
      "Effect": "Allow",
 +
      "Action": ["route53:*"],
 +
      "Resource": ["*"]
 +
    },
 +
    {
 +
      "Effect": "Allow",
 +
      "Action": "s3:*",
 +
      "Resource": [
 +
        "arn:aws:s3:::kubernetes-*"
 +
      ]
 +
    }
 +
  ]
 +
}
 +
EOF
 +
}
 +
 +
resource "aws_iam_instance_profile" "kubernetes-master" {
 +
 +
  name = "infra-${var.environment_name}-kubernetes-master-profile"
 +
  role = "${aws_iam_role.kubernetes-master.name}"
 +
}
 +
</syntaxhighlight>

Latest revision as of 01:21, 4 December 2019

Internal

Ready-Made AWS Modules

https://registry.terraform.io/modules/terraform-aws-modules

Create an EC2 Instance

Create an EC2 Instance with Terraform

IAM Operations

Create a Role, Permission Policy and Instance Profile

resource "aws_iam_role" "kubernetes-master" {

  name = "infra-${var.environment_name}-kubernetes-master"

  assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "ec2.amazonaws.com"
      }
      }
  ]
}
EOF
}

resource "aws_iam_role_policy" "kubernetes-master" {

  name = "infra-${var.environment_name}-kubernetes-master"
  role = aws_iam_role.kubernetes-master.id

  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["ec2:*"],
      "Resource": ["*"]
    },
    {
      "Effect": "Allow",
      "Action": ["elasticloadbalancing:*"],
      "Resource": ["*"]
    },
    {
      "Effect": "Allow",
      "Action": ["route53:*"],
      "Resource": ["*"]
    },
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::kubernetes-*"
      ]
    }
  ]
}
EOF
}

resource "aws_iam_instance_profile" "kubernetes-master" {

  name = "infra-${var.environment_name}-kubernetes-master-profile"
  role = "${aws_iam_role.kubernetes-master.name}"
}