Skip to content
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

Add a project tag in sliderule-base.pkr.hcl to capture costs for the prov-sys #297

Open
cugarteblair opened this issue Aug 8, 2023 · 5 comments

Comments

@cugarteblair
Copy link
Contributor

inside the default_tags. tags= section
Project = "cluster-${var.cluster_name}"

`locals {
terraform-git-repo = "sliderule-cluster"
}

provider "aws" {
region = var.aws_region
default_tags {
tags = {
Owner = "SlideRule"
Project = "cluster-${var.cluster_name}"
terraform-base-path = replace(path.cwd,
"/^.*?(${local.terraform-git-repo}\/)/", "$1")
cost-grouping = "${var.cluster_name}"
}
}
}`

@cugarteblair cugarteblair changed the title Add a a project tag in your sliderule-base.pkr.hcl to capture costs for the prov-sys Add a a project tag in sliderule-base.pkr.hcl to capture costs for the prov-sys Aug 8, 2023
@jpswinski
Copy link
Member

@cugarteblair - I went to add the project tag to the packer file, and I realized that there is no concept of a cluster for the packer build. We use the same AMI across all cluster and all types of instances. I think we want to keep it that way because it greatly simplifies managing it. Also, for security reasons, we never want to go back to an old AMI, or use anything other than the latest.

@cugarteblair
Copy link
Contributor Author

cugarteblair commented Aug 22, 2023 via email

@cugarteblair
Copy link
Contributor Author

Is the issue that the packer is built independent of instantiating the EC2?

@jpswinski
Copy link
Member

Yes, that's right. We maintain only three AMI's: "v3", "latest", and "unstable". In practice, v3 and latest are the only ones I keep up-to-date. We don't keep fully specified versions or old versions, because as soon as an AMI needs to be updated, it has to be updated across the board for every cluster.

@cugarteblair cugarteblair reopened this Aug 23, 2023
@cugarteblair cugarteblair changed the title Add a a project tag in sliderule-base.pkr.hcl to capture costs for the prov-sys Add a project tag in sliderule-base.pkr.hcl to capture costs for the prov-sys Aug 23, 2023
@cugarteblair
Copy link
Contributor Author

from chatgpt...
In AWS, there's a distinction between EC2 instance tags and Auto Scaling Group (ASG) tags. When you're using an Auto Scaling Group in Terraform, if you want the tags to propagate to the instances launched by that ASG, you must define them within the aws_autoscaling_group resource and ensure that propagate_at_launch is set to true for each tag.

The default_tags section under the provider "aws" block in your Terraform configuration will ensure that all AWS resources created by Terraform will get the defined tags. However, it won't ensure that the tags propagate to the instances launched by an ASG.

To ensure that the tags defined in the provider "aws" block get propagated to the EC2 instances launched by the ASG, you need to add those tags explicitly to the aws_autoscaling_group resource.

Here's how you can modify the aws_autoscaling_group block from your sliderule-asg.tf file:

resource "aws_autoscaling_group" "sliderule-cluster" {
  # ... (other properties)

  tag {
    key                 = "Name"
    value               = "${var.cluster_name}-node"
    propagate_at_launch = true
  }

  tag {
    key                 = "Owner"
    value               = "SlideRule"
    propagate_at_launch = true
  }

  tag {
    key                 = "Project"
    value               = "cluster-${var.cluster_name}"
    propagate_at_launch = true
  }

  tag {
    key                 = "terraform-base-path"
    value               = replace(path.cwd, "/^.*?(${local.terraform-git-repo}\\/)/", "$1")
    propagate_at_launch = true
  }

  tag {
    key                 = "cost-grouping"
    value               = "${var.cluster_name}"
    propagate_at_launch = true
  }
}

This will ensure that the tags you've defined in the provider "aws" block get propagated to the EC2 instances launched by the ASG.

jpswinski added a commit that referenced this issue Aug 23, 2023
Add a project tag  to capture costs for the prov-sys #297
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

No branches or pull requests

2 participants