Skip to content

Add possibility to use custom User Data #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed

Conversation

SweetOps
Copy link
Contributor

What

  • Add possibility to use custom User Data
  • Update README
  • Add template for PR

Why

  • Some AMIs doesn't support classic User Data

@SweetOps SweetOps self-assigned this Nov 24, 2017
@SweetOps
Copy link
Contributor Author

has been tested with following manifest

data "aws_ami" "pfsense" {
  most_recent = "true"

  filter {
    name   = "description"
    values = ["Netgate pfSense Certified 2.3.4"]
  }
}

data "template_file" "init" {
  template = "${file("1.sh")}"
}

module "admin_tier" {
  source                        = "cloudposse/terraform-aws-ec2-instance"
  ssh_key_pair                  = "sweetops"
  ami                           = "${data.aws_ami.pfsense.image_id}"
  vpc_id                        = "vpc-someid"
  subnet                        = "subnet-someid"
  associate_public_ip_address   = "true"
  create_default_security_group = "false"
  name                          = "pf"
  namespace                     = "cp"
  stage                         = "dev"
  user_data                     = ["${data.template_file.init.rendered}"]
}

module "admin_tier1" {
  source                        = "cloudposse/terraform-aws-ec2-instance"
  ssh_key_pair                  = "sweetops"
  ami                           = "${data.aws_ami.pfsense.image_id}"
  vpc_id                        = "vpc-someid"
  subnet                        = "subnet-someid"
  associate_public_ip_address   = "true"
  create_default_security_group = "false"
  name                          = "pf1"
  namespace                     = "cp"
  stage                         = "dev"
  custom_user_data              = ["${data.template_file.init.rendered}"]
}

README.md Outdated
@@ -56,7 +56,7 @@ module "kafka_instance" {
This module depends on these modules:

* [terraform-null-label](https://github.com/cloudposse/terraform-null-label)
* [terraform-template-user-data-github-authorized-keys](https://github.com/cloudposse/terraform-template-user-data-github-authorized-keys)
* [terraform-template-User Data-github-authorized-keys](https://github.com/cloudposse/terraform-template-user-data-github-authorized-keys)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to terraform-template-user-data-github-authorized-keys.

README.md Outdated
| `statistic_level` | `Maximum` | Statistic to apply to the alarm's associated metric | No |
| `metric_threshold` | `1` | Value against which the specified statistic is compared | No |
| `default_alarm_action` | `action/actions/AWS_EC2.InstanceId.Reboot/1.0` | String of action to execute when this alarm transitions into an ALARM state | No |
| `user_data` | `[]` | `User Data` which be concated with `terraform-template-User Data-github-authorized-keys`. Conflicts with `custom_user_data` | No |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terraform-template-user-data-github-authorized-keys

variables.tf Outdated
}

variable "user_data" {
description = "User data to provide when launching the instance"
description = "User Data which be concated with `terraform-template-User Data-github-authorized-keys`"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terraform-template-user-data-github-authorized-keys

main.tf Outdated
@@ -7,6 +7,7 @@ locals {
availability_zone = "${var.availability_zone != "" ? var.availability_zone : data.aws_subnet.default.availability_zone}"
ami = "${var.ami != "" ? var.ami : data.aws_ami.default.image_id}"
root_volume_type = "${var.root_volume_type != "" ? var.root_volume_type : data.aws_ami.info.root_device_type}"
user_data = "${length(var.custom_user_data) > 0 ? join("", var.custom_user_data) : join("", data.template_file.user_data.*.rendered)}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use var.custom_user_data instead of join("", var.custom_user_data) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case will be error during plan\apply, because trueval\falseeval should be string

user_data.tf Outdated
@@ -1,4 +1,5 @@
data "template_file" "user_data" {
count = "${local.instance_count && length(var.custom_user_data) == 0 ? 1 : 0}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use local.instance_count == 0.

value = "${zipmap(aws_network_interface.additional.*.id, aws_eip.additional.*.public_ip)}"
}

output "additional_eni_private" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example it need in sth for template rendering

@SweetOps
Copy link
Contributor Author

screenshot 2017-11-27 20 40 25

@osterman
Copy link
Member

osterman commented Dec 8, 2017

We are overloading this module. Enforcing a convention on the user data that including using github_authorized_keys is too restrictive. It's easy enough to pass these when invoking the module, especially since we have a module to generate user data for ghk.

Closing this in favor of #22

@osterman osterman closed this Dec 8, 2017
@aknysh aknysh deleted the custom_user_data branch June 3, 2018 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants