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

Refactor: optionally randomize resource names #73

Merged

Conversation

sanderginn
Copy link
Contributor

Adds a randomize_resource_names variable that allows random resource names to be generated.
This is less critical than its GCP counterpart due to the fact that AWS already generates random IDs, but for organizing resources it is still valuable to set resource names.

Due to a bug in the AWS provider running terraform apply twice would be needed to set the calculated tags. To circumvent this, the default_tags block in the provider config sets null for these tags:

default_tags {
  tags = {
    "Name"         = null
    "executor_tag" = null
    "deployment"   = "sourcegraph-executors"
  }
}

Test plan

Tested on scaletesting instance.

The following plan is produced when planning these changes on an existing deployment using v4.5.0 of the module with randomize_resource_names = false. There are some tags that are added because they have defaults added now, but those don't have functional impacts. The name tag for aws_autoscaling_group.autoscaler is updated from sourcegraph_executor to sourcegraph_executors to align with other naming conventions.

Terraform will perform the following actions:

  # module.executors.module.aws-docker-mirror.aws_security_group.default[0] will be updated in-place
  ~ resource "aws_security_group" "default" {
        id                     = "sg-0c3a16702f8ae3721"
        name                   = "SourcegraphExecutorsDockerMirrorAccess"
      ~ tags                   = {
          + "Name" = "SourcegraphExecutorsDockerMirrorAccess"
        }
      ~ tags_all               = {
          + "Name"       = "SourcegraphExecutorsDockerMirrorAccess"
            # (1 unchanged element hidden)
        }
        # (7 unchanged attributes hidden)
    }

  # module.executors.module.aws-executor.aws_autoscaling_group.autoscaler will be updated in-place
  ~ resource "aws_autoscaling_group" "autoscaler" {
        id                        = "sourcegraph_executors"
        name                      = "sourcegraph_executors"
        # (23 unchanged attributes hidden)


      - tag {
          - key                 = "name" -> null
          - propagate_at_launch = true -> null
          - value               = "sourcegraph_executor" -> null
        }
      + tag {
          + key                 = "name"
          + propagate_at_launch = true
          + value               = "sourcegraph_executors"
        }
        # (2 unchanged blocks hidden)
    }

  # module.executors.module.aws-executor.aws_iam_instance_profile.instance will be updated in-place
  ~ resource "aws_iam_instance_profile" "instance" {
        id          = "sourcegraph__executors"
        name        = "sourcegraph__executors"
      ~ tags        = {
          + "Name" = "sourcegraph__executors"
        }
      ~ tags_all    = {
          + "Name"       = "sourcegraph__executors"
            # (1 unchanged element hidden)
        }
        # (5 unchanged attributes hidden)
    }

  # module.executors.module.aws-executor.aws_launch_template.executor will be updated in-place
  ~ resource "aws_launch_template" "executor" {
      ~ default_version                      = 1 -> (known after apply)
        id                                   = "lt-0b1c2bb507662dc30"
      ~ latest_version                       = 1 -> (known after apply)
        name                                 = "sourcegraph_executor-template-20230304103845369900000002"
        tags                                 = {}
        # (17 unchanged attributes hidden)





      + tag_specifications {
          + resource_type = "instance"
        }
        # (4 unchanged blocks hidden)
    }

  # module.executors.module.aws-executor.aws_security_group.metrics_access[0] will be updated in-place
  ~ resource "aws_security_group" "metrics_access" {
        id                     = "sg-03830ca9ad561e223"
        name                   = "SourcegraphExecutorsMetricsAccess"
      ~ tags                   = {
          + "Name" = "SourcegraphExecutorsMetricsAccess"
        }
      ~ tags_all               = {
          + "Name"       = "SourcegraphExecutorsMetricsAccess"
            # (1 unchanged element hidden)
        }
        # (7 unchanged attributes hidden)
    }

Plan: 0 to add, 5 to change, 0 to destroy.

@sanderginn sanderginn requested review from a team and eseliger March 4, 2023 11:18
Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

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

Should we enable this by default in the examples, to highlight best practices?

@sanderginn sanderginn enabled auto-merge (squash) March 6, 2023 11:56
@sanderginn sanderginn merged commit 5e90164 into master Mar 6, 2023
@sanderginn sanderginn deleted the sginn/02-01-Refactor_add_option_to_randomize_resource_names branch March 6, 2023 12:07
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.

2 participants