Skip to content

Commit

Permalink
Merge #11426 #11454
Browse files Browse the repository at this point in the history
11426: Don't emit missing var errors for const vars r=Zaid-Ajaj a=iwahbe

Fixes #11372

11454: Don't print the update plan message if using --json r=Zaid-Ajaj a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #11453

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Ian Wahbe <ian@wahbe.com>
Co-authored-by: Fraser Waters <fraser@pulumi.com>
  • Loading branch information
3 people committed Nov 23, 2022
3 parents 0c7db79 + 3d27c75 + b6d61ec commit 534847d
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 19 deletions.
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: cli
description: Don't print update plan message with --json.
18 changes: 10 additions & 8 deletions pkg/cmd/pulumi/preview.go
Expand Up @@ -261,14 +261,16 @@ func newPreviewCmd() *cobra.Command {
return result.FromError(err)
}

// Write out message on how to use the plan
var buf bytes.Buffer
fprintf(&buf, "Update plan written to '%s'", planFilePath)
fprintf(
&buf,
"\nRun `pulumi up --plan='%s'` to constrain the update to the operations planned by this preview",
planFilePath)
cmdutil.Diag().Infof(diag.RawMessage("" /*urn*/, buf.String()))
// Write out message on how to use the plan (if not writing out --json)
if !jsonDisplay {
var buf bytes.Buffer
fprintf(&buf, "Update plan written to '%s'", planFilePath)
fprintf(
&buf,
"\nRun `pulumi up --plan='%s'` to constrain the update to the operations planned by this preview",
planFilePath)
cmdutil.Diag().Infof(diag.RawMessage("" /*urn*/, buf.String()))
}
}
return nil
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/codegen/hcl2/model/type_const.go
Expand Up @@ -98,3 +98,20 @@ func (t *ConstType) unify(other Type) (Type, ConversionKind) {
}

func (*ConstType) isType() {}

func IsConstType(t Type) bool {
switch t := t.(type) {
case *ConstType:
return true
case *UnionType:
for _, t := range t.ElementTypes {
_, ok := t.(*ConstType)
if !ok {
return false
}
}
return true
default:
return false
}
}
11 changes: 9 additions & 2 deletions pkg/codegen/pcl/binder_resource.go
Expand Up @@ -382,9 +382,16 @@ func (b *binder) bindResourceBody(node *Resource) hcl.Diagnostics {
}

for _, k := range codegen.SortedKeys(objectType.Properties) {
if !model.IsOptionalType(objectType.Properties[k]) && !attrNames.Has(k) {
diag(missingRequiredAttribute(k, block.Body.Syntax.MissingItemRange()))
typ := objectType.Properties[k]
if model.IsOptionalType(typ) || attrNames.Has(k) {
// The type is present or optional. No error.
continue
}
if model.IsConstType(objectType.Properties[k]) {
// The type is const, so the value is implied. No error.
continue
}
diag(missingRequiredAttribute(k, block.Body.Syntax.MissingItemRange()))
}
}

Expand Down
3 changes: 0 additions & 3 deletions pkg/codegen/testing/test/program_driver.go
Expand Up @@ -290,9 +290,6 @@ var PulumiPulumiYAMLProgramTests = []ProgramTest{
Directory: transpiled("kubernetes"),
Description: "Kubernetes",
Skip: codegen.NewStringSet("go"),
// PCL resource attribute type checking doesn't handle missing `const` attributes.
//
BindOptions: []pcl.BindOption{pcl.SkipResourceTypechecking},
},
{
Directory: transpiled("pulumi-variable"),
Expand Down
Expand Up @@ -7,7 +7,6 @@
var bar = new Kubernetes.Core.V1.Pod("bar", new()
{
ApiVersion = "v1",
Kind = "Pod",
Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs
{
Namespace = "foo",
Expand Down Expand Up @@ -41,5 +40,7 @@
},
});
var kind = bar.Kind;
});

Expand Up @@ -8,9 +8,8 @@ import (

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := corev1.NewPod(ctx, "bar", &corev1.PodArgs{
bar, err := corev1.NewPod(ctx, "bar", &corev1.PodArgs{
ApiVersion: pulumi.String("v1"),
Kind: pulumi.String("Pod"),
Metadata: &metav1.ObjectMetaArgs{
Namespace: pulumi.String("foo"),
Name: pulumi.String("bar"),
Expand Down Expand Up @@ -38,6 +37,7 @@ func main() {
if err != nil {
return err
}
_ := bar.Kind
return nil
})
}
@@ -1,6 +1,5 @@
resource bar "kubernetes:core/v1:Pod" {
apiVersion = "v1"
kind = "Pod"
metadata = {
namespace = "foo"
name = "bar"
Expand All @@ -21,3 +20,6 @@
]
}
}

// Test that we can assign from a constant without type errors
kind = bar.kind
Expand Up @@ -3,7 +3,6 @@ import * as kubernetes from "@pulumi/kubernetes";

const bar = new kubernetes.core.v1.Pod("bar", {
apiVersion: "v1",
kind: "Pod",
metadata: {
namespace: "foo",
name: "bar",
Expand All @@ -24,3 +23,4 @@ const bar = new kubernetes.core.v1.Pod("bar", {
}],
},
});
const kind = bar.kind;
Expand Up @@ -3,7 +3,6 @@

bar = kubernetes.core.v1.Pod("bar",
api_version="v1",
kind="Pod",
metadata=kubernetes.meta.v1.ObjectMetaArgs(
namespace="foo",
name="bar",
Expand All @@ -23,3 +22,4 @@
),
)],
))
kind = bar.kind

0 comments on commit 534847d

Please sign in to comment.