From 13dbb594ee33aac674ec5acdaa027f17b11394e1 Mon Sep 17 00:00:00 2001 From: Thomas Kappler Date: Fri, 19 Jul 2024 17:52:04 +0200 Subject: [PATCH] metadata_host is marked as required upstream but actually isn't (#1233) Resolves #362 - users of this provider need to specify this config even if the default is fine. The upstream provider [has this property marked as required](https://github.com/hashicorp/terraform-provider-azuread/blob/6594e1c6cd59ffc7f5e9a881412609d9cde816e7/internal/provider/provider.go#L126), but that works differently in Terraform: since there's also a `DefaultFunc` configured, the function's return value will be used if the user doesn't specify a value, and the function itself returns a default of `""`. So a value is guaranteed, even if it's the empty string. In Pulumi, "required" means needs to be configured by the user. Therefore, we mark this property as optional to get the same behavior as upstream. --- .../cmd/pulumi-resource-azuread/schema.json | 11 +----- provider/resources.go | 3 ++ sdk/dotnet/Provider.cs | 8 ++-- sdk/go/azuread/provider.go | 16 +++----- .../main/java/com/pulumi/azuread/Config.java | 4 +- .../java/com/pulumi/azuread/Provider.java | 10 ++--- .../java/com/pulumi/azuread/ProviderArgs.java | 14 +++---- sdk/nodejs/provider.ts | 9 ++--- sdk/python/pulumi_azuread/provider.py | 37 +++++++++---------- 9 files changed, 48 insertions(+), 64 deletions(-) diff --git a/provider/cmd/pulumi-resource-azuread/schema.json b/provider/cmd/pulumi-resource-azuread/schema.json index bef703d58..d0bdef0a8 100644 --- a/provider/cmd/pulumi-resource-azuread/schema.json +++ b/provider/cmd/pulumi-resource-azuread/schema.json @@ -164,8 +164,7 @@ } }, "defaults": [ - "environment", - "metadataHost" + "environment" ] }, "types": { @@ -3141,9 +3140,6 @@ "description": "Allow OpenID Connect to be used for authentication\n" } }, - "required": [ - "metadataHost" - ], "inputProperties": { "clientCertificate": { "type": "string", @@ -3248,10 +3244,7 @@ "type": "boolean", "description": "Allow OpenID Connect to be used for authentication\n" } - }, - "requiredInputs": [ - "metadataHost" - ] + } }, "resources": { "azuread:index/accessPackage:AccessPackage": { diff --git a/provider/resources.go b/provider/resources.go index 443ef3142..5f720f4e7 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -159,6 +159,9 @@ func Provider() tfbridge.ProviderInfo { EnvVars: []string{"ARM_ENVIRONMENT"}, }, }, + "metadata_host": { + MarkAsOptional: tfbridge.True(), + }, "msi_endpoint": { Default: &tfbridge.DefaultInfo{ EnvVars: []string{"ARM_MSI_ENDPOINT"}, diff --git a/sdk/dotnet/Provider.cs b/sdk/dotnet/Provider.cs index ad57eefc3..c709b5da8 100644 --- a/sdk/dotnet/Provider.cs +++ b/sdk/dotnet/Provider.cs @@ -75,7 +75,7 @@ public partial class Provider : global::Pulumi.ProviderResource /// The Hostname which should be used for the Azure Metadata Service. /// [Output("metadataHost")] - public Output MetadataHost { get; private set; } = null!; + public Output MetadataHost { get; private set; } = null!; /// /// The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically @@ -129,7 +129,7 @@ public partial class Provider : global::Pulumi.ProviderResource /// The unique name of the resource /// The arguments used to populate this resource's properties /// A bag of options that control this resource's behavior - public Provider(string name, ProviderArgs args, CustomResourceOptions? options = null) + public Provider(string name, ProviderArgs? args = null, CustomResourceOptions? options = null) : base("azuread", name, args ?? new ProviderArgs(), MakeResourceOptions(options, "")) { } @@ -244,8 +244,8 @@ public Input? ClientSecret /// /// The Hostname which should be used for the Azure Metadata Service. /// - [Input("metadataHost", required: true)] - public Input MetadataHost { get; set; } = null!; + [Input("metadataHost")] + public Input? MetadataHost { get; set; } /// /// The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically diff --git a/sdk/go/azuread/provider.go b/sdk/go/azuread/provider.go index 3fd686b9d..48202129c 100644 --- a/sdk/go/azuread/provider.go +++ b/sdk/go/azuread/provider.go @@ -7,7 +7,6 @@ import ( "context" "reflect" - "errors" "github.com/pulumi/pulumi-azuread/sdk/v5/go/azuread/internal" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" ) @@ -41,7 +40,7 @@ type Provider struct { // when `metadataHost` is specified. Environment pulumi.StringPtrOutput `pulumi:"environment"` // The Hostname which should be used for the Azure Metadata Service. - MetadataHost pulumi.StringOutput `pulumi:"metadataHost"` + MetadataHost pulumi.StringPtrOutput `pulumi:"metadataHost"` // The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically MsiEndpoint pulumi.StringPtrOutput `pulumi:"msiEndpoint"` // The bearer token for the request to the OIDC provider. For use when authenticating as a Service Principal using OpenID @@ -64,12 +63,9 @@ type Provider struct { func NewProvider(ctx *pulumi.Context, name string, args *ProviderArgs, opts ...pulumi.ResourceOption) (*Provider, error) { if args == nil { - return nil, errors.New("missing one or more required arguments") + args = &ProviderArgs{} } - if args.MetadataHost == nil { - return nil, errors.New("invalid value for required argument 'MetadataHost'") - } if args.Environment == nil { if d := internal.GetEnvOrDefault("public", nil, "ARM_ENVIRONMENT"); d != nil { args.Environment = pulumi.StringPtr(d.(string)) @@ -133,7 +129,7 @@ type providerArgs struct { // when `metadataHost` is specified. Environment *string `pulumi:"environment"` // The Hostname which should be used for the Azure Metadata Service. - MetadataHost string `pulumi:"metadataHost"` + MetadataHost *string `pulumi:"metadataHost"` // The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically MsiEndpoint *string `pulumi:"msiEndpoint"` // The bearer token for the request to the OIDC provider. For use when authenticating as a Service Principal using OpenID @@ -185,7 +181,7 @@ type ProviderArgs struct { // when `metadataHost` is specified. Environment pulumi.StringPtrInput // The Hostname which should be used for the Azure Metadata Service. - MetadataHost pulumi.StringInput + MetadataHost pulumi.StringPtrInput // The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically MsiEndpoint pulumi.StringPtrInput // The bearer token for the request to the OIDC provider. For use when authenticating as a Service Principal using OpenID @@ -295,8 +291,8 @@ func (o ProviderOutput) Environment() pulumi.StringPtrOutput { } // The Hostname which should be used for the Azure Metadata Service. -func (o ProviderOutput) MetadataHost() pulumi.StringOutput { - return o.ApplyT(func(v *Provider) pulumi.StringOutput { return v.MetadataHost }).(pulumi.StringOutput) +func (o ProviderOutput) MetadataHost() pulumi.StringPtrOutput { + return o.ApplyT(func(v *Provider) pulumi.StringPtrOutput { return v.MetadataHost }).(pulumi.StringPtrOutput) } // The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically diff --git a/sdk/java/src/main/java/com/pulumi/azuread/Config.java b/sdk/java/src/main/java/com/pulumi/azuread/Config.java index 5606b5389..97342a54c 100644 --- a/sdk/java/src/main/java/com/pulumi/azuread/Config.java +++ b/sdk/java/src/main/java/com/pulumi/azuread/Config.java @@ -79,8 +79,8 @@ public String environment() { * The Hostname which should be used for the Azure Metadata Service. * */ - public String metadataHost() { - return Codegen.stringProp("metadataHost").config(config).require(); + public Optional metadataHost() { + return Codegen.stringProp("metadataHost").config(config).get(); } /** * The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically diff --git a/sdk/java/src/main/java/com/pulumi/azuread/Provider.java b/sdk/java/src/main/java/com/pulumi/azuread/Provider.java index 6320b013b..709ff9f58 100644 --- a/sdk/java/src/main/java/com/pulumi/azuread/Provider.java +++ b/sdk/java/src/main/java/com/pulumi/azuread/Provider.java @@ -150,14 +150,14 @@ public Output> environment() { * */ @Export(name="metadataHost", refs={String.class}, tree="[0]") - private Output metadataHost; + private Output metadataHost; /** * @return The Hostname which should be used for the Azure Metadata Service. * */ - public Output metadataHost() { - return this.metadataHost; + public Output> metadataHost() { + return Codegen.optional(this.metadataHost); } /** * The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically @@ -274,7 +274,7 @@ public Provider(String name) { * @param name The _unique_ name of the resulting resource. * @param args The arguments to use to populate this resource's properties. */ - public Provider(String name, ProviderArgs args) { + public Provider(String name, @Nullable ProviderArgs args) { this(name, args, null); } /** @@ -283,7 +283,7 @@ public Provider(String name, ProviderArgs args) { * @param args The arguments to use to populate this resource's properties. * @param options A bag of options that control this resource's behavior. */ - public Provider(String name, ProviderArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) { + public Provider(String name, @Nullable ProviderArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) { super("azuread", name, args == null ? ProviderArgs.Empty : args, makeResourceOptions(options, Codegen.empty())); } diff --git a/sdk/java/src/main/java/com/pulumi/azuread/ProviderArgs.java b/sdk/java/src/main/java/com/pulumi/azuread/ProviderArgs.java index aa7e33c31..a46b8057c 100644 --- a/sdk/java/src/main/java/com/pulumi/azuread/ProviderArgs.java +++ b/sdk/java/src/main/java/com/pulumi/azuread/ProviderArgs.java @@ -6,7 +6,6 @@ import com.pulumi.core.Output; import com.pulumi.core.annotations.Import; import com.pulumi.core.internal.Codegen; -import com.pulumi.exceptions.MissingRequiredPropertyException; import java.lang.Boolean; import java.lang.String; import java.util.Objects; @@ -159,15 +158,15 @@ public Optional> environment() { * The Hostname which should be used for the Azure Metadata Service. * */ - @Import(name="metadataHost", required=true) - private Output metadataHost; + @Import(name="metadataHost") + private @Nullable Output metadataHost; /** * @return The Hostname which should be used for the Azure Metadata Service. * */ - public Output metadataHost() { - return this.metadataHost; + public Optional> metadataHost() { + return Optional.ofNullable(this.metadataHost); } /** @@ -576,7 +575,7 @@ public Builder environment(String environment) { * @return builder * */ - public Builder metadataHost(Output metadataHost) { + public Builder metadataHost(@Nullable Output metadataHost) { $.metadataHost = metadataHost; return this; } @@ -828,9 +827,6 @@ public Builder useOidc(Boolean useOidc) { public ProviderArgs build() { $.environment = Codegen.stringProp("environment").output().arg($.environment).env("ARM_ENVIRONMENT").def("public").getNullable(); - if ($.metadataHost == null) { - throw new MissingRequiredPropertyException("ProviderArgs", "metadataHost"); - } $.msiEndpoint = Codegen.stringProp("msiEndpoint").output().arg($.msiEndpoint).env("ARM_MSI_ENDPOINT").getNullable(); $.useMsi = Codegen.booleanProp("useMsi").output().arg($.useMsi).env("ARM_USE_MSI").def(false).getNullable(); return $; diff --git a/sdk/nodejs/provider.ts b/sdk/nodejs/provider.ts index 63dde64be..b48626326 100644 --- a/sdk/nodejs/provider.ts +++ b/sdk/nodejs/provider.ts @@ -65,7 +65,7 @@ export class Provider extends pulumi.ProviderResource { /** * The Hostname which should be used for the Azure Metadata Service. */ - public readonly metadataHost!: pulumi.Output; + public readonly metadataHost!: pulumi.Output; /** * The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically */ @@ -104,13 +104,10 @@ export class Provider extends pulumi.ProviderResource { * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ - constructor(name: string, args: ProviderArgs, opts?: pulumi.ResourceOptions) { + constructor(name: string, args?: ProviderArgs, opts?: pulumi.ResourceOptions) { let resourceInputs: pulumi.Inputs = {}; opts = opts || {}; { - if ((!args || args.metadataHost === undefined) && !opts.urn) { - throw new Error("Missing required property 'metadataHost'"); - } resourceInputs["clientCertificate"] = args ? args.clientCertificate : undefined; resourceInputs["clientCertificatePassword"] = args?.clientCertificatePassword ? pulumi.secret(args.clientCertificatePassword) : undefined; resourceInputs["clientCertificatePath"] = args ? args.clientCertificatePath : undefined; @@ -185,7 +182,7 @@ export interface ProviderArgs { /** * The Hostname which should be used for the Azure Metadata Service. */ - metadataHost: pulumi.Input; + metadataHost?: pulumi.Input; /** * The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically */ diff --git a/sdk/python/pulumi_azuread/provider.py b/sdk/python/pulumi_azuread/provider.py index 4fcb628eb..1e7723e65 100644 --- a/sdk/python/pulumi_azuread/provider.py +++ b/sdk/python/pulumi_azuread/provider.py @@ -19,7 +19,6 @@ @pulumi.input_type class ProviderArgs: def __init__(__self__, *, - metadata_host: pulumi.Input[str], client_certificate: Optional[pulumi.Input[str]] = None, client_certificate_password: Optional[pulumi.Input[str]] = None, client_certificate_path: Optional[pulumi.Input[str]] = None, @@ -29,6 +28,7 @@ def __init__(__self__, *, client_secret_file_path: Optional[pulumi.Input[str]] = None, disable_terraform_partner_id: Optional[pulumi.Input[bool]] = None, environment: Optional[pulumi.Input[str]] = None, + metadata_host: Optional[pulumi.Input[str]] = None, msi_endpoint: Optional[pulumi.Input[str]] = None, oidc_request_token: Optional[pulumi.Input[str]] = None, oidc_request_url: Optional[pulumi.Input[str]] = None, @@ -42,7 +42,6 @@ def __init__(__self__, *, use_oidc: Optional[pulumi.Input[bool]] = None): """ The set of arguments for constructing a Provider resource. - :param pulumi.Input[str] metadata_host: The Hostname which should be used for the Azure Metadata Service. :param pulumi.Input[str] client_certificate: Base64 encoded PKCS#12 certificate bundle to use when authenticating as a Service Principal using a Client Certificate :param pulumi.Input[str] client_certificate_password: The password to decrypt the Client Certificate. For use when authenticating as a Service Principal using a Client Certificate @@ -56,6 +55,7 @@ def __init__(__self__, *, :param pulumi.Input[str] environment: The cloud environment which should be used. Possible values are: `global` (also `public`), `usgovernmentl4` (also `usgovernment`), `usgovernmentl5` (also `dod`), and `china`. Defaults to `global`. Not used and should not be specified when `metadata_host` is specified. + :param pulumi.Input[str] metadata_host: The Hostname which should be used for the Azure Metadata Service. :param pulumi.Input[str] msi_endpoint: The path to a custom endpoint for Managed Identity - in most circumstances this should be detected automatically :param pulumi.Input[str] oidc_request_token: The bearer token for the request to the OIDC provider. For use when authenticating as a Service Principal using OpenID Connect. @@ -70,7 +70,6 @@ def __init__(__self__, *, :param pulumi.Input[bool] use_msi: Allow Managed Identity to be used for Authentication :param pulumi.Input[bool] use_oidc: Allow OpenID Connect to be used for authentication """ - pulumi.set(__self__, "metadata_host", metadata_host) if client_certificate is not None: pulumi.set(__self__, "client_certificate", client_certificate) if client_certificate_password is not None: @@ -91,6 +90,8 @@ def __init__(__self__, *, environment = (_utilities.get_env('ARM_ENVIRONMENT') or 'public') if environment is not None: pulumi.set(__self__, "environment", environment) + if metadata_host is not None: + pulumi.set(__self__, "metadata_host", metadata_host) if msi_endpoint is None: msi_endpoint = _utilities.get_env('ARM_MSI_ENDPOINT') if msi_endpoint is not None: @@ -118,18 +119,6 @@ def __init__(__self__, *, if use_oidc is not None: pulumi.set(__self__, "use_oidc", use_oidc) - @property - @pulumi.getter(name="metadataHost") - def metadata_host(self) -> pulumi.Input[str]: - """ - The Hostname which should be used for the Azure Metadata Service. - """ - return pulumi.get(self, "metadata_host") - - @metadata_host.setter - def metadata_host(self, value: pulumi.Input[str]): - pulumi.set(self, "metadata_host", value) - @property @pulumi.getter(name="clientCertificate") def client_certificate(self) -> Optional[pulumi.Input[str]]: @@ -240,6 +229,18 @@ def environment(self) -> Optional[pulumi.Input[str]]: def environment(self, value: Optional[pulumi.Input[str]]): pulumi.set(self, "environment", value) + @property + @pulumi.getter(name="metadataHost") + def metadata_host(self) -> Optional[pulumi.Input[str]]: + """ + The Hostname which should be used for the Azure Metadata Service. + """ + return pulumi.get(self, "metadata_host") + + @metadata_host.setter + def metadata_host(self, value: Optional[pulumi.Input[str]]): + pulumi.set(self, "metadata_host", value) + @property @pulumi.getter(name="msiEndpoint") def msi_endpoint(self) -> Optional[pulumi.Input[str]]: @@ -442,7 +443,7 @@ def __init__(__self__, @overload def __init__(__self__, resource_name: str, - args: ProviderArgs, + args: Optional[ProviderArgs] = None, opts: Optional[pulumi.ResourceOptions] = None): """ The provider type for the azuread package. By default, resources use package-wide configuration @@ -506,8 +507,6 @@ def _internal_init(__self__, if environment is None: environment = (_utilities.get_env('ARM_ENVIRONMENT') or 'public') __props__.__dict__["environment"] = environment - if metadata_host is None and not opts.urn: - raise TypeError("Missing required property 'metadata_host'") __props__.__dict__["metadata_host"] = metadata_host if msi_endpoint is None: msi_endpoint = _utilities.get_env('ARM_MSI_ENDPOINT') @@ -603,7 +602,7 @@ def environment(self) -> pulumi.Output[Optional[str]]: @property @pulumi.getter(name="metadataHost") - def metadata_host(self) -> pulumi.Output[str]: + def metadata_host(self) -> pulumi.Output[Optional[str]]: """ The Hostname which should be used for the Azure Metadata Service. """