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

WIP: feat: add the first component #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gberenice
Copy link
Member

@gberenice gberenice commented Apr 24, 2023

Info

  • This adds our first component tailscale so we could discuss and agree on the structure.

Questions that come up:

  1. At this moment we don't have any intermediate tool or interface that could help us to work with mixins the way we used to. We need to decide what is the role of mixins in our components? If we use them - what is the workflow/structure/other rules that we should declare?
  2. Should we add trunk?
  3. Basically these components should be used as TF modules unless we add some custom layer. If so - what is our definition of component? When it should be created and when it's enough to use a root module (+ probably some locals, variables or data)?
  4. Should we consider that these components will be used for current customers?
  5. Who is the end user of these components?

@gberenice gberenice requested a review from Gowiem April 24, 2023 14:54
@kevcube kevcube self-requested a review April 24, 2023 22:53
Comment on lines +2 to +3
vpc_id = data.aws_vpc.default.id
vpc_cidr_block = data.aws_vpc.default.cidr_block
Copy link

Choose a reason for hiding this comment

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

IMO these locals don't add any value

private_subnet_ids = toset(data.aws_subnets.private.ids)
}

data "aws_vpc" "default" {
Copy link

Choose a reason for hiding this comment

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

I don't think we should name this object "default" because we aren't looking for the default VPC

locals {
vpc_id = data.aws_vpc.default.id
vpc_cidr_block = data.aws_vpc.default.cidr_block
private_subnet_ids = toset(data.aws_subnets.private.ids)
Copy link

Choose a reason for hiding this comment

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

data.aws_subnets.private.ids will already be a list(string) in which we don't expect to find duplicates, right? I don't think we need explicit conversion to set

@@ -0,0 +1,25 @@
module "tailscale_subnet_router" {
source = "git::https://github.com/masterpointio/terraform-aws-tailscale.git?ref=tags/0.1.0"
Copy link

Choose a reason for hiding this comment

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

side note: @Gowiem we should publish to Terraform Registry so we can reference this as "masterpointio/tailscale/aws"

But also we should be more specific about how that repo is named, instead of "tailscale" call it "tailscale-subnet-router"

Or if it is going to be a collection of tailscale resources, then make ./modules/subnet-router

session_logging_enabled = var.tailscale_session_logging_enabled
}

module "ssh_key_pair" {
Copy link

Choose a reason for hiding this comment

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

Suggested change
module "ssh_key_pair" {
module "ec2_key_pair" {

to differentiate that we aren't just creating a public/private key with something like tls_private_key

Comment on lines +1 to +16
locals {
aws_account_id = module.account.outputs.full_account_map[var.stage]
assume_role = format("arn:aws:iam::${local.aws_account_id}:role/${var.namespace}-${var.stage}-%s", var.run_in_cicd ? "terraform" : "admin")
}

variable "run_in_cicd" {
type = bool
description = "If run in CI/CD platform, use terraform delegated role, otherwise use admin."
default = true
}

variable "assume_role_override" {
type = string
description = "Overrides the assumed role for the AWS provider. Useful for local testing and imports."
default = null
}
Copy link

Choose a reason for hiding this comment

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

All of this logic is pretty heavily dependent on someone already following the Cloudposse/Atmos account management blueprint, which marries us to their architecture. It makes sense to be prescriptive about their architecture to our customers because we are already deep in it, but public consumers of this "component" will likely not be using that same architecture.

cc @Gowiem

Copy link
Member Author

Choose a reason for hiding this comment

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

Mainly this is a trace of Masterpoint using Spacelift. The variable run_in_cicd was renamed from run_in_spacelift, for example.
The assumption here is that we still would want to separate local roles and roles used in CI/CD platforms. However, with tf-controller this all is very questionable, and the final working version could look very different from the pattern we're following now.

Comment on lines +28 to +36
module "account" {
source = "cloudposse/stack-config/yaml//modules/remote-state"
version = "0.22.3"

component = "account-map"
stage = "root"

context = module.this.context
}
Copy link

Choose a reason for hiding this comment

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

same as above

Comment on lines +49 to +53
provider "tailscale" {
tailnet = var.tailnet
oauth_client_id = local.secrets.tailscale_oauth_client_id
oauth_client_secret = local.secrets.tailscale_oauth_client_secret
}
Copy link

Choose a reason for hiding this comment

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

same here, I feel the way we are providing creds to the provider to be a little prescriptive, maybe I'm missing the point here and we really WANT to be prescriptive about this sort of stuff, but if I was managing infra I probably would have my stuff set up in a way that these are fed in via environment variables.

here we're placing a boundary to adoption on someone already storing these things in SSM

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's an open question.
I like the idea of having some kind of secrets mixin (or probably module), that provides us an elegant way to work primarily with SOPS (and support any other manager we need). If we unfollow Atmos' way - we need to come up with something new. I don't know if we ever would want to pass a secret value as a Terraform variable, since usually it's configured as fetching secret value from some storage, but I'm open to any good example to reconsider.

variable "ssh_public_key_path" {
type = string
description = "Path to SSH public key directory (e.g. `/secrets`)"
}
Copy link

Choose a reason for hiding this comment

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

Suggested change
}
}

Copy link

Choose a reason for hiding this comment

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

same as above, this is prescriptive and dependent on implementations that we use but others might not - if our master plan is to integrate tightly into the cloudposse component ecosystem then this makes sense

if our plan here is to make modules for internal use then no problem

but if our plan is to make an attractive library of useful marketing materials then I feel like we're placing a big operational burden on potential users here to conform to our implementation details - one of my main gripes with cloudposse's components. These things make sense for our customers - partly because it's how things are already done there - but might not make sense for everyone

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, agree here. We should have a clear understanding of who are our end users, and who do we expect to participate in evolution of this ecosystem.

@Gowiem
Copy link
Member

Gowiem commented Feb 9, 2024

@gberenice damn April 2023, I'm sorry this got full stopped! I'm surprised we did that to ourselves here. Let's chat through live and see if we should close or push through.

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