diff --git a/modules/aws/bootstrap/README.md b/modules/aws/bootstrap/README.md new file mode 100644 index 00000000000..01a9478254a --- /dev/null +++ b/modules/aws/bootstrap/README.md @@ -0,0 +1,51 @@ +# Bootstrap Module + +This [Terraform][] [module][] manages [AWS][] resources only needed during cluster bootstrapping. +It uses [implicit provider inheritance][implicit-provider-inheritance] to access the [AWS provider][AWS-provider]. + +## Example + +Set up a `main.tf` with: + +```hcl +provider "aws" { + region = "us-east-1" +} + +resource "aws_s3_bucket" "example" { +} + +resource "aws_vpc" "example" { + cidr_block = "10.0.0.0/16" + enable_dns_hostnames = true + enable_dns_support = true +} + +resource "aws_subnet" "example" { + vpc_id = "${aws_vpc.example.id}" + cidr_block = "${aws_vpc.example.cidr_block}" +} + +module "bootstrap" { + source = "github.com/openshift/installer//modules/aws/bootstrap" + + ami = "ami-07307c397daf4d02e" + bucket = "${aws_s3_bucket.example.id}" + cluster_name = "my-cluster" + ignition = "{\"ignition\": {\"version\": \"2.2.0\"}}", + subnet_id = "${aws_subnet.example.id}" +} +``` + +Then run: + +```console +$ terraform init +$ terraform plan +``` + +[AWS]: https://aws.amazon.com/ +[AWS-provider]: https://www.terraform.io/docs/providers/aws/ +[implicit-provider-inheritance]: https://www.terraform.io/docs/modules/usage.html#implicit-provider-inheritance +[module]: https://www.terraform.io/docs/modules/ +[Terraform]: https://www.terraform.io/ diff --git a/modules/aws/bootstrap/main.tf b/modules/aws/bootstrap/main.tf new file mode 100644 index 00000000000..c83b0cefecd --- /dev/null +++ b/modules/aws/bootstrap/main.tf @@ -0,0 +1,127 @@ +resource "aws_s3_bucket_object" "ignition" { + bucket = "${var.bucket}" + key = "bootstrap.ign" + content = "${var.ignition}" + acl = "private" + + server_side_encryption = "AES256" + + tags = "${var.tags}" + + lifecycle { + ignore_changes = ["*"] + } +} + +data "ignition_config" "redirect" { + replace { + source = "s3://${var.bucket}/bootstrap.ign" + } +} + +resource "aws_iam_instance_profile" "bootstrap" { + name = "${var.cluster_name}-bootstrap-profile" + + role = "${var.iam_role == "" ? + join("|", aws_iam_role.bootstrap.*.name) : + join("|", data.aws_iam_role.bootstrap.*.name) + }" +} + +data "aws_iam_role" "bootstrap" { + count = "${var.iam_role == "" ? 0 : 1}" + name = "${var.iam_role}" +} + +resource "aws_iam_role" "bootstrap" { + count = "${var.iam_role == "" ? 1 : 0}" + name = "${var.cluster_name}-bootstrap-role" + path = "/" + + assume_role_policy = <