pulumi / pulumi

Pulumi - Infrastructure as Code in any programming language 🚀
https://www.pulumi.com
Apache License 2.0
20.91k stars 1.09k forks source link

consider prompting for region with picklist #9228

Open susanev opened 2 years ago

susanev commented 2 years ago

overview

when the region is not yet set in the config, can we prompt for it with a picklist? e.g., when following this tutorial https://www.pulumi.com/registry/packages/aws/how-to-guides/s3-website/ they have to use the config command and know the appropriate values that are possible, can we make this better?

questions

when should we detect that this is not yet set?

Frassle commented 2 years ago

@AaronFriel this would be a good use case for typed provider configs

susanev commented 2 years ago

notes from Zaid:

susanev commented 2 years ago

notes from Pat

pgavlin commented 2 years ago

+1 to what @Frassle said

mikhailshilkov commented 2 years ago

Related to https://github.com/pulumi/pulumi/issues/2307

lukehoban commented 2 years ago

And perhaps even moreso related to https://github.com/pulumi/pulumi/issues/1052 and specifically https://github.com/pulumi/pulumi/issues/1052#issuecomment-374255486.

t0yv0 commented 2 years ago

I've looked here briefly, it feels good to wait on https://github.com/pulumi/home/issues/2216 typed config design to settle first, then revisit. What we need primarily is indeed knowing that the type of "aws:region" is "aws:index/Region:Region". If we knew that we could look up possible values from the schema and display them to the user, check, or auto-complete.

Possible values indexed by type info:

$ jq .types["aws:index/Region:Region"] pulumi-aws-v4.37.3.json

{
  "description": "A Region represents any valid Amazon region that may be targeted with deployments.",
  "type": "string",
  "enum": [
    {
      "name": "AFSouth1",
      "value": "af-south-1"
    },
    {
      "name": "APEast1",
      "value": "ap-east-1"
    },
    {
      "name": "APNortheast1",
      "value": "ap-northeast-1"
    },
    {
      "name": "APNortheast2",
      "value": "ap-northeast-2"
    },
    {
      "name": "APSouth1",
      "value": "ap-south-1"
    },
    {
      "name": "APSoutheast2",
      "value": "ap-southeast-2"
    },
    {
      "name": "APSoutheast1",
      "value": "ap-southeast-1"
    },
    {
      "name": "CACentral",
      "value": "ca-central-1"
    },
    {
      "name": "CNNorth1",
      "value": "cn-north-1"
    },
    {
      "name": "CNNorthwest1",
      "value": "cn-northwest-1"
    },
    {
      "name": "EUCentral1",
      "value": "eu-central-1"
    },
    {
      "name": "EUNorth1",
      "value": "eu-north-1"
    },
    {
      "name": "EUWest1",
      "value": "eu-west-1"
    },
    {
      "name": "EUWest2",
      "value": "eu-west-2"
    },
    {
      "name": "EUWest3",
      "value": "eu-west-3"
    },
    {
      "name": "EUSouth1",
      "value": "eu-south-1"
    },
    {
      "name": "MESouth1",
      "value": "me-south-1"
    },
    {
      "name": "SAEast1",
      "value": "sa-east-1"
    },
    {
      "name": "USGovEast1",
      "value": "us-gov-east-1"
    },
    {
      "name": "USGovWest1",
      "value": "us-gov-west-1"
    },
    {
      "name": "USEast1",
      "value": "us-east-1"
    },
    {
      "name": "USEast2",
      "value": "us-east-2"
    },
    {
      "name": "USWest1",
      "value": "us-west-1"
    },
    {
      "name": "USWest2",
      "value": "us-west-2"
    }
  ]
}

Ideally this typing of "aws:region" as "aws:index/Region:Region" would be simply written in Pulumi.yaml based on typed config work, but if not, perhaps there's other ways we can recover or special-case magically for "aws:region".

Here's another possible source of type information:

jq '.config.variables.region' pulumi-aws-v4.37.3.json                                                                                       ~/schemas
{
  "type": "string",
  "$ref": "#/types/aws:index/region:Region",
  "description": "The region where AWS operations will take place. Examples are us-east-1, us-west-2, etc.\n",
  "defaultInfo": {
    "environment": [
      "AWS_REGION",
      "AWS_DEFAULT_REGION"
    ]
  }
}

But I'm not sure we can assume that a Pulumi config value called "aws:region" refers to the "region" variable from the "aws" provider schema, or can we? If we can make this connection, we can already lookup the type of "aws:region".

I've also found something curious not covered by Config tickets. Looks like here: https://github.com/pulumi/templates/blob/master/aws-typescript/Pulumi.yaml#L8 - we support Config section in templates also, but this gets expanded out at "pulumi new". So actually pulumi new prompts for the value. Similarly if we could know the type there, and if this is an enum type we could improve how we prompt for this value at "pulumi new".

We also seem to be prompting for a value when doing "pulumi set aws:region", so this is another place where a pick list could go. We could also reject invalid values and print valid ones if the user does "pulumi set aws:region bad".

@dixler regarding the UI - do we have the capability to display a pick list already?

t0yv0 commented 2 years ago

In iteration planning today, we decided to drop this until structured config lands, and not to add an extra assumption in code that pulumi config set aws:region refers to a configuration property from .config.variables.region in the schema, or generally that:

pulumi config set aws:X <-> .config.variables.X

It seems to be accidental and not by-design.

So hopefully with structured/typed config we will have a cleaner way to look up type information for "aws:region" that will make it easy.

rulatir commented 2 months ago

While at it, consider picking all relevant values from the current AWS config (i.e. ~/.aws/config or wherever AWS_CONFIG_FILE points), or at least offering them as defaults in the prompts. ESPECIALLY for those situations where the values can't be supplied with pulumi config without pulumi config sending you back to square one ("choose a stack").