private void updateTags()

in aws-sso-permissionset/src/main/java/software/amazon/sso/permissionset/UpdateHandler.java [189:211]


    private void updateTags(ResourceModel model, AmazonWebServicesClientProxy proxy, ProxyClient<SsoAdminClient> proxyClient) {
        Set<Tag> previousTags = new HashSet<>(getResourceTags(model.getInstanceArn(),
                model.getPermissionSetArn(),
                proxy,
                proxyClient));
        Set<Tag> newTags = new HashSet<>(Translator.ConvertToSSOTag(model.getTags()));

        final Set<Tag> tagsToRemove = Sets.difference(previousTags, newTags);
        final Set<Tag> tagsToAdd  = Sets.difference(newTags, previousTags);

        if (!tagsToRemove.isEmpty()) {
            List<String> tagKeys = new ArrayList<>();
            for (Tag tag : tagsToRemove) {
                tagKeys.add(tag.key());
            }
            proxy.injectCredentialsAndInvokeV2(Translator.translateToUntagResourceRequest(model, tagKeys),
                    proxyClient.client()::untagResource);
        }
        if (!tagsToAdd.isEmpty()) {
            proxy.injectCredentialsAndInvokeV2(Translator.translateToTagResourceRequest(model, new ArrayList<>(tagsToAdd)),
                    proxyClient.client()::tagResource);
        }
    }