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

Deprecate Config, replace with StackConfigDir #9145

Merged
merged 14 commits into from Mar 13, 2022
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Expand Up @@ -15,6 +15,9 @@
edit the code to successfully run.
[#8922](https://github.com/pulumi/pulumi/pull/8922)

- [cli/config] Rename the `config` property in `Pulumi.yaml` to `stacksDirectory`. The `config` key will continue to be supported.
[#9145](https://github.com/pulumi/pulumi/pull/9145)

### Bug Fixes

- [sdk/python] - Fix build warnings. See
Expand Down
26 changes: 23 additions & 3 deletions sdk/go/common/workspace/paths.go
@@ -1,4 +1,4 @@
// Copyright 2016-2018, Pulumi Corporation.
// Copyright 2016-2022, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -98,8 +98,28 @@ func DetectProjectStackPath(stackName tokens.QName) (string, error) {
return "", err
}

return filepath.Join(filepath.Dir(projPath), proj.Config, fmt.Sprintf("%s.%s%s", ProjectFile, qnameFileName(stackName),
filepath.Ext(projPath))), nil
fileName := fmt.Sprintf("%s.%s%s", ProjectFile, qnameFileName(stackName), filepath.Ext(projPath))

// Back compat: StacksDirectory used to be called Config.
configValue, hasConfigValue := proj.Config.(string)
hasConfigValue = hasConfigValue && configValue != ""

if proj.StacksDirectory != "" {
// If config and stacksDirectory are both set return an error
if hasConfigValue {
return "", fmt.Errorf("can not set `config` and `stacksDirectory`, remove the `config` entry")
}

return filepath.Join(filepath.Dir(projPath), proj.StacksDirectory, fileName), nil
}

// Back compat: If StacksDirectory is not present and Config is given and it's a non-empty string use it
// for the stacks directory.
if hasConfigValue {
return filepath.Join(filepath.Dir(projPath), configValue, fileName), nil
Copy link
Member

@iwahbe iwahbe Mar 11, 2022

Choose a reason for hiding this comment

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

Should we issue a deprecation warning, suggesting that the user switches to use StacksDirectory?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure how well that would display, this is called into from a few different places.

}

return filepath.Join(filepath.Dir(projPath), fileName), nil
}

// DetectProjectPathFrom locates the closest project from the given path, searching "upwards" in the directory
Expand Down
104 changes: 104 additions & 0 deletions sdk/go/common/workspace/paths_test.go
@@ -0,0 +1,104 @@
// Copyright 2016-2022, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package workspace

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/stretchr/testify/assert"
)

func TestDetectProjectAndPath(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "projecttest")
assert.NoError(t, err)
cwd, err := os.Getwd()
assert.NoError(t, err)
defer func() { err := os.Chdir(cwd); assert.NoError(t, err) }()
err = os.Chdir(tmpDir)
assert.NoError(t, err)

yamlPath := filepath.Join(tmpDir, "Pulumi.yaml")
yamlContents :=
"name: some_project\ndescription: Some project\nruntime: nodejs\n"

err = os.WriteFile(yamlPath, []byte(yamlContents), 0600)
assert.NoError(t, err)

project, path, err := DetectProjectAndPath()
assert.NoError(t, err)
assert.Equal(t, yamlPath, path)
assert.Equal(t, tokens.PackageName("some_project"), project.Name)
assert.Equal(t, "Some project", *project.Description)
assert.Equal(t, "nodejs", project.Runtime.name)
}

