Describe the bug

When using the native environment provider a request such as GET /default/profile1,profile2,profile3 will return configuration from profile3,profile2, and profile1 in that order respecting the "last-wins" approach described here: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files.profile-specific

When using the awsparamstore ( and also the awssecretsmanager ) provider a request such as GET /default/profile1,profile2,profile3 returns configurations in the order of profile1,profile2 and profile3, not respecting the "last-wins" approach

I think, at a minimum, there should be consistency between the providers, and ideally the last-wins approach should be used everywhere.

This affects us as property overrides defined in later profiles in Parameter store were not taking effect, but this approach was working when using the native provider and local properties files

Sample

Tested using Spring Boot 3.1.8 as a client, Spring Cloud Config Server 4.0.4 as the server

Spring boot client code: application.properties:

spring.profiles.active=profile1,profile2,profile3
spring.main.web-application-type=none
spring.config.import=configserver:http://localhost:16501

DemoApplication.java:

package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.AbstractEnvironment;

import lombok.extern.slf4j.Slf4j;

@SpringBootApplication
@Slf4j
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }


    @Bean
    public ApplicationRunner runner() {
        return new ApplicationRunner() {
            @Value("${testprop}") String testprop;

            @Autowired AbstractEnvironment environment;

            @Override
            public void run(ApplicationArguments args) throws Exception {
                environment.getPropertySources().forEach(p -> {
                    log.info("Property Source: Type:{} Name: {}", p.getClass().getSimpleName(), p.getName());
                }); 
                log.info("Effective value of \"testprop\": {}", testprop);
            }
        };
    }
}

native provider

"native-profile3" should be the winning property value (and is) :

2024-02-15T17:10:24.404Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : The following 3 profiles are active: "profile1", "profile2", "profile3"
2024-02-15T17:10:24.451Z  INFO 89022 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:16501
2024-02-15T17:10:24.452Z  INFO 89022 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[default], label=null, version=null, state=null
2024-02-15T17:10:24.452Z  INFO 89022 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:16501
2024-02-15T17:10:24.452Z  INFO 89022 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[profile1,profile2,profile3], label=null, version=null, state=null
2024-02-15T17:10:24.858Z  INFO 89022 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=d6819dbe-3450-33b8-88bd-3f273dbf29b1
2024-02-15T17:10:26.018Z  INFO 89022 --- [           main] o.s.cloud.commons.util.InetUtils         : Cannot determine local hostname
2024-02-15T17:10:26.045Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 3.272 seconds (process running for 3.615)
2024-02-15T17:10:26.047Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:ConfigurationPropertySourcesPropertySource Name: configurationProperties
2024-02-15T17:10:26.048Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:PropertiesPropertySource Name: systemProperties
2024-02-15T17:10:26.048Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginAwareSystemEnvironmentPropertySource Name: systemEnvironment
2024-02-15T17:10:26.048Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:RandomValuePropertySource Name: random
2024-02-15T17:10:26.048Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:CachedRandomPropertySource Name: cachedrandom
2024-02-15T17:10:26.048Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:MapPropertySource Name: springCloudClientHostInfo
2024-02-15T17:10:26.048Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginTrackedMapPropertySource Name: configserver:classpath:/override-profile3.properties
2024-02-15T17:10:26.048Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginTrackedMapPropertySource Name: configserver:classpath:/override-profile2.properties
2024-02-15T17:10:26.048Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginTrackedMapPropertySource Name: configserver:classpath:/override-profile1.properties
2024-02-15T17:10:26.048Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:MapPropertySource Name: configClient
2024-02-15T17:10:26.049Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginTrackedMapPropertySource Name: Config resource 'class path resource [application.properties]' via location 'optional:classpath:/'
2024-02-15T17:10:26.049Z  INFO 89022 --- [           main] com.example.demo.DemoApplication         : Effective value of "testprop": native-profile3
user@localhost:~$ curl -s http://localhost:16501/default/profile1,profile2,profile3 | jq .
{
  "name": "default",
  "profiles": [
    "profile1,profile2,profile3"
  ],
  "label": null,
  "version": null,
  "state": null,
  "propertySources": [
    {
      "name": "classpath:/override-profile3.properties",
      "source": {
        "testprop": "native-profile3"
      }
    },
    {
      "name": "classpath:/override-profile2.properties",
      "source": {
        "testprop": "native-profile2"
      }
    },
    {
      "name": "classpath:/override-profile1.properties",
      "source": {
        "testprop": "native-profile1"
      }
    }
  ]
}

awsparamstore provider

"ssm-profile3" should be the winning property value (but is not - "ssm-profile1" wins) :

2024-02-15T17:11:12.909Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : The following 3 profiles are active: "profile1", "profile2", "profile3"
2024-02-15T17:11:12.942Z  INFO 90644 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:16501
2024-02-15T17:11:12.942Z  INFO 90644 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[default], label=null, version=null, state=null
2024-02-15T17:11:12.943Z  INFO 90644 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:16501
2024-02-15T17:11:12.943Z  INFO 90644 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[profile1,profile2,profile3], label=null, version=null, state=null
2024-02-15T17:11:13.284Z  INFO 90644 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=d6819dbe-3450-33b8-88bd-3f273dbf29b1
2024-02-15T17:11:14.436Z  INFO 90644 --- [           main] o.s.cloud.commons.util.InetUtils         : Cannot determine local hostname
2024-02-15T17:11:14.465Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 3.348 seconds (process running for 3.668)
2024-02-15T17:11:14.467Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:ConfigurationPropertySourcesPropertySource Name: configurationProperties
2024-02-15T17:11:14.468Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:PropertiesPropertySource Name: systemProperties
2024-02-15T17:11:14.468Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginAwareSystemEnvironmentPropertySource Name: systemEnvironment
2024-02-15T17:11:14.468Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:RandomValuePropertySource Name: random
2024-02-15T17:11:14.468Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:CachedRandomPropertySource Name: cachedrandom
2024-02-15T17:11:14.468Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:MapPropertySource Name: springCloudClientHostInfo
2024-02-15T17:11:14.468Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginTrackedMapPropertySource Name: configserver:aws:ssm:parameter:/config/application-profile1/
2024-02-15T17:11:14.468Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginTrackedMapPropertySource Name: configserver:aws:ssm:parameter:/config/application-profile2/
2024-02-15T17:11:14.468Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginTrackedMapPropertySource Name: configserver:aws:ssm:parameter:/config/application-profile3/
2024-02-15T17:11:14.469Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:MapPropertySource Name: configClient
2024-02-15T17:11:14.469Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Property Source: Type:OriginTrackedMapPropertySource Name: Config resource 'class path resource [application.properties]' via location 'optional:classpath:/'
2024-02-15T17:11:14.469Z  INFO 90644 --- [           main] com.example.demo.DemoApplication         : Effective value of "testprop": ssm-profile1
user@localhost:~$ curl -s http://localhost:16501/default/profile1,profile2,profile3 | jq .
{
  "name": "default",
  "profiles": [
    "profile1,profile2,profile3"
  ],
  "label": null,
  "version": null,
  "state": null,
  "propertySources": [
    {
      "name": "aws:ssm:parameter:/config/application-profile1/",
      "source": {
        "testprop": "ssm-profile1"
      }
    },
    {
      "name": "aws:ssm:parameter:/config/application-profile2/",
      "source": {
        "testprop": "ssm-profile2"
      }
    },
    {
      "name": "aws:ssm:parameter:/config/application-profile3/",
      "source": {
        "testprop": "ssm-profile3"
      }
    }
  ]
}