func TestProjectStackPath(t *testing.T) {
Frassle marked this conversation as resolved.
Show resolved Hide resolved
expectedPath := func(expectedPath string) func(t *testing.T, projectDir, path string, err error) {
return func(t *testing.T, projectDir, path string, err error) {
assert.NoError(t, err)
assert.Equal(t, filepath.Join(projectDir, expectedPath), path)
}
}

tests := []struct {
name string
yamlContents string
validate func(t *testing.T, projectDir, path string, err error)
}{{
"WithoutStacksDirectory",
"name: some_project\ndescription: Some project\nruntime: nodejs\n",
expectedPath("Pulumi.my_stack.yaml"),
}, {
"WithStacksDirectory",
"name: some_project\ndescription: Some project\nruntime: nodejs\nstacksDirectory: stacks\n",
expectedPath(filepath.Join("stacks", "Pulumi.my_stack.yaml")),
}, {
"WithConfig",
"name: some_project\ndescription: Some project\nruntime: nodejs\nconfig: stacks\n",
expectedPath(filepath.Join("stacks", "Pulumi.my_stack.yaml")),
}, {
"WithBoth",
"name: some_project\ndescription: Some project\nruntime: nodejs\nconfig: stacks\nstacksDirectory: stacks\n",
func(t *testing.T, projectDir, path string, err error) {
assert.Error(t, err)
},
}}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "projecttest")
assert.NoError(t, err)
cwd, err := os.Getwd()
assert.NoError(t, err)
defer func() { err := os.Chdir(cwd); assert.NoError(t, err) }()
err = os.Chdir(tmpDir)
assert.NoError(t, err)

err = os.WriteFile(
filepath.Join(tmpDir, "Pulumi.yaml"),
[]byte(tt.yamlContents),
0600)
assert.NoError(t, err)

path, err := DetectProjectStackPath("my_stack")
tt.validate(t, tmpDir, path, err)
})
}
}
10 changes: 7 additions & 3 deletions sdk/go/common/workspace/project.go
@@ -1,4 +1,4 @@
// Copyright 2016-2018, Pulumi Corporation.
// Copyright 2016-2022, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -87,8 +87,12 @@ type Project struct {
// License is the optional license governing this project's usage.
License *string `json:"license,omitempty" yaml:"license,omitempty"`

// Config indicates where to store the Pulumi.<stack-name>.yaml files, combined with the folder Pulumi.yaml is in.
Config string `json:"config,omitempty" yaml:"config,omitempty"`
// Config has been renamed to StacksDirectory.
Config interface{} `json:"config,omitempty" yaml:"config,omitempty"`

// StacksDirectory indicates where to store the Pulumi.<stack-name>.yaml files, combined with the folder
// Pulumi.yaml is in.
StacksDirectory string `json:"stacksDirectory,omitempty" yaml:"stacksDirectory,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

only comment here is for such a visible change which will need to be reflected in docs, might want to get wider feedback on the name. up to you

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I want to get a few OKs on this before committing to this name.

Copy link
Member

@jkodroff jkodroff Mar 8, 2022

Choose a reason for hiding this comment

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

StackConfigFilesPath? Might be a little clearer, since we're pointing to config files, not the stacks themselves (obviously).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking off Josh's comment, maybe this should be "ConfigDirectory"? It used to just be called Config, how much do we need to make it clear its for stacks config?
Other ideas, "Stack[s]ConfigDirectory". "Dir" or "FilesPath" instead of "Directory"?

Copy link
Member

Choose a reason for hiding this comment

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

@Frassle What's the proper term for Pulumi.yaml versus Pulumi.stackname.yaml?

Copy link
Member Author

Choose a reason for hiding this comment

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

shrug "Project settings file" and "stack config file" I think.
@pgavlin or @lukehoban might have a definitive answer to that.

Copy link
Member

Choose a reason for hiding this comment

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

In our docs - these are currently "project file" and "stack configuration file". (Though this page includes a weird title that I feel like we should change "Project Configuration Reference").

From that page - the description of the current option is:

config: (optional) directory to store stack-specific configuration files, relative to location of Pulumi.yaml.

Here's suggestions in my order of preference:

  • stackConfigDir
  • stackDir
  • stackConfigPath
  • stackPath
  • stacksDir
  • stacksPath

Copy link
Member Author

Choose a reason for hiding this comment

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

stackConfigDir seems fine to me, will update.


// Template is an optional template manifest, if this project is a template.
Template *ProjectTemplate `json:"template,omitempty" yaml:"template,omitempty"`
Expand Down